From 5046a8a4a117f68c2792fac8dbbdb50fb0b1e3d8 Mon Sep 17 00:00:00 2001 From: maor malka Date: Mon, 6 Oct 2025 07:50:48 -0400 Subject: stm32/adc/v3: * spelling mistakes fixed * added required changes to ringbufferedadc to support G0 --- embassy-stm32/CHANGELOG.md | 2 +- embassy-stm32/src/adc/ringbuffered_v3.rs | 18 +++++++++--------- embassy-stm32/src/adc/v3.rs | 11 ++++++++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md index b661e0bae..6e069b22d 100644 --- a/embassy-stm32/CHANGELOG.md +++ b/embassy-stm32/CHANGELOG.md @@ -43,7 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - chore: Updated stm32-metapac and stm32-data dependencies - feat: stm32/adc/v3: allow DMA reads to loop through enable channels - fix: Fix XSPI not disabling alternate bytes when they were previously enabled -- feat: stm32/adc/v3: added support for Continous DMA configuration +- feat: stm32/adc/v3: added support for Continuous DMA configuration - fix: Fix stm32h7rs init when using external flash via XSPI - feat: Add Adc::new_with_clock() to configure analog clock - feat: Add GPDMA linked-list + ringbuffer support ([#3923](https://github.com/embassy-rs/embassy/pull/3923)) diff --git a/embassy-stm32/src/adc/ringbuffered_v3.rs b/embassy-stm32/src/adc/ringbuffered_v3.rs index d7af2322d..a2c9f2bca 100644 --- a/embassy-stm32/src/adc/ringbuffered_v3.rs +++ b/embassy-stm32/src/adc/ringbuffered_v3.rs @@ -37,7 +37,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> { } #[inline] - fn start_continous_sampling(&mut self) { + fn start_continuous_sampling(&mut self) { // Start adc conversion T::regs().cr().modify(|reg| { reg.set_adstart(true); @@ -46,7 +46,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> { } #[inline] - pub fn stop_continous_sampling(&mut self) { + pub fn stop_continuous_sampling(&mut self) { // Stop adc conversion if T::regs().cr().read().adstart() && !T::regs().cr().read().addis() { T::regs().cr().modify(|reg| { @@ -56,7 +56,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> { } } pub fn disable_adc(&mut self) { - self.stop_continous_sampling(); + self.stop_continuous_sampling(); self.ring_buf.clear(); self.ring_buf.request_pause(); } @@ -123,7 +123,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> { /// /// /// [`teardown_adc`]: #method.teardown_adc - /// [`start_continous_sampling`]: #method.start_continous_sampling + /// [`start_continuous_sampling`]: #method.start_continuous_sampling pub async fn read(&mut self, measurements: &mut [u16]) -> Result { assert_eq!( self.ring_buf.capacity() / 2, @@ -135,7 +135,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> { // Start background receive if it was not already started if !r.cr().read().adstart() { - self.start_continous_sampling(); + self.start_continuous_sampling(); } self.ring_buf.read_exact(measurements).await.map_err(|_| OverrunError) @@ -145,16 +145,16 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> { /// If no bytes are currently available in the buffer the call waits until the some /// bytes are available (at least one byte and at most half the buffer size) /// - /// Background receive is started if `start_continous_sampling()` has not been previously called. + /// Background receive is started if `start_continuous_sampling()` has not been previously called. /// /// Receive in the background is terminated if an error is returned. - /// It must then manually be started again by calling `start_continous_sampling()` or by re-calling `blocking_read()`. + /// It must then manually be started again by calling `start_continuous_sampling()` or by re-calling `blocking_read()`. pub fn blocking_read(&mut self, buf: &mut [u16]) -> Result { let r = T::regs(); // Start background receive if it was not already started if !r.cr().read().adstart() { - self.start_continous_sampling(); + self.start_continuous_sampling(); } loop { @@ -164,7 +164,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> { return Ok(len); } Err(_) => { - self.stop_continous_sampling(); + self.stop_continuous_sampling(); return Err(OverrunError); } } diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index f714e030f..ef68fe223 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs @@ -13,10 +13,10 @@ use super::{ blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, }; -#[cfg(adc_v3)] +#[cfg(adc_v3, adc_g0)] mod ringbuffered_v3; -#[cfg(adc_v3)] +#[cfg(adc_v3, adc_g0)] use ringbuffered_v3::RingBufferedAdc; use crate::dma::Transfer; @@ -576,7 +576,7 @@ impl<'d, T: Instance> Adc<'d, T> { /// It is critical to call `read` frequently to prevent DMA buffer overrun. /// /// [`read`]: #method.read - #[cfg(adc_v3)] + #[cfg(adc_v3, adc_g0)] pub fn into_ring_buffered<'a>( &mut self, dma: Peri<'a, impl RxDma>, @@ -633,6 +633,11 @@ impl<'d, T: Instance> Adc<'d, T> { } _ => unreachable!(), } + + #[cfg(any(adc_g0, adc_u0))] + { + channel_mask |= 1 << channel.channel(); + } } // On G0 and U0 enabled channels are sampled from 0 to last channel. -- cgit