Skip to content

cpu/stm32f2: Fix Sampling Time for VBat #21346

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

Merged
merged 1 commit into from
Apr 2, 2025
Merged

Conversation

crasbe
Copy link
Contributor

@crasbe crasbe commented Apr 2, 2025

Contribution description

During the testing of #20971 I noticed that the sampling time for reading VBat is insufficient. This happened on other platforms as well, apparently I did not test the F2 yet...

Testing procedure

To test this PR, #20971 has to be applied as well, otherwise the sampling will freeze after the zero-th to second sampling due to incorrect resolution settings (I guess?).

With current master:

cbuec@W11nMate:~/RIOTstuff/riot-stm32adc/RIOT$ BOARD=nucleo-f207zg USEMODULE+=periph_vbat  make -C tests/periph/vbat flash term -j12
make: Entering directory '/home/cbuec/RIOTstuff/riot-stm32adc/RIOT/tests/periph/vbat'
Building application "tests_vbat" for "nucleo-f207zg" with CPU "stm32".

"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/boards
"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/boards/nucleo-f207zg
...
shutdown command invoked
Done flashing
/home/cbuec/RIOTstuff/riot-stm32adc/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" -ln "/tmp/pyterm-cbuec" -rn "2025-04-02_21.33.29-tests_vbat-nucleo-f207zg"
2025-04-02 21:33:29,475 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2025-04-02 21:33:30,483 # 89[mV]
*freeze*

With #20971:

cbuec@W11nMate:~/RIOTstuff/riot-stm32adc/RIOT$ BOARD=nucleo-f207zg USEMODULE+=periph_vbat  make -C tests/per
iph/vbat flash term -j12
make: Entering directory '/home/cbuec/RIOTstuff/riot-stm32adc/RIOT/tests/periph/vbat'
Building application "tests_vbat" for "nucleo-f207zg" with CPU "stm32".

"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/boards
...
shutdown command invoked
Done flashing
/home/cbuec/RIOTstuff/riot-stm32adc/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" -ln "/tmp/pyterm-cbuec" -rn "2025-04-02_21.36.39-tests_vbat-nucleo-f207zg"
2025-04-02 21:36:39,903 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2025-04-02 21:36:40,910 # VBAT: 106[mV]
2025-04-02 21:36:41,566 # VBAT: 98[mV]
2025-04-02 21:36:42,544 # VBAT: 93[mV]
2025-04-02 21:36:43,525 # VBAT: 87[mV]
2025-04-02 21:36:44,504 # VBAT: 75[mV]
2025-04-02 21:36:45,484 # VBAT: 96[mV]
2025-04-02 21:36:46,463 # VBAT: 91[mV]

With this PR:

cbuec@W11nMate:~/RIOTstuff/riot-stm32adc/RIOT$ BOARD=nucleo-f207zg USEMODULE+=periph_vbat  make -C tests/periph/vbat flash term -j12
make: Entering directory '/home/cbuec/RIOTstuff/riot-stm32adc/RIOT/tests/periph/vbat'
Building application "tests_vbat" for "nucleo-f207zg" with CPU "stm32".

"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/boards
...

shutdown command invoked
Done flashing
/home/cbuec/RIOTstuff/riot-stm32adc/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" -ln "/tmp/pyterm-cbuec" -rn "2025-04-02_21.38.46-tests_vbat-nucleo-f207zg"
2025-04-02 21:38:46,799 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2025-04-02 21:38:47,806 # BAT: 91[mV]
2025-04-02 21:38:47,806 # VBAT: 83[mV]
*freeze*

With this PR and #20971:

cbuec@W11nMate:~/RIOTstuff/riot-stm32adc/RIOT$ BOARD=nucleo-f207zg USEMODULE+=periph_vbat  make -C tests/periph/vbat flash term -j12
make: Entering directory '/home/cbuec/RIOTstuff/riot-stm32adc/RIOT/tests/periph/vbat'
Building application "tests_vbat" for "nucleo-f207zg" with CPU "stm32".

"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-stm32adc/RIOT/boards
...
Done flashing
/home/cbuec/RIOTstuff/riot-stm32adc/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" -ln "/tmp/pyterm-cbuec" -rn "2025-04-02_21.27.21-tests_vbat-nucleo-f207zg"
2025-04-02 21:27:22,189 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2025-04-02 21:27:23,195 # VBAT: 3291[mV]
2025-04-02 21:27:23,820 # VBAT: 3291[mV]
2025-04-02 21:27:24,799 # VBAT: 3289[mV]
2025-04-02 21:27:25,780 # VBAT: 3289[mV]
2025-04-02 21:27:26,758 # VBAT: 3291[mV]
2025-04-02 21:27:27,738 # VBAT: 3289[mV]
2025-04-02 21:27:28,718 # VBAT: 3289[mV]
2025-04-02 21:27:29,697 # VBAT: 3289[mV]
2025-04-02 21:27:31,407 # VBAT: 3289[mV]
...

Issues/PRs references

Prerequisite for #20971.

@crasbe crasbe requested review from aabadie and vincent-d as code owners April 2, 2025 19:41
@github-actions github-actions bot added Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: cpu Area: CPU/MCU ports labels Apr 2, 2025
@crasbe crasbe added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 2, 2025
@crasbe
Copy link
Contributor Author

crasbe commented Apr 2, 2025

Some context from the datasheet below. The VBat line is not usually connected to the ADC input and has to be enabled. This switching takes some time and for a proper measurement, the cycle count has to be significantly higher.
The datasheet recommends to try out a proper value, that's what I did :D

image

https://www.st.com/resource/en/datasheet/cd00237391.pdf p.128

@riot-ci
Copy link

riot-ci commented Apr 2, 2025

Murdock results

✔️ PASSED

596670b cpu/stm32f2: fix sampling time for VBat

Success Failures Total Runtime
10280 0 10280 08m:57s

Artifacts

@maribu maribu enabled auto-merge April 2, 2025 20:16
@maribu maribu added this pull request to the merge queue Apr 2, 2025
Merged via the queue into RIOT-OS:master with commit 22531e6 Apr 2, 2025
29 checks passed
@crasbe
Copy link
Contributor Author

crasbe commented Apr 2, 2025

Thank you for reviewing this so quickly :)

@crasbe crasbe deleted the pr/stm32f2_adc branch April 2, 2025 22:04
@mguetschow mguetschow added this to the Release 2025.04 milestone Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants