From 1b6e563260ec2b00cb518e0e801222ebd1ba9902 Mon Sep 17 00:00:00 2001 From: Adrian Wowk Date: Wed, 26 Mar 2025 17:11:27 -0500 Subject: [PATCH] rp/adc: fix potential race condition This commit rearranges the Adc::wait_for_ready function to make sure that wakers are registered before the interrupt is enabled, and keeps enabling the interrupt until the ADC is ready --- embassy-rp/src/adc.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index 8defb5231..1265a22a0 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs @@ -205,11 +205,13 @@ impl<'d> Adc<'d, Async> { fn wait_for_ready() -> impl Future { let r = Self::regs(); - r.inte().write(|w| w.set_fifo(true)); - compiler_fence(Ordering::SeqCst); poll_fn(move |cx| { WAKER.register(cx.waker()); + + r.inte().write(|w| w.set_fifo(true)); + compiler_fence(Ordering::SeqCst); + if r.cs().read().ready() { return Poll::Ready(()); }