stm32/machine_adc: Enable ADC re-read errata handling for STM32WB55. #17230
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
For STM32WB errata 2.7.1:
"Wrong ADC result if conversion done late after calibration or previous conversion"
states an incorrect reading is returned if more than 1ms has elapsed since the last
reading or calibration. According to the errata, this can be avoided by performing
two consecutive ADC conversions and keeping the second result.
This matches existing handling for a comparable STM32G4 errata 2.7.7
Testing
Before this change the first read from an ADC channel often looked wrong, it turns out we'd previously added what was essentially a double-read in our application "to help the adc stabilise". Fixing it here in micropython is far more reliable and efficient.
Trade-offs and Alternatives
I initially though it would be better to add some timing checks / "how long since last read" and only re-read if needed, however I temporarily added some timing checks with
ticks_us
/ticks_diff
and on my STM32WB55 @ 64Mhz and each ADC read seemed to take only ~ 3us, certainly not worth the overhead of storing and checking the time of last read.