Skip to content
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

ADC interrupt for STM32F103 doesn't work property #3805

Open
Tnze opened this issue Jan 25, 2025 · 3 comments
Open

ADC interrupt for STM32F103 doesn't work property #3805

Tnze opened this issue Jan 25, 2025 · 3 comments

Comments

@Tnze
Copy link

Tnze commented Jan 25, 2025

Current ADC implement only works on the example. Adding totally unrelated parts to the program breaks the ADC function.

  • The default sample time SampleTime::CYCLES1_5 works. Set to other cause Adc::read().await hang-up forever.
  • Then add line defmt::info!("convert started"); to embassy-stm32/src/adc/f1.rs file convert() function above line T::state().waker.register(.... makes it work...
  • My project uses USB CDC. When start the USB task, ADC doesn't work, when remove USB stuffs the ADC works again.

, which is quite confusing. And it takes my hours to debug.

It turns out that the ADC End of Convert interrupt doesn't triggered at all. So the poll_fn wouldn't wake up once it go pending. It only works if the convert was completed before first time the poll_fn is polled.

poll_fn(|cx| {
T::state().waker.register(cx.waker());
if !T::regs().cr2().read().swstart() && T::regs().sr().read().eoc() {
Poll::Ready(())
} else {
Poll::Pending
}
})

@Tnze
Copy link
Author

Tnze commented Jan 25, 2025

Also, the example stm32f1/src/bin/adc.rs only works on Debug. Release doesn't work.

I think it's because of Debug runs a lot slowly, so that the ADC can finish its work before the HAL first query the eof flag.

@Tnze
Copy link
Author

Tnze commented Jan 25, 2025

Regards @xoviat ,
I would be grateful if you could help. I'm unable to find the reason why the EOC interrupt didn't be triggered.

@Tnze
Copy link
Author

Tnze commented Jan 25, 2025

Add this line fix this problem:

unsafe { NVIC::unmask(pac::interrupt::ADC1_2) };

Tnze added a commit to Tnze/embassy that referenced this issue Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant