arch/arm/stm32h5: Fix hanging ADC enable call - #19929
Open
liam-geotab wants to merge 1 commit into
Open
Conversation
Posix open() calls to /dev/adc# were hanging often due to the ready loop check at the end of adc_enable() never returning. According to ES0565 document, at least 4 ADC clock cycles must pass between the time we waited for calibration to end and before we can set ADEN. This will depend on what clock is set for ADC. So to ensure enough time passes, we are adding a short delay (so that even a slow clock will work). Also, we are clearing the ADRDY flag before hand to ensure we are detecting a fresh event. The delay to wait for the voltage regulator is also increased to account for extra time required in non-ideal conditions. Signed-off-by: Liam Howatt <liamhowatt@geotab.com>
xiaoxiang781216
approved these changes
Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix an ADC issue that was seen occasionally. Increase+add a delay and "Also, clear ADRDY to ensure we are waiting for a fresh event."
The author explains:
Impact
Delays were changed and a register write was added to avoid reading an outdated "ready" value.
The register bit is a read/write bit which is read to detect sample "ready", and written with a 1 to clear it. It is cleared at the end, but it's defensively being cleared in case of an existing value.
Testing
I have validated this patch in isolation on the custom board by measuring a depleting a capacitor and the voltage source upstream of a diode before and after removing the voltage source.
Custom STM32H5 board with 12 ADC channels. config with:
Grepping the two channels of interest: