Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long delay during ADC initialization #217

Merged
merged 1 commit into from
Apr 25, 2021

Conversation

Rahix
Copy link
Contributor

@Rahix Rahix commented Apr 25, 2021

As explained in issue #206, the code here is doing the calculation completely wrong. This leads to a multi-second startup delay instead of just a few clock cycles.

Fix this by using the correct calculation; currently only ADC clock configurations synchronous to the AHB are supported which makes this quite easy: We just need to delay the given number of cycles * the selected ADC clock prescaler (1, 2, or 4).

To make this code future proof against an implementation of asynchronous ADC clock configurations, use a match statement here which will fail to compile once the ASYNCHRONOUS variant is added to the CkMode struct - thus forcing the implementor to take another look at this.

Fixes: #206

As explained in issue stm32-rs#206, the code here is doing the calculation
completely wrong.  This leads to a multi-second startup delay instead of
just a few clock cycles.

Fix this by using the correct calculation; currently only ADC clock
configurations synchronous to the AHB are supported which makes this
quite easy: We just need to delay the given number of cycles * the
selected ADC clock prescaler (1, 2, or 4).

To make this code future proof against an implementation of asynchronous
ADC clock configurations, use a `match` statement here which will fail
to compile once the `ASYNCHRONOUS` variant is added to the `CkMode`
struct - thus forcing the implementor to take another look at this.

Fixes: stm32-rs#206
@Rahix
Copy link
Contributor Author

Rahix commented Apr 25, 2021

(FYI, you manually need to approve the CI run now due to recent changes with GHA)

@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Apr 25, 2021

Thanks! Very much appreciated

@Sh3Rm4n Sh3Rm4n merged commit ff65124 into stm32-rs:master Apr 25, 2021
@Rahix Rahix deleted the fix-adc-init branch April 25, 2021 19:04
Rahix added a commit to Rahix/pavu-mixer that referenced this pull request Aug 16, 2021
This was fixed upstream [1] and with the switch to the git version of
stm32f3xx-hal, we no longer face this issue.

[1]: stm32-rs/stm32f3xx-hal#217
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

adc delays for seconds on init
2 participants