aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/CHANGELOG.md2
-rw-r--r--embassy-stm32/src/adc/ringbuffered_v3.rs18
-rw-r--r--embassy-stm32/src/adc/v3.rs11
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
43- chore: Updated stm32-metapac and stm32-data dependencies 43- chore: Updated stm32-metapac and stm32-data dependencies
44- feat: stm32/adc/v3: allow DMA reads to loop through enable channels 44- feat: stm32/adc/v3: allow DMA reads to loop through enable channels
45- fix: Fix XSPI not disabling alternate bytes when they were previously enabled 45- fix: Fix XSPI not disabling alternate bytes when they were previously enabled
46- feat: stm32/adc/v3: added support for Continous DMA configuration 46- feat: stm32/adc/v3: added support for Continuous DMA configuration
47- fix: Fix stm32h7rs init when using external flash via XSPI 47- fix: Fix stm32h7rs init when using external flash via XSPI
48- feat: Add Adc::new_with_clock() to configure analog clock 48- feat: Add Adc::new_with_clock() to configure analog clock
49- feat: Add GPDMA linked-list + ringbuffer support ([#3923](https://github.com/embassy-rs/embassy/pull/3923)) 49- 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> {
37 } 37 }
38 38
39 #[inline] 39 #[inline]
40 fn start_continous_sampling(&mut self) { 40 fn start_continuous_sampling(&mut self) {
41 // Start adc conversion 41 // Start adc conversion
42 T::regs().cr().modify(|reg| { 42 T::regs().cr().modify(|reg| {
43 reg.set_adstart(true); 43 reg.set_adstart(true);
@@ -46,7 +46,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> {
46 } 46 }
47 47
48 #[inline] 48 #[inline]
49 pub fn stop_continous_sampling(&mut self) { 49 pub fn stop_continuous_sampling(&mut self) {
50 // Stop adc conversion 50 // Stop adc conversion
51 if T::regs().cr().read().adstart() && !T::regs().cr().read().addis() { 51 if T::regs().cr().read().adstart() && !T::regs().cr().read().addis() {
52 T::regs().cr().modify(|reg| { 52 T::regs().cr().modify(|reg| {
@@ -56,7 +56,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> {
56 } 56 }
57 } 57 }
58 pub fn disable_adc(&mut self) { 58 pub fn disable_adc(&mut self) {
59 self.stop_continous_sampling(); 59 self.stop_continuous_sampling();
60 self.ring_buf.clear(); 60 self.ring_buf.clear();
61 self.ring_buf.request_pause(); 61 self.ring_buf.request_pause();
62 } 62 }
@@ -123,7 +123,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> {
123 /// 123 ///
124 /// 124 ///
125 /// [`teardown_adc`]: #method.teardown_adc 125 /// [`teardown_adc`]: #method.teardown_adc
126 /// [`start_continous_sampling`]: #method.start_continous_sampling 126 /// [`start_continuous_sampling`]: #method.start_continuous_sampling
127 pub async fn read(&mut self, measurements: &mut [u16]) -> Result<usize, OverrunError> { 127 pub async fn read(&mut self, measurements: &mut [u16]) -> Result<usize, OverrunError> {
128 assert_eq!( 128 assert_eq!(
129 self.ring_buf.capacity() / 2, 129 self.ring_buf.capacity() / 2,
@@ -135,7 +135,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> {
135 135
136 // Start background receive if it was not already started 136 // Start background receive if it was not already started
137 if !r.cr().read().adstart() { 137 if !r.cr().read().adstart() {
138 self.start_continous_sampling(); 138 self.start_continuous_sampling();
139 } 139 }
140 140
141 self.ring_buf.read_exact(measurements).await.map_err(|_| OverrunError) 141 self.ring_buf.read_exact(measurements).await.map_err(|_| OverrunError)
@@ -145,16 +145,16 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> {
145 /// If no bytes are currently available in the buffer the call waits until the some 145 /// If no bytes are currently available in the buffer the call waits until the some
146 /// bytes are available (at least one byte and at most half the buffer size) 146 /// bytes are available (at least one byte and at most half the buffer size)
147 /// 147 ///
148 /// Background receive is started if `start_continous_sampling()` has not been previously called. 148 /// Background receive is started if `start_continuous_sampling()` has not been previously called.
149 /// 149 ///
150 /// Receive in the background is terminated if an error is returned. 150 /// Receive in the background is terminated if an error is returned.
151 /// It must then manually be started again by calling `start_continous_sampling()` or by re-calling `blocking_read()`. 151 /// It must then manually be started again by calling `start_continuous_sampling()` or by re-calling `blocking_read()`.
152 pub fn blocking_read(&mut self, buf: &mut [u16]) -> Result<usize, OverrunError> { 152 pub fn blocking_read(&mut self, buf: &mut [u16]) -> Result<usize, OverrunError> {
153 let r = T::regs(); 153 let r = T::regs();
154 154
155 // Start background receive if it was not already started 155 // Start background receive if it was not already started
156 if !r.cr().read().adstart() { 156 if !r.cr().read().adstart() {
157 self.start_continous_sampling(); 157 self.start_continuous_sampling();
158 } 158 }
159 159
160 loop { 160 loop {
@@ -164,7 +164,7 @@ impl<'d, T: Instance> RingBufferedAdc<'d, T> {
164 return Ok(len); 164 return Ok(len);
165 } 165 }
166 Err(_) => { 166 Err(_) => {
167 self.stop_continous_sampling(); 167 self.stop_continuous_sampling();
168 return Err(OverrunError); 168 return Err(OverrunError);
169 } 169 }
170 } 170 }
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::{
13 blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, 13 blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel,
14}; 14};
15 15
16#[cfg(adc_v3)] 16#[cfg(adc_v3, adc_g0)]
17mod ringbuffered_v3; 17mod ringbuffered_v3;
18 18
19#[cfg(adc_v3)] 19#[cfg(adc_v3, adc_g0)]
20use ringbuffered_v3::RingBufferedAdc; 20use ringbuffered_v3::RingBufferedAdc;
21 21
22use crate::dma::Transfer; 22use crate::dma::Transfer;
@@ -576,7 +576,7 @@ impl<'d, T: Instance> Adc<'d, T> {
576 /// It is critical to call `read` frequently to prevent DMA buffer overrun. 576 /// It is critical to call `read` frequently to prevent DMA buffer overrun.
577 /// 577 ///
578 /// [`read`]: #method.read 578 /// [`read`]: #method.read
579 #[cfg(adc_v3)] 579 #[cfg(adc_v3, adc_g0)]
580 pub fn into_ring_buffered<'a>( 580 pub fn into_ring_buffered<'a>(
581 &mut self, 581 &mut self,
582 dma: Peri<'a, impl RxDma<T>>, 582 dma: Peri<'a, impl RxDma<T>>,
@@ -633,6 +633,11 @@ impl<'d, T: Instance> Adc<'d, T> {
633 } 633 }
634 _ => unreachable!(), 634 _ => unreachable!(),
635 } 635 }
636
637 #[cfg(any(adc_g0, adc_u0))]
638 {
639 channel_mask |= 1 << channel.channel();
640 }
636 } 641 }
637 642
638 // On G0 and U0 enabled channels are sampled from 0 to last channel. 643 // On G0 and U0 enabled channels are sampled from 0 to last channel.