From 3c6a13c620158ec65a1ee362e6aeb5ce90ec309c Mon Sep 17 00:00:00 2001 From: Michael Prantl Date: Fri, 3 May 2024 00:23:53 +0100 Subject: [PATCH 1/3] Fix oneshot adc read waiting indefinitely --- rp2040-hal/src/adc.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rp2040-hal/src/adc.rs b/rp2040-hal/src/adc.rs index 846677db7..1a5ba5457 100644 --- a/rp2040-hal/src/adc.rs +++ b/rp2040-hal/src/adc.rs @@ -404,12 +404,16 @@ impl Adc { /// /// Also returns immediately if start_many is set, to avoid indefinite blocking. pub fn wait_ready(&self) { - let cs = self.device.cs().read(); - while !cs.ready().bit_is_set() && !cs.start_many().bit_is_set() { + while !self.is_ready_or_free_running() { cortex_m::asm::nop(); } } + fn is_ready_or_free_running(&self) -> bool { + let cs = self.device.cs().read(); + cs.ready().bit_is_set() || cs.start_many().bit_is_set() + } + /// Returns true if the ADC is ready for the next conversion. /// /// This implies that any previous conversion has finished. From 1553ea7fb2994afee06e171f97fbf03b888ea53e Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Fri, 3 May 2024 06:16:26 +0000 Subject: [PATCH 2/3] This adds a test-case covering the fix from PR #799 --- on-target-tests/tests/gpio.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/on-target-tests/tests/gpio.rs b/on-target-tests/tests/gpio.rs index 2dc1c5daf..662c19a4d 100644 --- a/on-target-tests/tests/gpio.rs +++ b/on-target-tests/tests/gpio.rs @@ -100,4 +100,15 @@ mod tests { assert!(pac.PADS_BANK0.gpio(id).read().ie().bit_is_clear()); } } + + #[test] + fn read_adc() { + use embedded_hal_0_2::adc::OneShot; + + // Safety: Test cases do not run in parallel + let mut pac = unsafe { pac::Peripherals::steal() }; + let mut adc = hal::Adc::new(pac.ADC, &mut pac.RESETS); + let mut temp_sensor = hal::adc::Adc::take_temp_sensor(&mut adc).unwrap(); + let _temperature: u16 = adc.read(&mut temp_sensor).unwrap(); + } } From c9145ba9b90d38c4fe256a622cfe1cc67a0b94ab Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Fri, 3 May 2024 20:52:29 +0000 Subject: [PATCH 3/3] Add changelog entry for #799 --- rp2040-hal/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rp2040-hal/CHANGELOG.md b/rp2040-hal/CHANGELOG.md index b4e2175ba..e591df690 100644 --- a/rp2040-hal/CHANGELOG.md +++ b/rp2040-hal/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Fix oneshot adc read waiting indefinitely - #799 @mjptree + ## [0.10.1] - 2024-04-28 ### Added