- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.1k
cpu/stm32{f0,g0,c0}: fix ADC initialization sequence #21230
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
Conversation
c6897e0    to
    6ba243d      
    Compare
  
    | I applied some ideas from the STM32WL PR to this one, namingly giving  Tested again with the  | 
| The Nucleo-G071RB and Nucleo-C031C6 arrived today for testing. Apparently there is an unrelated bug since the G071RB does not even boot with RIOT. Not the  So I'll have to investigate when it broke and why. The support for this Nucleo was introduced in Release 2020.10, so that's only... a lot of releases to go through 😅 The C031C6 has an interesting behavior with  The reason for this lies in #20971, as the resolution defines are not defined for the STM32C0 at all and just set to 0-5 for 6 to 16-bit, which aren't legal values to put into the registers: https://github.com/RIOT-OS/RIOT/pull/20971/files#diff-536800c2dc2fdcbba4197ce4fc78f7da0a9f660b4c5e6951f411d86a7ccc448e Apparently I applied the resolution PR to the C0 PR for testing already and failed to mention it in the testing procedure.. With just #20971 applied to  With both PRs applied, the output is as it should be:  | 
| Okay, there is nothing wrong with the Nucleo-G071RB board. Apparently there is a bug with the ST-Link that the file upload does not work correctly for the G071RB. I tested a simple Arduino program and it didn't work either. With SWD, it runs as it should. With master: With master and #20971: With this PR and #20971:  | 
| From my side this is complete now and I can squash it if requested. | 
| One additional thing to test (even though it doesn't really have to do with this PR): Test the STM32G0 with  | 
| Nucleo-G071RB with  Measuring the VBat with another ADC pin (by bridging the two pins) shows that in fact it has 3.3V. The voltage reported by  The STM32WL55 has the same behavior, as documented in #21238. Perhaps I'll create another issue for this to document it. Let's get this and the other related PRs merged first. | 
58db884    to
    db9d7f3      
    Compare
  
    db9d7f3    to
    05eda72      
    Compare
  
    | I think for this PR, I don't want to conditionally set the sampling time for VBat as the current implementation on Master already has quite a high sampling time and nobody complained so far 😅 But let me know if I should change and test it. Other than that, this is squashed and ready for review. | 
| Thanks :) | 
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.It arrived and everything works as it should :)
Tested with:
Additional Tests:
periph_vbatenabled.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.
In both cases, PR #20971 has to be applied to set the correct values to the resolution register.
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