cpu/stm32{f0,g0,c0}: fix ADC initialization sequence #21230
+133
−19
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.
Contribution description
Most of the issue was described in #21222.
tl;dr: The initialization sequence was not entirely correct and at least for the STM32C0, changing the resolution did not work.
I rewrote the calibration and initialization sequence to follow the guides outlined in the reference manuals more closely.
It should be noted here that the reference manuals involve more steps and checks the newer the devices gets. The sequence for the F0 is very simple [1], for the G0 more complicated [2] and quite involved for the C0 [3].
Currently I don't have a STM32G0 nucleo, so the changes are untested for that family. Soon(ish) I'll buy one though.
Tested with:
Testing procedure
I recommend to apply #21223 as well to check all resolutions at once.The updated test is now in master and I rebased this PR.For some STM32C0xx boards, PR #20939 has to be applied with my proposed changes as well if you want to use the NUCLEO-C071 (not really convenient). The NUCLEO-C031 is supported by master already.
You can simply use the adc test
BOARD=nucleo-f030r8 make flash term
.Before this PR with the STM32C071RB (Pin A0 connected to 3.3V, all samples have the same resolution):
With this PR on STM32F030R8 and STM32C071RB (Pin A3 connected to +3.3V, samples have different resolution):
Issues/PRs references
Fixes #21222.
[1] https://www.st.com/resource/en/reference_manual/rm0360-stm32f030x4x6x8xc-and-stm32f070x6xb-advanced-armbased-32bit-mcus-stmicroelectronics.pdf p. 185 section 12.3.2 and 12.3.3
[2] https://www.st.com/resource/en/reference_manual/rm0454-stm32g0x0-advanced-armbased-32bit-mcus-stmicroelectronics.pdf p. 278 section 14.3.3 and 14.3.4
[3] https://www.st.com/resource/en/reference_manual/rm0490-stm32c0-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf p. 290 section 16.4.3 and section 16.4.4