embassy icon indicating copy to clipboard operation
embassy copied to clipboard

stm32f1 ADC example does not work

Open katyo opened this issue 8 months ago • 3 comments

I run ADC example on stm32f103c8 but seems it does not works as expected.

It just awaits infinitely here: https://github.com/embassy-rs/embassy/blob/94586576a06cf5869d0cdea6d678a0448bb1fdf8/examples/stm32f1/src/bin/adc.rs#L26

GDB shows me that wfe instruction was executed last but seems no events happening.

katyo avatar Nov 08 '23 18:11 katyo

I run into the same problem but actually only if I use the crates. If I use the dependencies from path it works fine for me. Did you fix it for you?

marsjo avatar Feb 11 '24 13:02 marsjo

Same issue here on a stm32f103c6 (Infinite wait on adc.read()).

I run into the same problem but actually only if I use the crates. If I use the dependencies from path it works fine for me. Did you fix it for you?

Using the suggested method with 3638df789e4f498b9058bbeb27bdddab4a80bd49 I can read the adc value one time for each ADC. On the second invocation it hangs again. The output of the ADC-example for stm32f1 is:

0.000000 TRACE BDCR ok: 00008200
└─ embassy_stm32::rcc::bd::{impl#2}::init @ /home/paulz/src/embedded/embassy/embassy-stm32/src/fmt.rs:117
0.000000 DEBUG rcc: Clocks { hclk1: Some(Hertz(8000000)), pclk1: Some(Hertz(8000000)), pclk1_tim: Some(Hertz(8000000)), pclk2: Some(Hertz(8000000)), pclk2_tim: Some(Hertz(8000000)), rtc: Some(Hertz(40000)), sys: Some(Hertz(8000000)), usb: None }
└─ embassy_stm32::rcc::set_freqs @ /home/paulz/src/embedded/embassy/embassy-stm32/src/fmt.rs:130
0.000030 INFO  Hello World!
└─ embassy_stm32f1_examples::____embassy_main_task::{async_fn#0} @ src/main.rs:19

The code hangs on the first loop iteration because read got called for vref.

The issue seems to be timing related. Adding a Timer::after_ticks(1).await; to https://github.com/embassy-rs/embassy/blob/3638df789e4f498b9058bbeb27bdddab4a80bd49/embassy-stm32/src/adc/f1.rs#L126 fixed the issue xD

Edit: even a Timer::after_ticks(1).await; in L124 fixes the issue.

pfzetto avatar Mar 06 '24 13:03 pfzetto