aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src
diff options
context:
space:
mode:
authorchasingRs <[email protected]>2025-10-10 10:26:46 +0800
committerGitHub <[email protected]>2025-10-10 10:26:46 +0800
commit944fda48a94c2d6cb6bea56c8c8471858d75da7d (patch)
tree1e3e2f463c2440afe81ca37b2e161f85d0bfc374 /embassy-stm32/src
parent04171d903d3676d87aa0fd85719878d3087028f3 (diff)
parent35b0ba4ce0fed7588febe504e16bbf1788384f5a (diff)
Merge branch 'embassy-rs:main' into fix/simple-pwm-32bit-timer-support
Diffstat (limited to 'embassy-stm32/src')
-rw-r--r--embassy-stm32/src/adc/adc4.rs9
-rw-r--r--embassy-stm32/src/adc/c0.rs9
-rw-r--r--embassy-stm32/src/adc/f1.rs2
-rw-r--r--embassy-stm32/src/adc/f3.rs2
-rw-r--r--embassy-stm32/src/adc/f3_v1_1.rs2
-rw-r--r--embassy-stm32/src/adc/g4.rs9
-rw-r--r--embassy-stm32/src/adc/mod.rs2
-rw-r--r--embassy-stm32/src/adc/ringbuffered_v2.rs4
-rw-r--r--embassy-stm32/src/adc/v1.rs8
-rw-r--r--embassy-stm32/src/adc/v2.rs2
-rw-r--r--embassy-stm32/src/adc/v3.rs4
-rw-r--r--embassy-stm32/src/adc/v4.rs9
-rw-r--r--embassy-stm32/src/can/bxcan/mod.rs12
-rw-r--r--embassy-stm32/src/can/fd/config.rs2
-rw-r--r--embassy-stm32/src/can/fdcan.rs12
-rw-r--r--embassy-stm32/src/can/util.rs2
-rw-r--r--embassy-stm32/src/crc/v1.rs2
-rw-r--r--embassy-stm32/src/crc/v2v3.rs4
-rw-r--r--embassy-stm32/src/cryp/mod.rs10
-rw-r--r--embassy-stm32/src/dac/mod.rs2
-rw-r--r--embassy-stm32/src/dcmi.rs2
-rw-r--r--embassy-stm32/src/dma/dma_bdma.rs4
-rw-r--r--embassy-stm32/src/dma/gpdma/mod.rs2
-rw-r--r--embassy-stm32/src/dma/gpdma/ringbuffered.rs4
-rw-r--r--embassy-stm32/src/dma/mod.rs2
-rw-r--r--embassy-stm32/src/dma/ringbuffer/tests/prop_test/mod.rs2
-rw-r--r--embassy-stm32/src/dsihost.rs2
-rw-r--r--embassy-stm32/src/dts/mod.rs2
-rw-r--r--embassy-stm32/src/eth/v1/mod.rs8
-rw-r--r--embassy-stm32/src/eth/v1/rx_desc.rs2
-rw-r--r--embassy-stm32/src/eth/v1/tx_desc.rs2
-rw-r--r--embassy-stm32/src/eth/v2/descriptors.rs2
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs6
-rw-r--r--embassy-stm32/src/exti.rs6
-rw-r--r--embassy-stm32/src/flash/asynch.rs8
-rw-r--r--embassy-stm32/src/flash/common.rs8
-rw-r--r--embassy-stm32/src/flash/eeprom.rs2
-rw-r--r--embassy-stm32/src/flash/f0.rs2
-rw-r--r--embassy-stm32/src/flash/f1f3.rs2
-rw-r--r--embassy-stm32/src/flash/f2.rs4
-rw-r--r--embassy-stm32/src/flash/f4.rs24
-rw-r--r--embassy-stm32/src/flash/f7.rs12
-rw-r--r--embassy-stm32/src/flash/g.rs18
-rw-r--r--embassy-stm32/src/flash/h5.rs2
-rw-r--r--embassy-stm32/src/flash/h50.rs2
-rw-r--r--embassy-stm32/src/flash/h7.rs4
-rw-r--r--embassy-stm32/src/flash/l.rs18
-rw-r--r--embassy-stm32/src/flash/u0.rs2
-rw-r--r--embassy-stm32/src/flash/u5.rs2
-rw-r--r--embassy-stm32/src/fmc.rs2
-rw-r--r--embassy-stm32/src/gpio.rs2
-rw-r--r--embassy-stm32/src/hash/mod.rs8
-rw-r--r--embassy-stm32/src/hsem/mod.rs4
-rw-r--r--embassy-stm32/src/hspi/mod.rs2
-rw-r--r--embassy-stm32/src/i2c/mod.rs4
-rw-r--r--embassy-stm32/src/i2c/v1.rs8
-rw-r--r--embassy-stm32/src/i2c/v2.rs2
-rw-r--r--embassy-stm32/src/i2s.rs4
-rw-r--r--embassy-stm32/src/ipcc.rs2
-rw-r--r--embassy-stm32/src/lib.rs5
-rw-r--r--embassy-stm32/src/low_power.rs4
-rw-r--r--embassy-stm32/src/lptim/pwm.rs6
-rw-r--r--embassy-stm32/src/ltdc.rs2
-rw-r--r--embassy-stm32/src/opamp.rs2
-rw-r--r--embassy-stm32/src/ospi/mod.rs6
-rw-r--r--embassy-stm32/src/qspi/mod.rs2
-rw-r--r--embassy-stm32/src/rcc/bd.rs4
-rw-r--r--embassy-stm32/src/rcc/f247.rs4
-rw-r--r--embassy-stm32/src/rcc/h.rs5
-rw-r--r--embassy-stm32/src/rcc/l.rs8
-rw-r--r--embassy-stm32/src/rcc/mco.rs27
-rw-r--r--embassy-stm32/src/rcc/mod.rs2
-rw-r--r--embassy-stm32/src/rcc/u5.rs9
-rw-r--r--embassy-stm32/src/rcc/wba.rs9
-rw-r--r--embassy-stm32/src/rng.rs2
-rw-r--r--embassy-stm32/src/rtc/low_power.rs2
-rw-r--r--embassy-stm32/src/rtc/mod.rs8
-rw-r--r--embassy-stm32/src/rtc/v3.rs2
-rw-r--r--embassy-stm32/src/sai/mod.rs6
-rw-r--r--embassy-stm32/src/sdmmc/mod.rs6
-rw-r--r--embassy-stm32/src/spdifrx/mod.rs2
-rw-r--r--embassy-stm32/src/spi/mod.rs8
-rw-r--r--embassy-stm32/src/time_driver.rs6
-rw-r--r--embassy-stm32/src/timer/complementary_pwm.rs6
-rw-r--r--embassy-stm32/src/timer/input_capture.rs2
-rw-r--r--embassy-stm32/src/timer/one_pulse.rs2
-rw-r--r--embassy-stm32/src/timer/pwm_input.rs2
-rw-r--r--embassy-stm32/src/timer/qei.rs102
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs2
-rw-r--r--embassy-stm32/src/tsc/acquisition_banks.rs4
-rw-r--r--embassy-stm32/src/tsc/pin_groups.rs4
-rw-r--r--embassy-stm32/src/ucpd.rs4
-rw-r--r--embassy-stm32/src/usart/buffered.rs73
-rw-r--r--embassy-stm32/src/usart/mod.rs77
-rw-r--r--embassy-stm32/src/usart/ringbuffered.rs126
-rw-r--r--embassy-stm32/src/usb/otg.rs10
-rw-r--r--embassy-stm32/src/usb/usb.rs4
-rw-r--r--embassy-stm32/src/vrefbuf/mod.rs3
-rw-r--r--embassy-stm32/src/wdg/mod.rs2
-rw-r--r--embassy-stm32/src/xspi/mod.rs6
100 files changed, 549 insertions, 319 deletions
diff --git a/embassy-stm32/src/adc/adc4.rs b/embassy-stm32/src/adc/adc4.rs
index 255dc7956..2608160a3 100644
--- a/embassy-stm32/src/adc/adc4.rs
+++ b/embassy-stm32/src/adc/adc4.rs
@@ -4,7 +4,7 @@ use pac::adc::vals::{Adc4Dmacfg as Dmacfg, Adc4Exten as Exten, Adc4OversamplingR
4#[cfg(stm32wba)] 4#[cfg(stm32wba)]
5use pac::adc::vals::{Chselrmod, Cont, Dmacfg, Exten, OversamplingRatio, Ovss, Smpsel}; 5use pac::adc::vals::{Chselrmod, Cont, Dmacfg, Exten, OversamplingRatio, Ovss, Smpsel};
6 6
7use super::{blocking_delay_us, AdcChannel, AnyAdcChannel, RxDma4, SealedAdcChannel}; 7use super::{AdcChannel, AnyAdcChannel, RxDma4, SealedAdcChannel, blocking_delay_us};
8use crate::dma::Transfer; 8use crate::dma::Transfer;
9#[cfg(stm32u5)] 9#[cfg(stm32u5)]
10pub use crate::pac::adc::regs::Adc4Chselrmod0 as Chselr; 10pub use crate::pac::adc::regs::Adc4Chselrmod0 as Chselr;
@@ -15,7 +15,7 @@ pub use crate::pac::adc::vals::{Adc4Presc as Presc, Adc4Res as Resolution, Adc4S
15#[cfg(stm32wba)] 15#[cfg(stm32wba)]
16pub use crate::pac::adc::vals::{Presc, Res as Resolution, SampleTime}; 16pub use crate::pac::adc::vals::{Presc, Res as Resolution, SampleTime};
17use crate::time::Hertz; 17use crate::time::Hertz;
18use crate::{pac, rcc, Peri}; 18use crate::{Peri, pac, rcc};
19 19
20const MAX_ADC_CLK_FREQ: Hertz = Hertz::mhz(55); 20const MAX_ADC_CLK_FREQ: Hertz = Hertz::mhz(55);
21 21
@@ -208,7 +208,10 @@ impl<'d, T: Instance> Adc4<'d, T> {
208 info!("ADC4 frequency set to {}", frequency); 208 info!("ADC4 frequency set to {}", frequency);
209 209
210 if frequency > MAX_ADC_CLK_FREQ { 210 if frequency > MAX_ADC_CLK_FREQ {
211 panic!("Maximal allowed frequency for ADC4 is {} MHz and it varies with different packages, refer to ST docs for more information.", MAX_ADC_CLK_FREQ.0 / 1_000_000 ); 211 panic!(
212 "Maximal allowed frequency for ADC4 is {} MHz and it varies with different packages, refer to ST docs for more information.",
213 MAX_ADC_CLK_FREQ.0 / 1_000_000
214 );
212 } 215 }
213 216
214 let mut s = Self { adc }; 217 let mut s = Self { adc };
diff --git a/embassy-stm32/src/adc/c0.rs b/embassy-stm32/src/adc/c0.rs
index f2837a8f1..fc28df346 100644
--- a/embassy-stm32/src/adc/c0.rs
+++ b/embassy-stm32/src/adc/c0.rs
@@ -4,11 +4,11 @@ use pac::adc::vals::{Adstp, Align, Ckmode, Dmacfg, Exten, Ovrmod, Ovsr};
4use pac::adccommon::vals::Presc; 4use pac::adccommon::vals::Presc;
5 5
6use super::{ 6use super::{
7 blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, 7 Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, blocking_delay_us,
8}; 8};
9use crate::dma::Transfer; 9use crate::dma::Transfer;
10use crate::time::Hertz; 10use crate::time::Hertz;
11use crate::{pac, rcc, Peri}; 11use crate::{Peri, pac, rcc};
12 12
13/// Default VREF voltage used for sample conversion to millivolts. 13/// Default VREF voltage used for sample conversion to millivolts.
14pub const VREF_DEFAULT_MV: u32 = 3300; 14pub const VREF_DEFAULT_MV: u32 = 3300;
@@ -168,7 +168,10 @@ impl<'d, T: Instance> Adc<'d, T> {
168 debug!("ADC frequency set to {}", frequency); 168 debug!("ADC frequency set to {}", frequency);
169 169
170 if frequency > MAX_ADC_CLK_FREQ { 170 if frequency > MAX_ADC_CLK_FREQ {
171 panic!("Maximal allowed frequency for the ADC is {} MHz and it varies with different packages, refer to ST docs for more information.", MAX_ADC_CLK_FREQ.0 / 1_000_000 ); 171 panic!(
172 "Maximal allowed frequency for the ADC is {} MHz and it varies with different packages, refer to ST docs for more information.",
173 MAX_ADC_CLK_FREQ.0 / 1_000_000
174 );
172 } 175 }
173 176
174 let mut s = Self { 177 let mut s = Self {
diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs
index 3cdc9d8fb..f9c23d72b 100644
--- a/embassy-stm32/src/adc/f1.rs
+++ b/embassy-stm32/src/adc/f1.rs
@@ -7,7 +7,7 @@ use crate::adc::{Adc, AdcChannel, Instance, SampleTime};
7use crate::interrupt::typelevel::Interrupt; 7use crate::interrupt::typelevel::Interrupt;
8use crate::interrupt::{self}; 8use crate::interrupt::{self};
9use crate::time::Hertz; 9use crate::time::Hertz;
10use crate::{rcc, Peri}; 10use crate::{Peri, rcc};
11 11
12pub const VDDA_CALIB_MV: u32 = 3300; 12pub const VDDA_CALIB_MV: u32 = 3300;
13pub const ADC_MAX: u32 = (1 << 12) - 1; 13pub const ADC_MAX: u32 = (1 << 12) - 1;
diff --git a/embassy-stm32/src/adc/f3.rs b/embassy-stm32/src/adc/f3.rs
index 3aeb6f2c7..73ceb087a 100644
--- a/embassy-stm32/src/adc/f3.rs
+++ b/embassy-stm32/src/adc/f3.rs
@@ -6,7 +6,7 @@ use super::blocking_delay_us;
6use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; 6use crate::adc::{Adc, AdcChannel, Instance, SampleTime};
7use crate::interrupt::typelevel::Interrupt; 7use crate::interrupt::typelevel::Interrupt;
8use crate::time::Hertz; 8use crate::time::Hertz;
9use crate::{interrupt, rcc, Peri}; 9use crate::{Peri, interrupt, rcc};
10 10
11pub const VDDA_CALIB_MV: u32 = 3300; 11pub const VDDA_CALIB_MV: u32 = 3300;
12pub const ADC_MAX: u32 = (1 << 12) - 1; 12pub const ADC_MAX: u32 = (1 << 12) - 1;
diff --git a/embassy-stm32/src/adc/f3_v1_1.rs b/embassy-stm32/src/adc/f3_v1_1.rs
index 84613078c..cd5de54f5 100644
--- a/embassy-stm32/src/adc/f3_v1_1.rs
+++ b/embassy-stm32/src/adc/f3_v1_1.rs
@@ -9,7 +9,7 @@ use super::Resolution;
9use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; 9use crate::adc::{Adc, AdcChannel, Instance, SampleTime};
10use crate::interrupt::typelevel::Interrupt; 10use crate::interrupt::typelevel::Interrupt;
11use crate::time::Hertz; 11use crate::time::Hertz;
12use crate::{interrupt, rcc, Peri}; 12use crate::{Peri, interrupt, rcc};
13 13
14const ADC_FREQ: Hertz = crate::rcc::HSI_FREQ; 14const ADC_FREQ: Hertz = crate::rcc::HSI_FREQ;
15 15
diff --git a/embassy-stm32/src/adc/g4.rs b/embassy-stm32/src/adc/g4.rs
index 43498966f..5098aadd8 100644
--- a/embassy-stm32/src/adc/g4.rs
+++ b/embassy-stm32/src/adc/g4.rs
@@ -7,11 +7,11 @@ use pac::adc::vals::{Adcaldif, Difsel, Exten, Rovsm, Trovs};
7use pac::adccommon::vals::Presc; 7use pac::adccommon::vals::Presc;
8use stm32_metapac::adc::vals::{Adstp, Dmacfg, Dmaen}; 8use stm32_metapac::adc::vals::{Adstp, Dmacfg, Dmaen};
9 9
10use super::{blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime}; 10use super::{Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, blocking_delay_us};
11use crate::adc::SealedAdcChannel; 11use crate::adc::SealedAdcChannel;
12use crate::dma::Transfer; 12use crate::dma::Transfer;
13use crate::time::Hertz; 13use crate::time::Hertz;
14use crate::{pac, rcc, Peri}; 14use crate::{Peri, pac, rcc};
15 15
16/// Default VREF voltage used for sample conversion to millivolts. 16/// Default VREF voltage used for sample conversion to millivolts.
17pub const VREF_DEFAULT_MV: u32 = 3300; 17pub const VREF_DEFAULT_MV: u32 = 3300;
@@ -133,7 +133,10 @@ impl<'d, T: Instance> Adc<'d, T> {
133 trace!("ADC frequency set to {}", frequency); 133 trace!("ADC frequency set to {}", frequency);
134 134
135 if frequency > MAX_ADC_CLK_FREQ { 135 if frequency > MAX_ADC_CLK_FREQ {
136 panic!("Maximal allowed frequency for the ADC is {} MHz and it varies with different packages, refer to ST docs for more information.", MAX_ADC_CLK_FREQ.0 / 1_000_000 ); 136 panic!(
137 "Maximal allowed frequency for the ADC is {} MHz and it varies with different packages, refer to ST docs for more information.",
138 MAX_ADC_CLK_FREQ.0 / 1_000_000
139 );
137 } 140 }
138 141
139 let mut s = Self { 142 let mut s = Self {
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs
index ea986f4cf..22ed8295f 100644
--- a/embassy-stm32/src/adc/mod.rs
+++ b/embassy-stm32/src/adc/mod.rs
@@ -22,7 +22,7 @@ use core::marker::PhantomData;
22#[allow(unused)] 22#[allow(unused)]
23#[cfg(not(any(adc_f3v3, adc_wba)))] 23#[cfg(not(any(adc_f3v3, adc_wba)))]
24pub use _version::*; 24pub use _version::*;
25use embassy_hal_internal::{impl_peripheral, PeripheralType}; 25use embassy_hal_internal::{PeripheralType, impl_peripheral};
26#[cfg(any(adc_f1, adc_f3v1, adc_v1, adc_l0, adc_f3v2))] 26#[cfg(any(adc_f1, adc_f3v1, adc_v1, adc_l0, adc_f3v2))]
27use embassy_sync::waitqueue::AtomicWaker; 27use embassy_sync::waitqueue::AtomicWaker;
28 28
diff --git a/embassy-stm32/src/adc/ringbuffered_v2.rs b/embassy-stm32/src/adc/ringbuffered_v2.rs
index 6f69e8486..9b2e5b8fe 100644
--- a/embassy-stm32/src/adc/ringbuffered_v2.rs
+++ b/embassy-stm32/src/adc/ringbuffered_v2.rs
@@ -1,13 +1,13 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::mem; 2use core::mem;
3use core::sync::atomic::{compiler_fence, Ordering}; 3use core::sync::atomic::{Ordering, compiler_fence};
4 4
5use stm32_metapac::adc::vals::SampleTime; 5use stm32_metapac::adc::vals::SampleTime;
6 6
7use crate::adc::{Adc, AdcChannel, Instance, RxDma}; 7use crate::adc::{Adc, AdcChannel, Instance, RxDma};
8use crate::dma::{Priority, ReadableRingBuffer, TransferOptions}; 8use crate::dma::{Priority, ReadableRingBuffer, TransferOptions};
9use crate::pac::adc::vals; 9use crate::pac::adc::vals;
10use crate::{rcc, Peri}; 10use crate::{Peri, rcc};
11 11
12#[cfg_attr(feature = "defmt", derive(defmt::Format))] 12#[cfg_attr(feature = "defmt", derive(defmt::Format))]
13pub struct OverrunError; 13pub struct OverrunError;
diff --git a/embassy-stm32/src/adc/v1.rs b/embassy-stm32/src/adc/v1.rs
index d09374876..a5869d110 100644
--- a/embassy-stm32/src/adc/v1.rs
+++ b/embassy-stm32/src/adc/v1.rs
@@ -9,7 +9,7 @@ use super::blocking_delay_us;
9use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; 9use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime};
10use crate::interrupt::typelevel::Interrupt; 10use crate::interrupt::typelevel::Interrupt;
11use crate::peripherals::ADC1; 11use crate::peripherals::ADC1;
12use crate::{interrupt, rcc, Peri}; 12use crate::{Peri, interrupt, rcc};
13 13
14mod watchdog_v1; 14mod watchdog_v1;
15pub use watchdog_v1::WatchdogChannels; 15pub use watchdog_v1::WatchdogChannels;
@@ -66,11 +66,7 @@ pub struct Temperature;
66impl AdcChannel<ADC1> for Temperature {} 66impl AdcChannel<ADC1> for Temperature {}
67impl super::SealedAdcChannel<ADC1> for Temperature { 67impl super::SealedAdcChannel<ADC1> for Temperature {
68 fn channel(&self) -> u8 { 68 fn channel(&self) -> u8 {
69 if cfg!(adc_l0) { 69 if cfg!(adc_l0) { 18 } else { 16 }
70 18
71 } else {
72 16
73 }
74 } 70 }
75} 71}
76 72
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs
index e94a25b24..93ec78548 100644
--- a/embassy-stm32/src/adc/v2.rs
+++ b/embassy-stm32/src/adc/v2.rs
@@ -2,7 +2,7 @@ use super::blocking_delay_us;
2use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; 2use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime};
3use crate::peripherals::ADC1; 3use crate::peripherals::ADC1;
4use crate::time::Hertz; 4use crate::time::Hertz;
5use crate::{rcc, Peri}; 5use crate::{Peri, rcc};
6 6
7mod ringbuffered_v2; 7mod ringbuffered_v2;
8pub use ringbuffered_v2::{RingBufferedAdc, Sequence}; 8pub use ringbuffered_v2::{RingBufferedAdc, Sequence};
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs
index 16063ce4d..47632263b 100644
--- a/embassy-stm32/src/adc/v3.rs
+++ b/embassy-stm32/src/adc/v3.rs
@@ -10,10 +10,10 @@ use pac::adc::vals::{OversamplingRatio, OversamplingShift, Rovsm, Trovs};
10pub use pac::adc::vals::{Ovsr, Ovss, Presc}; 10pub use pac::adc::vals::{Ovsr, Ovss, Presc};
11 11
12use super::{ 12use super::{
13 blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, 13 Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, blocking_delay_us,
14}; 14};
15use crate::dma::Transfer; 15use crate::dma::Transfer;
16use crate::{pac, rcc, Peri}; 16use crate::{Peri, pac, rcc};
17 17
18/// Default VREF voltage used for sample conversion to millivolts. 18/// Default VREF voltage used for sample conversion to millivolts.
19pub const VREF_DEFAULT_MV: u32 = 3300; 19pub const VREF_DEFAULT_MV: u32 = 3300;
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs
index b66437e6e..c7d0103a6 100644
--- a/embassy-stm32/src/adc/v4.rs
+++ b/embassy-stm32/src/adc/v4.rs
@@ -5,11 +5,11 @@ use pac::adc::vals::{Adstp, Difsel, Dmngt, Exten, Pcsel};
5use pac::adccommon::vals::Presc; 5use pac::adccommon::vals::Presc;
6 6
7use super::{ 7use super::{
8 blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, 8 Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, blocking_delay_us,
9}; 9};
10use crate::dma::Transfer; 10use crate::dma::Transfer;
11use crate::time::Hertz; 11use crate::time::Hertz;
12use crate::{pac, rcc, Peri}; 12use crate::{Peri, pac, rcc};
13 13
14/// Default VREF voltage used for sample conversion to millivolts. 14/// Default VREF voltage used for sample conversion to millivolts.
15pub const VREF_DEFAULT_MV: u32 = 3300; 15pub const VREF_DEFAULT_MV: u32 = 3300;
@@ -171,7 +171,10 @@ impl<'d, T: Instance> Adc<'d, T> {
171 info!("ADC frequency set to {}", frequency); 171 info!("ADC frequency set to {}", frequency);
172 172
173 if frequency > MAX_ADC_CLK_FREQ { 173 if frequency > MAX_ADC_CLK_FREQ {
174 panic!("Maximal allowed frequency for the ADC is {} MHz and it varies with different packages, refer to ST docs for more information.", MAX_ADC_CLK_FREQ.0 / 1_000_000 ); 174 panic!(
175 "Maximal allowed frequency for the ADC is {} MHz and it varies with different packages, refer to ST docs for more information.",
176 MAX_ADC_CLK_FREQ.0 / 1_000_000
177 );
175 } 178 }
176 179
177 #[cfg(stm32h7)] 180 #[cfg(stm32h7)]
diff --git a/embassy-stm32/src/can/bxcan/mod.rs b/embassy-stm32/src/can/bxcan/mod.rs
index 8eb188560..507350c42 100644
--- a/embassy-stm32/src/can/bxcan/mod.rs
+++ b/embassy-stm32/src/can/bxcan/mod.rs
@@ -5,8 +5,8 @@ use core::future::poll_fn;
5use core::marker::PhantomData; 5use core::marker::PhantomData;
6use core::task::Poll; 6use core::task::Poll;
7 7
8use embassy_hal_internal::interrupt::InterruptExt;
9use embassy_hal_internal::PeripheralType; 8use embassy_hal_internal::PeripheralType;
9use embassy_hal_internal::interrupt::InterruptExt;
10use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 10use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
11use embassy_sync::channel::Channel; 11use embassy_sync::channel::Channel;
12use embassy_sync::waitqueue::AtomicWaker; 12use embassy_sync::waitqueue::AtomicWaker;
@@ -22,7 +22,7 @@ use crate::can::enums::{BusError, RefCountOp, TryReadError};
22use crate::gpio::{AfType, OutputType, Pull, Speed}; 22use crate::gpio::{AfType, OutputType, Pull, Speed};
23use crate::interrupt::typelevel::Interrupt; 23use crate::interrupt::typelevel::Interrupt;
24use crate::rcc::{self, RccPeripheral}; 24use crate::rcc::{self, RccPeripheral};
25use crate::{interrupt, peripherals, Peri}; 25use crate::{Peri, interrupt, peripherals};
26 26
27/// Interrupt handler. 27/// Interrupt handler.
28pub struct TxInterruptHandler<T: Instance> { 28pub struct TxInterruptHandler<T: Instance> {
@@ -186,10 +186,10 @@ impl<'d> Can<'d> {
186 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>, 186 rx: Peri<'d, if_afio!(impl RxPin<T, A>)>,
187 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>, 187 tx: Peri<'d, if_afio!(impl TxPin<T, A>)>,
188 _irqs: impl interrupt::typelevel::Binding<T::TXInterrupt, TxInterruptHandler<T>> 188 _irqs: impl interrupt::typelevel::Binding<T::TXInterrupt, TxInterruptHandler<T>>
189 + interrupt::typelevel::Binding<T::RX0Interrupt, Rx0InterruptHandler<T>> 189 + interrupt::typelevel::Binding<T::RX0Interrupt, Rx0InterruptHandler<T>>
190 + interrupt::typelevel::Binding<T::RX1Interrupt, Rx1InterruptHandler<T>> 190 + interrupt::typelevel::Binding<T::RX1Interrupt, Rx1InterruptHandler<T>>
191 + interrupt::typelevel::Binding<T::SCEInterrupt, SceInterruptHandler<T>> 191 + interrupt::typelevel::Binding<T::SCEInterrupt, SceInterruptHandler<T>>
192 + 'd, 192 + 'd,
193 ) -> Self { 193 ) -> Self {
194 let info = T::info(); 194 let info = T::info();
195 let regs = &T::info().regs; 195 let regs = &T::info().regs;
diff --git a/embassy-stm32/src/can/fd/config.rs b/embassy-stm32/src/can/fd/config.rs
index c6a66b469..e08349f02 100644
--- a/embassy-stm32/src/can/fd/config.rs
+++ b/embassy-stm32/src/can/fd/config.rs
@@ -1,7 +1,7 @@
1//! Configuration for FDCAN Module 1//! Configuration for FDCAN Module
2// Note: This file is copied and modified from fdcan crate by Richard Meadows 2// Note: This file is copied and modified from fdcan crate by Richard Meadows
3 3
4use core::num::{NonZeroU16, NonZeroU8}; 4use core::num::{NonZeroU8, NonZeroU16};
5 5
6/// Configures the bit timings. 6/// Configures the bit timings.
7/// 7///
diff --git a/embassy-stm32/src/can/fdcan.rs b/embassy-stm32/src/can/fdcan.rs
index d8f71e03e..a142a6d63 100644
--- a/embassy-stm32/src/can/fdcan.rs
+++ b/embassy-stm32/src/can/fdcan.rs
@@ -3,8 +3,8 @@ use core::future::poll_fn;
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::task::Poll; 4use core::task::Poll;
5 5
6use embassy_hal_internal::interrupt::InterruptExt;
7use embassy_hal_internal::PeripheralType; 6use embassy_hal_internal::PeripheralType;
7use embassy_hal_internal::interrupt::InterruptExt;
8use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 8use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
9use embassy_sync::channel::Channel; 9use embassy_sync::channel::Channel;
10use embassy_sync::waitqueue::AtomicWaker; 10use embassy_sync::waitqueue::AtomicWaker;
@@ -13,7 +13,7 @@ use crate::can::fd::peripheral::Registers;
13use crate::gpio::{AfType, OutputType, Pull, SealedPin as _, Speed}; 13use crate::gpio::{AfType, OutputType, Pull, SealedPin as _, Speed};
14use crate::interrupt::typelevel::Interrupt; 14use crate::interrupt::typelevel::Interrupt;
15use crate::rcc::{self, RccPeripheral}; 15use crate::rcc::{self, RccPeripheral};
16use crate::{interrupt, peripherals, Peri}; 16use crate::{Peri, interrupt, peripherals};
17 17
18pub(crate) mod fd; 18pub(crate) mod fd;
19 19
@@ -182,8 +182,8 @@ impl<'d> CanConfigurator<'d> {
182 rx: Peri<'d, impl RxPin<T>>, 182 rx: Peri<'d, impl RxPin<T>>,
183 tx: Peri<'d, impl TxPin<T>>, 183 tx: Peri<'d, impl TxPin<T>>,
184 _irqs: impl interrupt::typelevel::Binding<T::IT0Interrupt, IT0InterruptHandler<T>> 184 _irqs: impl interrupt::typelevel::Binding<T::IT0Interrupt, IT0InterruptHandler<T>>
185 + interrupt::typelevel::Binding<T::IT1Interrupt, IT1InterruptHandler<T>> 185 + interrupt::typelevel::Binding<T::IT1Interrupt, IT1InterruptHandler<T>>
186 + 'd, 186 + 'd,
187 ) -> CanConfigurator<'d> { 187 ) -> CanConfigurator<'d> {
188 set_as_af!(rx, AfType::input(Pull::None)); 188 set_as_af!(rx, AfType::input(Pull::None));
189 set_as_af!(tx, AfType::output(OutputType::PushPull, Speed::VeryHigh)); 189 set_as_af!(tx, AfType::output(OutputType::PushPull, Speed::VeryHigh));
@@ -459,7 +459,7 @@ impl<'c, 'd, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> BufferedCan<'d,
459 pub async fn write(&mut self, frame: Frame) { 459 pub async fn write(&mut self, frame: Frame) {
460 self.tx_buf.send(frame).await; 460 self.tx_buf.send(frame).await;
461 self.info.interrupt0.pend(); // Wake for Tx 461 self.info.interrupt0.pend(); // Wake for Tx
462 //T::IT0Interrupt::pend(); // Wake for Tx 462 //T::IT0Interrupt::pend(); // Wake for Tx
463 } 463 }
464 464
465 /// Async read frame from RX buffer. 465 /// Async read frame from RX buffer.
@@ -548,7 +548,7 @@ impl<'c, 'd, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> BufferedCanFd<'
548 pub async fn write(&mut self, frame: FdFrame) { 548 pub async fn write(&mut self, frame: FdFrame) {
549 self.tx_buf.send(frame).await; 549 self.tx_buf.send(frame).await;
550 self.info.interrupt0.pend(); // Wake for Tx 550 self.info.interrupt0.pend(); // Wake for Tx
551 //T::IT0Interrupt::pend(); // Wake for Tx 551 //T::IT0Interrupt::pend(); // Wake for Tx
552 } 552 }
553 553
554 /// Async read frame from RX buffer. 554 /// Async read frame from RX buffer.
diff --git a/embassy-stm32/src/can/util.rs b/embassy-stm32/src/can/util.rs
index fcdbbad62..6d7f0c16a 100644
--- a/embassy-stm32/src/can/util.rs
+++ b/embassy-stm32/src/can/util.rs
@@ -1,6 +1,6 @@
1//! Utility functions shared between CAN controller types. 1//! Utility functions shared between CAN controller types.
2 2
3use core::num::{NonZeroU16, NonZeroU8}; 3use core::num::{NonZeroU8, NonZeroU16};
4 4
5/// Shared struct to represent bit timings used by calc_can_timings. 5/// Shared struct to represent bit timings used by calc_can_timings.
6#[derive(Clone, Copy, Debug)] 6#[derive(Clone, Copy, Debug)]
diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs
index 13e5263de..836228599 100644
--- a/embassy-stm32/src/crc/v1.rs
+++ b/embassy-stm32/src/crc/v1.rs
@@ -1,6 +1,6 @@
1use crate::pac::CRC as PAC_CRC; 1use crate::pac::CRC as PAC_CRC;
2use crate::peripherals::CRC; 2use crate::peripherals::CRC;
3use crate::{rcc, Peri}; 3use crate::{Peri, rcc};
4 4
5/// CRC driver. 5/// CRC driver.
6pub struct Crc<'d> { 6pub struct Crc<'d> {
diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs
index d834d0971..a566a2e04 100644
--- a/embassy-stm32/src/crc/v2v3.rs
+++ b/embassy-stm32/src/crc/v2v3.rs
@@ -1,7 +1,7 @@
1use crate::pac::crc::vals;
2use crate::pac::CRC as PAC_CRC; 1use crate::pac::CRC as PAC_CRC;
2use crate::pac::crc::vals;
3use crate::peripherals::CRC; 3use crate::peripherals::CRC;
4use crate::{rcc, Peri}; 4use crate::{Peri, rcc};
5 5
6/// CRC driver. 6/// CRC driver.
7pub struct Crc<'d> { 7pub struct Crc<'d> {
diff --git a/embassy-stm32/src/cryp/mod.rs b/embassy-stm32/src/cryp/mod.rs
index 0173b2b5d..4f1115fb7 100644
--- a/embassy-stm32/src/cryp/mod.rs
+++ b/embassy-stm32/src/cryp/mod.rs
@@ -1236,7 +1236,10 @@ impl<'d, T: Instance, M: Mode> Cryp<'d, T, M> {
1236 } 1236 }
1237 if C::REQUIRES_PADDING { 1237 if C::REQUIRES_PADDING {
1238 if last_block_remainder != 0 { 1238 if last_block_remainder != 0 {
1239 panic!("Input must be a multiple of {} bytes in ECB and CBC modes. Consider padding or ciphertext stealing.", C::BLOCK_SIZE); 1239 panic!(
1240 "Input must be a multiple of {} bytes in ECB and CBC modes. Consider padding or ciphertext stealing.",
1241 C::BLOCK_SIZE
1242 );
1240 } 1243 }
1241 } 1244 }
1242 if last_block { 1245 if last_block {
@@ -1703,7 +1706,10 @@ impl<'d, T: Instance> Cryp<'d, T, Async> {
1703 } 1706 }
1704 if C::REQUIRES_PADDING { 1707 if C::REQUIRES_PADDING {
1705 if last_block_remainder != 0 { 1708 if last_block_remainder != 0 {
1706 panic!("Input must be a multiple of {} bytes in ECB and CBC modes. Consider padding or ciphertext stealing.", C::BLOCK_SIZE); 1709 panic!(
1710 "Input must be a multiple of {} bytes in ECB and CBC modes. Consider padding or ciphertext stealing.",
1711 C::BLOCK_SIZE
1712 );
1707 } 1713 }
1708 } 1714 }
1709 if last_block { 1715 if last_block {
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs
index 08e001337..d74d4a4be 100644
--- a/embassy-stm32/src/dac/mod.rs
+++ b/embassy-stm32/src/dac/mod.rs
@@ -8,7 +8,7 @@ use crate::mode::{Async, Blocking, Mode as PeriMode};
8#[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))] 8#[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))]
9use crate::pac::dac; 9use crate::pac::dac;
10use crate::rcc::{self, RccPeripheral}; 10use crate::rcc::{self, RccPeripheral};
11use crate::{peripherals, Peri}; 11use crate::{Peri, peripherals};
12 12
13mod tsel; 13mod tsel;
14use embassy_hal_internal::PeripheralType; 14use embassy_hal_internal::PeripheralType;
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs
index bd03f1e00..dcae9f298 100644
--- a/embassy-stm32/src/dcmi.rs
+++ b/embassy-stm32/src/dcmi.rs
@@ -9,7 +9,7 @@ use embassy_sync::waitqueue::AtomicWaker;
9use crate::dma::Transfer; 9use crate::dma::Transfer;
10use crate::gpio::{AfType, Pull}; 10use crate::gpio::{AfType, Pull};
11use crate::interrupt::typelevel::Interrupt; 11use crate::interrupt::typelevel::Interrupt;
12use crate::{interrupt, rcc, Peri}; 12use crate::{Peri, interrupt, rcc};
13 13
14/// Interrupt handler. 14/// Interrupt handler.
15pub struct InterruptHandler<T: Instance> { 15pub struct InterruptHandler<T: Instance> {
diff --git a/embassy-stm32/src/dma/dma_bdma.rs b/embassy-stm32/src/dma/dma_bdma.rs
index 73ecab070..90dbf4f09 100644
--- a/embassy-stm32/src/dma/dma_bdma.rs
+++ b/embassy-stm32/src/dma/dma_bdma.rs
@@ -1,6 +1,6 @@
1use core::future::{poll_fn, Future}; 1use core::future::{Future, poll_fn};
2use core::pin::Pin; 2use core::pin::Pin;
3use core::sync::atomic::{fence, AtomicUsize, Ordering}; 3use core::sync::atomic::{AtomicUsize, Ordering, fence};
4use core::task::{Context, Poll, Waker}; 4use core::task::{Context, Poll, Waker};
5 5
6use embassy_hal_internal::Peri; 6use embassy_hal_internal::Peri;
diff --git a/embassy-stm32/src/dma/gpdma/mod.rs b/embassy-stm32/src/dma/gpdma/mod.rs
index 4a14c2a8e..3e117c331 100644
--- a/embassy-stm32/src/dma/gpdma/mod.rs
+++ b/embassy-stm32/src/dma/gpdma/mod.rs
@@ -2,7 +2,7 @@
2 2
3use core::future::Future; 3use core::future::Future;
4use core::pin::Pin; 4use core::pin::Pin;
5use core::sync::atomic::{fence, AtomicUsize, Ordering}; 5use core::sync::atomic::{AtomicUsize, Ordering, fence};
6use core::task::{Context, Poll}; 6use core::task::{Context, Poll};
7 7
8use embassy_hal_internal::Peri; 8use embassy_hal_internal::Peri;
diff --git a/embassy-stm32/src/dma/gpdma/ringbuffered.rs b/embassy-stm32/src/dma/gpdma/ringbuffered.rs
index 9ee52193b..94c597e0d 100644
--- a/embassy-stm32/src/dma/gpdma/ringbuffered.rs
+++ b/embassy-stm32/src/dma/gpdma/ringbuffered.rs
@@ -3,12 +3,12 @@
3//! FIXME: Add request_pause functionality? 3//! FIXME: Add request_pause functionality?
4//! FIXME: Stop the DMA, if a user does not queue new transfers (chain of linked-list items ends automatically). 4//! FIXME: Stop the DMA, if a user does not queue new transfers (chain of linked-list items ends automatically).
5use core::future::poll_fn; 5use core::future::poll_fn;
6use core::sync::atomic::{fence, Ordering}; 6use core::sync::atomic::{Ordering, fence};
7use core::task::Waker; 7use core::task::Waker;
8 8
9use embassy_hal_internal::Peri; 9use embassy_hal_internal::Peri;
10 10
11use super::{AnyChannel, TransferOptions, STATE}; 11use super::{AnyChannel, STATE, TransferOptions};
12use crate::dma::gpdma::linked_list::{RunMode, Table}; 12use crate::dma::gpdma::linked_list::{RunMode, Table};
13use crate::dma::ringbuffer::{DmaCtrl, Error, ReadableDmaRingBuffer, WritableDmaRingBuffer}; 13use crate::dma::ringbuffer::{DmaCtrl, Error, ReadableDmaRingBuffer, WritableDmaRingBuffer};
14use crate::dma::word::Word; 14use crate::dma::word::Word;
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs
index 5989bfd7c..297fa3674 100644
--- a/embassy-stm32/src/dma/mod.rs
+++ b/embassy-stm32/src/dma/mod.rs
@@ -24,7 +24,7 @@ pub(crate) use util::*;
24pub(crate) mod ringbuffer; 24pub(crate) mod ringbuffer;
25pub mod word; 25pub mod word;
26 26
27use embassy_hal_internal::{impl_peripheral, PeripheralType}; 27use embassy_hal_internal::{PeripheralType, impl_peripheral};
28 28
29use crate::interrupt; 29use crate::interrupt;
30 30
diff --git a/embassy-stm32/src/dma/ringbuffer/tests/prop_test/mod.rs b/embassy-stm32/src/dma/ringbuffer/tests/prop_test/mod.rs
index 661fb1728..eff5b4058 100644
--- a/embassy-stm32/src/dma/ringbuffer/tests/prop_test/mod.rs
+++ b/embassy-stm32/src/dma/ringbuffer/tests/prop_test/mod.rs
@@ -2,7 +2,7 @@ use std::task::Waker;
2 2
3use proptest::prop_oneof; 3use proptest::prop_oneof;
4use proptest::strategy::{self, BoxedStrategy, Strategy as _}; 4use proptest::strategy::{self, BoxedStrategy, Strategy as _};
5use proptest_state_machine::{prop_state_machine, ReferenceStateMachine, StateMachineTest}; 5use proptest_state_machine::{ReferenceStateMachine, StateMachineTest, prop_state_machine};
6 6
7use super::*; 7use super::*;
8 8
diff --git a/embassy-stm32/src/dsihost.rs b/embassy-stm32/src/dsihost.rs
index deda956af..fd1682d2b 100644
--- a/embassy-stm32/src/dsihost.rs
+++ b/embassy-stm32/src/dsihost.rs
@@ -7,7 +7,7 @@ use embassy_hal_internal::PeripheralType;
7//use crate::gpio::{AnyPin, SealedPin}; 7//use crate::gpio::{AnyPin, SealedPin};
8use crate::gpio::{AfType, AnyPin, OutputType, Speed}; 8use crate::gpio::{AfType, AnyPin, OutputType, Speed};
9use crate::rcc::{self, RccPeripheral}; 9use crate::rcc::{self, RccPeripheral};
10use crate::{peripherals, Peri}; 10use crate::{Peri, peripherals};
11 11
12/// Performs a busy-wait delay for a specified number of microseconds. 12/// Performs a busy-wait delay for a specified number of microseconds.
13pub fn blocking_delay_ms(ms: u32) { 13pub fn blocking_delay_ms(ms: u32) {
diff --git a/embassy-stm32/src/dts/mod.rs b/embassy-stm32/src/dts/mod.rs
index 1f39c8db5..a75ae0560 100644
--- a/embassy-stm32/src/dts/mod.rs
+++ b/embassy-stm32/src/dts/mod.rs
@@ -1,7 +1,7 @@
1//! Digital Temperature Sensor (DTS) 1//! Digital Temperature Sensor (DTS)
2 2
3use core::future::poll_fn; 3use core::future::poll_fn;
4use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{Ordering, compiler_fence};
5use core::task::Poll; 5use core::task::Poll;
6 6
7use embassy_hal_internal::Peri; 7use embassy_hal_internal::Peri;
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs
index 5be1c9739..a77eb8719 100644
--- a/embassy-stm32/src/eth/v1/mod.rs
+++ b/embassy-stm32/src/eth/v1/mod.rs
@@ -4,7 +4,7 @@ mod rx_desc;
4mod tx_desc; 4mod tx_desc;
5 5
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::sync::atomic::{fence, Ordering}; 7use core::sync::atomic::{Ordering, fence};
8 8
9use embassy_hal_internal::Peri; 9use embassy_hal_internal::Peri;
10use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf}; 10use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf};
@@ -190,7 +190,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
190 w.set_apcs(Apcs::STRIP); // automatic padding and crc stripping 190 w.set_apcs(Apcs::STRIP); // automatic padding and crc stripping
191 w.set_fes(Fes::FES100); // fast ethernet speed 191 w.set_fes(Fes::FES100); // fast ethernet speed
192 w.set_dm(Dm::FULL_DUPLEX); // full duplex 192 w.set_dm(Dm::FULL_DUPLEX); // full duplex
193 // TODO: Carrier sense ? ECRSFD 193 // TODO: Carrier sense ? ECRSFD
194 }); 194 });
195 195
196 // Set the mac to pass all multicast packets 196 // Set the mac to pass all multicast packets
@@ -350,7 +350,9 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
350 } 350 }
351 351
352 #[cfg(any(eth_v1b, eth_v1c))] 352 #[cfg(any(eth_v1b, eth_v1c))]
353 config_pins!(rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en); 353 config_pins!(
354 rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en
355 );
354 356
355 let pins = Pins::Mii([ 357 let pins = Pins::Mii([
356 rx_clk.into(), 358 rx_clk.into(),
diff --git a/embassy-stm32/src/eth/v1/rx_desc.rs b/embassy-stm32/src/eth/v1/rx_desc.rs
index 2a46c1895..6ade1f29c 100644
--- a/embassy-stm32/src/eth/v1/rx_desc.rs
+++ b/embassy-stm32/src/eth/v1/rx_desc.rs
@@ -1,4 +1,4 @@
1use core::sync::atomic::{compiler_fence, fence, Ordering}; 1use core::sync::atomic::{Ordering, compiler_fence, fence};
2 2
3use stm32_metapac::eth::vals::{Rpd, Rps}; 3use stm32_metapac::eth::vals::{Rpd, Rps};
4use vcell::VolatileCell; 4use vcell::VolatileCell;
diff --git a/embassy-stm32/src/eth/v1/tx_desc.rs b/embassy-stm32/src/eth/v1/tx_desc.rs
index 1317d20f4..ba99b66cb 100644
--- a/embassy-stm32/src/eth/v1/tx_desc.rs
+++ b/embassy-stm32/src/eth/v1/tx_desc.rs
@@ -1,4 +1,4 @@
1use core::sync::atomic::{compiler_fence, fence, Ordering}; 1use core::sync::atomic::{Ordering, compiler_fence, fence};
2 2
3use vcell::VolatileCell; 3use vcell::VolatileCell;
4 4
diff --git a/embassy-stm32/src/eth/v2/descriptors.rs b/embassy-stm32/src/eth/v2/descriptors.rs
index 645bfdb14..e335ed8f3 100644
--- a/embassy-stm32/src/eth/v2/descriptors.rs
+++ b/embassy-stm32/src/eth/v2/descriptors.rs
@@ -1,4 +1,4 @@
1use core::sync::atomic::{fence, Ordering}; 1use core::sync::atomic::{Ordering, fence};
2 2
3use vcell::VolatileCell; 3use vcell::VolatileCell;
4 4
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs
index cf7a9901b..39a6e8b0f 100644
--- a/embassy-stm32/src/eth/v2/mod.rs
+++ b/embassy-stm32/src/eth/v2/mod.rs
@@ -1,7 +1,7 @@
1mod descriptors; 1mod descriptors;
2 2
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::sync::atomic::{fence, Ordering}; 4use core::sync::atomic::{Ordering, fence};
5 5
6use embassy_hal_internal::Peri; 6use embassy_hal_internal::Peri;
7use stm32_metapac::syscfg::vals::EthSelPhy; 7use stm32_metapac::syscfg::vals::EthSelPhy;
@@ -144,7 +144,9 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
144 .modify(|w| w.set_eth_sel_phy(EthSelPhy::MII_GMII)); 144 .modify(|w| w.set_eth_sel_phy(EthSelPhy::MII_GMII));
145 }); 145 });
146 146
147 config_pins!(rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en); 147 config_pins!(
148 rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en
149 );
148 150
149 let pins = Pins::Mii([ 151 let pins = Pins::Mii([
150 rx_clk.into(), 152 rx_clk.into(),
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index 9fce78f95..12600d4eb 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -5,13 +5,13 @@ use core::marker::PhantomData;
5use core::pin::Pin; 5use core::pin::Pin;
6use core::task::{Context, Poll}; 6use core::task::{Context, Poll};
7 7
8use embassy_hal_internal::{impl_peripheral, PeripheralType}; 8use embassy_hal_internal::{PeripheralType, impl_peripheral};
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10 10
11use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin, Pull}; 11use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin, Pull};
12use crate::pac::exti::regs::Lines;
13use crate::pac::EXTI; 12use crate::pac::EXTI;
14use crate::{interrupt, pac, peripherals, Peri}; 13use crate::pac::exti::regs::Lines;
14use crate::{Peri, interrupt, pac, peripherals};
15 15
16const EXTI_COUNT: usize = 16; 16const EXTI_COUNT: usize = 16;
17static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT]; 17static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT];
diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs
index 006dcddeb..a131217b7 100644
--- a/embassy-stm32/src/flash/asynch.rs
+++ b/embassy-stm32/src/flash/asynch.rs
@@ -1,17 +1,17 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use embassy_hal_internal::drop::OnDrop; 4use embassy_hal_internal::drop::OnDrop;
5use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 5use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
6use embassy_sync::mutex::Mutex; 6use embassy_sync::mutex::Mutex;
7 7
8use super::{ 8use super::{
9 blocking_read, ensure_sector_aligned, family, get_flash_regions, get_sector, Async, Error, Flash, FlashLayout, 9 Async, Error, FLASH_BASE, FLASH_SIZE, Flash, FlashLayout, WRITE_SIZE, blocking_read, ensure_sector_aligned, family,
10 FLASH_BASE, FLASH_SIZE, WRITE_SIZE, 10 get_flash_regions, get_sector,
11}; 11};
12use crate::interrupt::InterruptExt; 12use crate::interrupt::InterruptExt;
13use crate::peripherals::FLASH; 13use crate::peripherals::FLASH;
14use crate::{interrupt, Peri}; 14use crate::{Peri, interrupt};
15 15
16pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(()); 16pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(());
17 17
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs
index 10023e637..b595938a6 100644
--- a/embassy-stm32/src/flash/common.rs
+++ b/embassy-stm32/src/flash/common.rs
@@ -1,14 +1,14 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use embassy_hal_internal::drop::OnDrop; 4use embassy_hal_internal::drop::OnDrop;
5 5
6use super::{ 6use super::{
7 family, get_flash_regions, Async, Blocking, Error, FlashBank, FlashLayout, FlashRegion, FlashSector, FLASH_SIZE, 7 Async, Blocking, Error, FLASH_SIZE, FlashBank, FlashLayout, FlashRegion, FlashSector, MAX_ERASE_SIZE, READ_SIZE,
8 MAX_ERASE_SIZE, READ_SIZE, WRITE_SIZE, 8 WRITE_SIZE, family, get_flash_regions,
9}; 9};
10use crate::Peri;
11use crate::_generated::FLASH_BASE; 10use crate::_generated::FLASH_BASE;
11use crate::Peri;
12use crate::peripherals::FLASH; 12use crate::peripherals::FLASH;
13 13
14/// Internal flash memory driver. 14/// Internal flash memory driver.
diff --git a/embassy-stm32/src/flash/eeprom.rs b/embassy-stm32/src/flash/eeprom.rs
index cc3529eb9..39c497e3f 100644
--- a/embassy-stm32/src/flash/eeprom.rs
+++ b/embassy-stm32/src/flash/eeprom.rs
@@ -1,6 +1,6 @@
1use embassy_hal_internal::drop::OnDrop; 1use embassy_hal_internal::drop::OnDrop;
2 2
3use super::{family, Blocking, Error, Flash, EEPROM_BASE, EEPROM_SIZE}; 3use super::{Blocking, EEPROM_BASE, EEPROM_SIZE, Error, Flash, family};
4 4
5#[cfg(eeprom)] 5#[cfg(eeprom)]
6impl<'d> Flash<'d, Blocking> { 6impl<'d> Flash<'d, Blocking> {
diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs
index 3f9dbe945..5c01fce9c 100644
--- a/embassy-stm32/src/flash/f0.rs
+++ b/embassy-stm32/src/flash/f0.rs
@@ -1,5 +1,5 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use super::{FlashSector, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
diff --git a/embassy-stm32/src/flash/f1f3.rs b/embassy-stm32/src/flash/f1f3.rs
index bf9ad2893..9e469ffbc 100644
--- a/embassy-stm32/src/flash/f1f3.rs
+++ b/embassy-stm32/src/flash/f1f3.rs
@@ -1,5 +1,5 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use super::{FlashSector, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
diff --git a/embassy-stm32/src/flash/f2.rs b/embassy-stm32/src/flash/f2.rs
index 67e380619..b48ab3b76 100644
--- a/embassy-stm32/src/flash/f2.rs
+++ b/embassy-stm32/src/flash/f2.rs
@@ -1,9 +1,9 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, AtomicBool, Ordering}; 2use core::sync::atomic::{AtomicBool, Ordering, fence};
3 3
4use pac::flash::regs::Sr; 4use pac::flash::regs::Sr;
5 5
6use super::{get_flash_regions, FlashBank, FlashSector, WRITE_SIZE}; 6use super::{FlashBank, FlashSector, WRITE_SIZE, get_flash_regions};
7use crate::flash::Error; 7use crate::flash::Error;
8use crate::pac; 8use crate::pac;
9 9
diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs
index 62e0492b5..9c5051492 100644
--- a/embassy-stm32/src/flash/f4.rs
+++ b/embassy-stm32/src/flash/f4.rs
@@ -1,10 +1,10 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, AtomicBool, Ordering}; 2use core::sync::atomic::{AtomicBool, Ordering, fence};
3 3
4use embassy_sync::waitqueue::AtomicWaker; 4use embassy_sync::waitqueue::AtomicWaker;
5use pac::flash::regs::Sr; 5use pac::flash::regs::Sr;
6 6
7use super::{get_flash_regions, FlashBank, FlashSector, WRITE_SIZE}; 7use super::{FlashBank, FlashSector, WRITE_SIZE, get_flash_regions};
8use crate::_generated::FLASH_SIZE; 8use crate::_generated::FLASH_SIZE;
9use crate::flash::Error; 9use crate::flash::Error;
10use crate::pac; 10use crate::pac;
@@ -246,7 +246,9 @@ pub(crate) fn assert_not_corrupted_read(end_address: u32) {
246 feature = "stm32f439zi", 246 feature = "stm32f439zi",
247 ))] 247 ))]
248 if second_bank_read && pac::DBGMCU.idcode().read().rev_id() < REVISION_3 && !pa12_is_output_pull_low() { 248 if second_bank_read && pac::DBGMCU.idcode().read().rev_id() < REVISION_3 && !pa12_is_output_pull_low() {
249 panic!("Read corruption for stm32f42xxI and stm32f43xxI when PA12 is in use for chips below revision 3, see errata 2.2.11"); 249 panic!(
250 "Read corruption for stm32f42xxI and stm32f43xxI when PA12 is in use for chips below revision 3, see errata 2.2.11"
251 );
250 } 252 }
251 253
252 #[cfg(any( 254 #[cfg(any(
@@ -270,14 +272,16 @@ pub(crate) fn assert_not_corrupted_read(end_address: u32) {
270 feature = "stm32f439zg", 272 feature = "stm32f439zg",
271 ))] 273 ))]
272 if second_bank_read && pac::DBGMCU.idcode().read().rev_id() < REVISION_3 && !pa12_is_output_pull_low() { 274 if second_bank_read && pac::DBGMCU.idcode().read().rev_id() < REVISION_3 && !pa12_is_output_pull_low() {
273 panic!("Read corruption for stm32f42xxG and stm32f43xxG in dual bank mode when PA12 is in use for chips below revision 3, see errata 2.2.11"); 275 panic!(
276 "Read corruption for stm32f42xxG and stm32f43xxG in dual bank mode when PA12 is in use for chips below revision 3, see errata 2.2.11"
277 );
274 } 278 }
275} 279}
276 280
277#[allow(unused)] 281#[allow(unused)]
278fn pa12_is_output_pull_low() -> bool { 282fn pa12_is_output_pull_low() -> bool {
279 use pac::gpio::vals;
280 use pac::GPIOA; 283 use pac::GPIOA;
284 use pac::gpio::vals;
281 const PIN: usize = 12; 285 const PIN: usize = 12;
282 GPIOA.moder().read().moder(PIN) == vals::Moder::OUTPUT 286 GPIOA.moder().read().moder(PIN) == vals::Moder::OUTPUT
283 && GPIOA.pupdr().read().pupdr(PIN) == vals::Pupdr::PULL_DOWN 287 && GPIOA.pupdr().read().pupdr(PIN) == vals::Pupdr::PULL_DOWN
@@ -287,7 +291,7 @@ fn pa12_is_output_pull_low() -> bool {
287#[cfg(test)] 291#[cfg(test)]
288mod tests { 292mod tests {
289 use super::*; 293 use super::*;
290 use crate::flash::{get_sector, FlashBank}; 294 use crate::flash::{FlashBank, get_sector};
291 295
292 #[test] 296 #[test]
293 #[cfg(stm32f429)] 297 #[cfg(stm32f429)]
@@ -370,9 +374,13 @@ mod tests {
370#[cfg(all(bank_setup_configurable))] 374#[cfg(all(bank_setup_configurable))]
371pub(crate) fn check_bank_setup() { 375pub(crate) fn check_bank_setup() {
372 if cfg!(feature = "single-bank") && pac::FLASH.optcr().read().db1m() { 376 if cfg!(feature = "single-bank") && pac::FLASH.optcr().read().db1m() {
373 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the db1m value in the user option bytes or configure embassy to use dual-bank config"); 377 panic!(
378 "Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the db1m value in the user option bytes or configure embassy to use dual-bank config"
379 );
374 } 380 }
375 if cfg!(feature = "dual-bank") && !pac::FLASH.optcr().read().db1m() { 381 if cfg!(feature = "dual-bank") && !pac::FLASH.optcr().read().db1m() {
376 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the db1m value in the user option bytes or configure embassy to use single-bank config"); 382 panic!(
383 "Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the db1m value in the user option bytes or configure embassy to use single-bank config"
384 );
377 } 385 }
378} 386}
diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs
index 0547c747a..09389c417 100644
--- a/embassy-stm32/src/flash/f7.rs
+++ b/embassy-stm32/src/flash/f7.rs
@@ -1,5 +1,5 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use super::{FlashSector, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
@@ -99,7 +99,7 @@ unsafe fn blocking_wait_ready() -> Result<(), Error> {
99#[cfg(test)] 99#[cfg(test)]
100mod tests { 100mod tests {
101 use super::*; 101 use super::*;
102 use crate::flash::{get_sector, FlashBank}; 102 use crate::flash::{FlashBank, get_sector};
103 103
104 #[test] 104 #[test]
105 #[cfg(stm32f732)] 105 #[cfg(stm32f732)]
@@ -218,9 +218,13 @@ mod tests {
218#[cfg(all(bank_setup_configurable))] 218#[cfg(all(bank_setup_configurable))]
219pub(crate) fn check_bank_setup() { 219pub(crate) fn check_bank_setup() {
220 if cfg!(feature = "single-bank") && !pac::FLASH.optcr().read().n_dbank() { 220 if cfg!(feature = "single-bank") && !pac::FLASH.optcr().read().n_dbank() {
221 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the ndbank value in the user option bytes or configure embassy to use dual-bank config"); 221 panic!(
222 "Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the ndbank value in the user option bytes or configure embassy to use dual-bank config"
223 );
222 } 224 }
223 if cfg!(feature = "dual-bank") && pac::FLASH.optcr().read().n_dbank() { 225 if cfg!(feature = "dual-bank") && pac::FLASH.optcr().read().n_dbank() {
224 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the ndbank value in the user option bytes or configure embassy to use single-bank config"); 226 panic!(
227 "Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the ndbank value in the user option bytes or configure embassy to use single-bank config"
228 );
225 } 229 }
226} 230}
diff --git a/embassy-stm32/src/flash/g.rs b/embassy-stm32/src/flash/g.rs
index bc1fd360c..d026541a4 100644
--- a/embassy-stm32/src/flash/g.rs
+++ b/embassy-stm32/src/flash/g.rs
@@ -1,5 +1,5 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use cortex_m::interrupt; 4use cortex_m::interrupt;
5 5
@@ -105,19 +105,27 @@ fn wait_busy() {
105#[cfg(all(bank_setup_configurable, any(flash_g4c2, flash_g4c3, flash_g4c4)))] 105#[cfg(all(bank_setup_configurable, any(flash_g4c2, flash_g4c3, flash_g4c4)))]
106pub(crate) fn check_bank_setup() { 106pub(crate) fn check_bank_setup() {
107 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dbank() { 107 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dbank() {
108 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use dual-bank config"); 108 panic!(
109 "Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use dual-bank config"
110 );
109 } 111 }
110 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dbank() { 112 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dbank() {
111 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use single-bank config"); 113 panic!(
114 "Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use single-bank config"
115 );
112 } 116 }
113} 117}
114 118
115#[cfg(all(bank_setup_configurable, flash_g0x1))] 119#[cfg(all(bank_setup_configurable, flash_g0x1))]
116pub(crate) fn check_bank_setup() { 120pub(crate) fn check_bank_setup() {
117 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dual_bank() { 121 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dual_bank() {
118 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dual_bank value in the user option bytes or configure embassy to use dual-bank config"); 122 panic!(
123 "Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dual_bank value in the user option bytes or configure embassy to use dual-bank config"
124 );
119 } 125 }
120 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dual_bank() { 126 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dual_bank() {
121 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dual_bank value in the user option bytes or configure embassy to use single-bank config"); 127 panic!(
128 "Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dual_bank value in the user option bytes or configure embassy to use single-bank config"
129 );
122 } 130 }
123} 131}
diff --git a/embassy-stm32/src/flash/h5.rs b/embassy-stm32/src/flash/h5.rs
index fd9bfcc75..88f247879 100644
--- a/embassy-stm32/src/flash/h5.rs
+++ b/embassy-stm32/src/flash/h5.rs
@@ -1,5 +1,5 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use super::{FlashSector, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
diff --git a/embassy-stm32/src/flash/h50.rs b/embassy-stm32/src/flash/h50.rs
index f8e210556..91d5da4d6 100644
--- a/embassy-stm32/src/flash/h50.rs
+++ b/embassy-stm32/src/flash/h50.rs
@@ -1,7 +1,7 @@
1/// STM32H50 series flash impl. See RM0492 1/// STM32H50 series flash impl. See RM0492
2use core::{ 2use core::{
3 ptr::write_volatile, 3 ptr::write_volatile,
4 sync::atomic::{fence, Ordering}, 4 sync::atomic::{Ordering, fence},
5}; 5};
6 6
7use cortex_m::interrupt; 7use cortex_m::interrupt;
diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs
index f1d84101c..8a43cce3f 100644
--- a/embassy-stm32/src/flash/h7.rs
+++ b/embassy-stm32/src/flash/h7.rs
@@ -1,7 +1,7 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use super::{FlashSector, BANK1_REGION, FLASH_REGIONS, WRITE_SIZE}; 4use super::{BANK1_REGION, FLASH_REGIONS, FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
6use crate::pac; 6use crate::pac;
7 7
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs
index 1b82704ec..cd23cda5c 100644
--- a/embassy-stm32/src/flash/l.rs
+++ b/embassy-stm32/src/flash/l.rs
@@ -1,5 +1,5 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use super::{FlashSector, WRITE_SIZE}; 4use super::{FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
@@ -234,19 +234,27 @@ pub(crate) unsafe fn wait_ready_blocking() -> Result<(), Error> {
234#[cfg(all(bank_setup_configurable, flash_l5))] 234#[cfg(all(bank_setup_configurable, flash_l5))]
235pub(crate) fn check_bank_setup() { 235pub(crate) fn check_bank_setup() {
236 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dbank() { 236 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dbank() {
237 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use dual-bank config"); 237 panic!(
238 "Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use dual-bank config"
239 );
238 } 240 }
239 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dbank() { 241 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dbank() {
240 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use single-bank config"); 242 panic!(
243 "Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use single-bank config"
244 );
241 } 245 }
242} 246}
243 247
244#[cfg(all(bank_setup_configurable, flash_l4))] 248#[cfg(all(bank_setup_configurable, flash_l4))]
245pub(crate) fn check_bank_setup() { 249pub(crate) fn check_bank_setup() {
246 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dualbank() { 250 if cfg!(feature = "single-bank") && pac::FLASH.optr().read().dualbank() {
247 panic!("Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dualbank value in the user option bytes or configure embassy to use dual-bank config"); 251 panic!(
252 "Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dualbank value in the user option bytes or configure embassy to use dual-bank config"
253 );
248 } 254 }
249 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dualbank() { 255 if cfg!(feature = "dual-bank") && !pac::FLASH.optr().read().dualbank() {
250 panic!("Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dualbank value in the user option bytes or configure embassy to use single-bank config"); 256 panic!(
257 "Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dualbank value in the user option bytes or configure embassy to use single-bank config"
258 );
251 } 259 }
252} 260}
diff --git a/embassy-stm32/src/flash/u0.rs b/embassy-stm32/src/flash/u0.rs
index 68d847eca..a64f6c492 100644
--- a/embassy-stm32/src/flash/u0.rs
+++ b/embassy-stm32/src/flash/u0.rs
@@ -1,5 +1,5 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use cortex_m::interrupt; 4use cortex_m::interrupt;
5 5
diff --git a/embassy-stm32/src/flash/u5.rs b/embassy-stm32/src/flash/u5.rs
index 6c3d4b422..5f1f562c0 100644
--- a/embassy-stm32/src/flash/u5.rs
+++ b/embassy-stm32/src/flash/u5.rs
@@ -1,5 +1,5 @@
1use core::ptr::write_volatile; 1use core::ptr::write_volatile;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{Ordering, fence};
3 3
4use super::{FlashBank, FlashSector, WRITE_SIZE}; 4use super::{FlashBank, FlashSector, WRITE_SIZE};
5use crate::flash::Error; 5use crate::flash::Error;
diff --git a/embassy-stm32/src/fmc.rs b/embassy-stm32/src/fmc.rs
index ff18a8bee..8ecfbc522 100644
--- a/embassy-stm32/src/fmc.rs
+++ b/embassy-stm32/src/fmc.rs
@@ -4,7 +4,7 @@ use core::marker::PhantomData;
4use embassy_hal_internal::PeripheralType; 4use embassy_hal_internal::PeripheralType;
5 5
6use crate::gpio::{AfType, OutputType, Pull, Speed}; 6use crate::gpio::{AfType, OutputType, Pull, Speed};
7use crate::{rcc, Peri}; 7use crate::{Peri, rcc};
8 8
9/// FMC driver 9/// FMC driver
10pub struct Fmc<'d, T: Instance> { 10pub struct Fmc<'d, T: Instance> {
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 5a8d23183..b55baffdc 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -4,7 +4,7 @@
4use core::convert::Infallible; 4use core::convert::Infallible;
5 5
6use critical_section::CriticalSection; 6use critical_section::CriticalSection;
7use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; 7use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral};
8 8
9use crate::pac::gpio::{self, vals}; 9use crate::pac::gpio::{self, vals};
10use crate::peripherals; 10use crate::peripherals;
diff --git a/embassy-stm32/src/hash/mod.rs b/embassy-stm32/src/hash/mod.rs
index 90c06c0d8..ba573267c 100644
--- a/embassy-stm32/src/hash/mod.rs
+++ b/embassy-stm32/src/hash/mod.rs
@@ -19,7 +19,7 @@ use crate::interrupt::typelevel::Interrupt;
19use crate::mode::Async; 19use crate::mode::Async;
20use crate::mode::{Blocking, Mode}; 20use crate::mode::{Blocking, Mode};
21use crate::peripherals::HASH; 21use crate::peripherals::HASH;
22use crate::{interrupt, pac, peripherals, rcc, Peri}; 22use crate::{Peri, interrupt, pac, peripherals, rcc};
23 23
24#[cfg(hash_v1)] 24#[cfg(hash_v1)]
25const NUM_CONTEXT_REGS: usize = 51; 25const NUM_CONTEXT_REGS: usize = 51;
@@ -514,11 +514,7 @@ impl<'d, T: Instance> Hash<'d, T, Async> {
514 T::regs().imr().modify(|reg| reg.set_dcie(true)); 514 T::regs().imr().modify(|reg| reg.set_dcie(true));
515 // Check for completion. 515 // Check for completion.
516 let bits = T::regs().sr().read(); 516 let bits = T::regs().sr().read();
517 if bits.dcis() { 517 if bits.dcis() { Poll::Ready(()) } else { Poll::Pending }
518 Poll::Ready(())
519 } else {
520 Poll::Pending
521 }
522 }) 518 })
523 .await; 519 .await;
524 520
diff --git a/embassy-stm32/src/hsem/mod.rs b/embassy-stm32/src/hsem/mod.rs
index 573a1851d..4d3a5d68d 100644
--- a/embassy-stm32/src/hsem/mod.rs
+++ b/embassy-stm32/src/hsem/mod.rs
@@ -2,13 +2,13 @@
2 2
3use embassy_hal_internal::PeripheralType; 3use embassy_hal_internal::PeripheralType;
4 4
5use crate::pac;
6use crate::rcc::{self, RccPeripheral};
7// TODO: This code works for all HSEM implemenations except for the STM32WBA52/4/5xx MCUs. 5// TODO: This code works for all HSEM implemenations except for the STM32WBA52/4/5xx MCUs.
8// Those MCUs have a different HSEM implementation (Secure semaphore lock support, 6// Those MCUs have a different HSEM implementation (Secure semaphore lock support,
9// Privileged / unprivileged semaphore lock support, Semaphore lock protection via semaphore attribute), 7// Privileged / unprivileged semaphore lock support, Semaphore lock protection via semaphore attribute),
10// which is not yet supported by this code. 8// which is not yet supported by this code.
11use crate::Peri; 9use crate::Peri;
10use crate::pac;
11use crate::rcc::{self, RccPeripheral};
12 12
13/// HSEM error. 13/// HSEM error.
14#[derive(Debug)] 14#[derive(Debug)]
diff --git a/embassy-stm32/src/hspi/mod.rs b/embassy-stm32/src/hspi/mod.rs
index 95d9e5099..69baa708e 100644
--- a/embassy-stm32/src/hspi/mod.rs
+++ b/embassy-stm32/src/hspi/mod.rs
@@ -16,7 +16,7 @@ use embassy_embedded_hal::{GetConfig, SetConfig};
16use embassy_hal_internal::{Peri, PeripheralType}; 16use embassy_hal_internal::{Peri, PeripheralType};
17pub use enums::*; 17pub use enums::*;
18 18
19use crate::dma::{word, ChannelAndRequest}; 19use crate::dma::{ChannelAndRequest, word};
20use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; 20use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
21use crate::mode::{Async, Blocking, Mode as PeriMode}; 21use crate::mode::{Async, Blocking, Mode as PeriMode};
22use crate::pac::hspi::Hspi as Regs; 22use crate::pac::hspi::Hspi as Regs;
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs
index 249bac41c..f4bf55d34 100644
--- a/embassy-stm32/src/i2c/mod.rs
+++ b/embassy-stm32/src/i2c/mod.rs
@@ -154,8 +154,8 @@ impl<'d> I2c<'d, Async, Master> {
154 scl: Peri<'d, if_afio!(impl SclPin<T, A>)>, 154 scl: Peri<'d, if_afio!(impl SclPin<T, A>)>,
155 sda: Peri<'d, if_afio!(impl SdaPin<T, A>)>, 155 sda: Peri<'d, if_afio!(impl SdaPin<T, A>)>,
156 _irq: impl interrupt::typelevel::Binding<T::EventInterrupt, EventInterruptHandler<T>> 156 _irq: impl interrupt::typelevel::Binding<T::EventInterrupt, EventInterruptHandler<T>>
157 + interrupt::typelevel::Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> 157 + interrupt::typelevel::Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>>
158 + 'd, 158 + 'd,
159 tx_dma: Peri<'d, impl TxDma<T>>, 159 tx_dma: Peri<'d, impl TxDma<T>>,
160 rx_dma: Peri<'d, impl RxDma<T>>, 160 rx_dma: Peri<'d, impl RxDma<T>>,
161 config: Config, 161 config: Config,
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index 081eb1191..e6b6c7c42 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -8,7 +8,7 @@ use core::future::poll_fn;
8use core::task::Poll; 8use core::task::Poll;
9 9
10use embassy_embedded_hal::SetConfig; 10use embassy_embedded_hal::SetConfig;
11use embassy_futures::select::{select, Either}; 11use embassy_futures::select::{Either, select};
12use embassy_hal_internal::drop::OnDrop; 12use embassy_hal_internal::drop::OnDrop;
13use embedded_hal_1::i2c::Operation; 13use embedded_hal_1::i2c::Operation;
14use mode::Master; 14use mode::Master;
@@ -762,11 +762,7 @@ impl Timings {
762 mode = Mode::Standard; 762 mode = Mode::Standard;
763 ccr = { 763 ccr = {
764 let ccr = clock / (frequency * 2); 764 let ccr = clock / (frequency * 2);
765 if ccr < 4 { 765 if ccr < 4 { 4 } else { ccr }
766 4
767 } else {
768 ccr
769 }
770 }; 766 };
771 } else { 767 } else {
772 const DUTYCYCLE: u8 = 0; 768 const DUTYCYCLE: u8 = 0;
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 0bfc795ac..01b6b8800 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -2,7 +2,7 @@ use core::cmp;
2use core::future::poll_fn; 2use core::future::poll_fn;
3use core::task::Poll; 3use core::task::Poll;
4 4
5use config::{Address, OwnAddresses, OA2}; 5use config::{Address, OA2, OwnAddresses};
6use embassy_embedded_hal::SetConfig; 6use embassy_embedded_hal::SetConfig;
7use embassy_hal_internal::drop::OnDrop; 7use embassy_hal_internal::drop::OnDrop;
8use embedded_hal_1::i2c::Operation; 8use embedded_hal_1::i2c::Operation;
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs
index b6d3daf54..db22cfa11 100644
--- a/embassy-stm32/src/i2s.rs
+++ b/embassy-stm32/src/i2s.rs
@@ -3,12 +3,12 @@
3use embassy_futures::join::join; 3use embassy_futures::join::join;
4use stm32_metapac::spi::vals; 4use stm32_metapac::spi::vals;
5 5
6use crate::dma::{ringbuffer, ChannelAndRequest, ReadableRingBuffer, TransferOptions, WritableRingBuffer}; 6use crate::Peri;
7use crate::dma::{ChannelAndRequest, ReadableRingBuffer, TransferOptions, WritableRingBuffer, ringbuffer};
7use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed}; 8use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed};
8use crate::mode::Async; 9use crate::mode::Async;
9use crate::spi::{Config as SpiConfig, RegsExt as _, *}; 10use crate::spi::{Config as SpiConfig, RegsExt as _, *};
10use crate::time::Hertz; 11use crate::time::Hertz;
11use crate::Peri;
12 12
13/// I2S mode 13/// I2S mode
14#[derive(Copy, Clone)] 14#[derive(Copy, Clone)]
diff --git a/embassy-stm32/src/ipcc.rs b/embassy-stm32/src/ipcc.rs
index 670d8332c..e1d8b1c2a 100644
--- a/embassy-stm32/src/ipcc.rs
+++ b/embassy-stm32/src/ipcc.rs
@@ -1,7 +1,7 @@
1//! Inter-Process Communication Controller (IPCC) 1//! Inter-Process Communication Controller (IPCC)
2 2
3use core::future::poll_fn; 3use core::future::poll_fn;
4use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{Ordering, compiler_fence};
5use core::task::Poll; 5use core::task::Poll;
6 6
7use embassy_sync::waitqueue::AtomicWaker; 7use embassy_sync::waitqueue::AtomicWaker;
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 7e0f7884e..dbf0fe620 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -1,5 +1,6 @@
1#![cfg_attr(not(test), no_std)] 1#![cfg_attr(not(test), no_std)]
2#![allow(async_fn_in_trait)] 2#![allow(async_fn_in_trait)]
3#![allow(unsafe_op_in_unsafe_fn)]
3#![cfg_attr( 4#![cfg_attr(
4 docsrs, 5 docsrs,
5 doc = "<div style='padding:30px;background:#810;color:#fff;text-align:center;'><p>You might want to <a href='https://docs.embassy.dev/embassy-stm32'>browse the `embassy-stm32` documentation on the Embassy website</a> instead.</p><p>The documentation here on `docs.rs` is built for a single chip only (stm32h7, stm32h7rs55 in particular), while on the Embassy website you can pick your exact chip from the top menu. Available peripherals and their APIs change depending on the chip.</p></div>\n\n" 6 doc = "<div style='padding:30px;background:#810;color:#fff;text-align:center;'><p>You might want to <a href='https://docs.embassy.dev/embassy-stm32'>browse the `embassy-stm32` documentation on the Embassy website</a> instead.</p><p>The documentation here on `docs.rs` is built for a single chip only (stm32h7, stm32h7rs55 in particular), while on the Embassy website you can pick your exact chip from the top menu. Available peripherals and their APIs change depending on the chip.</p></div>\n\n"
@@ -194,7 +195,7 @@ macro_rules! bind_interrupts {
194 195
195 $( 196 $(
196 #[allow(non_snake_case)] 197 #[allow(non_snake_case)]
197 #[no_mangle] 198 #[unsafe(no_mangle)]
198 $(#[cfg($cond_irq)])? 199 $(#[cfg($cond_irq)])?
199 $(#[doc = $doc])* 200 $(#[doc = $doc])*
200 unsafe extern "C" fn $irq() { 201 unsafe extern "C" fn $irq() {
@@ -222,7 +223,7 @@ macro_rules! bind_interrupts {
222} 223}
223 224
224// Reexports 225// Reexports
225pub use _generated::{peripherals, Peripherals}; 226pub use _generated::{Peripherals, peripherals};
226pub use embassy_hal_internal::{Peri, PeripheralType}; 227pub use embassy_hal_internal::{Peri, PeripheralType};
227#[cfg(feature = "unstable-pac")] 228#[cfg(feature = "unstable-pac")]
228pub use stm32_metapac as pac; 229pub use stm32_metapac as pac;
diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs
index 342f73bc8..1b66ca680 100644
--- a/embassy-stm32/src/low_power.rs
+++ b/embassy-stm32/src/low_power.rs
@@ -56,13 +56,13 @@
56 56
57use core::arch::asm; 57use core::arch::asm;
58use core::marker::PhantomData; 58use core::marker::PhantomData;
59use core::sync::atomic::{compiler_fence, Ordering}; 59use core::sync::atomic::{Ordering, compiler_fence};
60 60
61use cortex_m::peripheral::SCB; 61use cortex_m::peripheral::SCB;
62use embassy_executor::*; 62use embassy_executor::*;
63 63
64use crate::interrupt; 64use crate::interrupt;
65use crate::time_driver::{get_driver, RtcDriver}; 65use crate::time_driver::{RtcDriver, get_driver};
66 66
67const THREAD_PENDER: usize = usize::MAX; 67const THREAD_PENDER: usize = usize::MAX;
68 68
diff --git a/embassy-stm32/src/lptim/pwm.rs b/embassy-stm32/src/lptim/pwm.rs
index 96af9f4d9..a69db3caf 100644
--- a/embassy-stm32/src/lptim/pwm.rs
+++ b/embassy-stm32/src/lptim/pwm.rs
@@ -4,12 +4,12 @@ use core::marker::PhantomData;
4 4
5use embassy_hal_internal::Peri; 5use embassy_hal_internal::Peri;
6 6
7use super::timer::Timer;
8#[cfg(not(any(lptim_v2a, lptim_v2b)))] 7#[cfg(not(any(lptim_v2a, lptim_v2b)))]
9use super::OutputPin; 8use super::OutputPin;
10#[cfg(any(lptim_v2a, lptim_v2b))] 9use super::timer::Timer;
11use super::{channel::Channel, timer::ChannelDirection, Channel1Pin, Channel2Pin};
12use super::{BasicInstance, Instance}; 10use super::{BasicInstance, Instance};
11#[cfg(any(lptim_v2a, lptim_v2b))]
12use super::{Channel1Pin, Channel2Pin, channel::Channel, timer::ChannelDirection};
13#[cfg(gpio_v2)] 13#[cfg(gpio_v2)]
14use crate::gpio::Pull; 14use crate::gpio::Pull;
15use crate::gpio::{AfType, AnyPin, OutputType, Speed}; 15use crate::gpio::{AfType, AnyPin, OutputType, Speed};
diff --git a/embassy-stm32/src/ltdc.rs b/embassy-stm32/src/ltdc.rs
index 0f6ef569c..de2db9872 100644
--- a/embassy-stm32/src/ltdc.rs
+++ b/embassy-stm32/src/ltdc.rs
@@ -14,7 +14,7 @@ use stm32_metapac::ltdc::vals::{Bf1, Bf2, Cfuif, Clif, Crrif, Cterrif, Pf, Vbr};
14use crate::gpio::{AfType, OutputType, Speed}; 14use crate::gpio::{AfType, OutputType, Speed};
15use crate::interrupt::typelevel::Interrupt; 15use crate::interrupt::typelevel::Interrupt;
16use crate::interrupt::{self}; 16use crate::interrupt::{self};
17use crate::{peripherals, rcc, Peri}; 17use crate::{Peri, peripherals, rcc};
18 18
19static LTDC_WAKER: AtomicWaker = AtomicWaker::new(); 19static LTDC_WAKER: AtomicWaker = AtomicWaker::new();
20 20
diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs
index e36719ef3..ac8d5de21 100644
--- a/embassy-stm32/src/opamp.rs
+++ b/embassy-stm32/src/opamp.rs
@@ -3,10 +3,10 @@
3 3
4use embassy_hal_internal::PeripheralType; 4use embassy_hal_internal::PeripheralType;
5 5
6use crate::Peri;
6use crate::pac::opamp::vals::*; 7use crate::pac::opamp::vals::*;
7#[cfg(not(any(stm32g4, stm32f3)))] 8#[cfg(not(any(stm32g4, stm32f3)))]
8use crate::rcc::RccInfo; 9use crate::rcc::RccInfo;
9use crate::Peri;
10 10
11/// Performs a busy-wait delay for a specified number of microseconds. 11/// Performs a busy-wait delay for a specified number of microseconds.
12#[cfg(opamp_v5)] 12#[cfg(opamp_v5)]
diff --git a/embassy-stm32/src/ospi/mod.rs b/embassy-stm32/src/ospi/mod.rs
index d93cecb69..592a8594a 100644
--- a/embassy-stm32/src/ospi/mod.rs
+++ b/embassy-stm32/src/ospi/mod.rs
@@ -12,14 +12,14 @@ use embassy_hal_internal::PeripheralType;
12pub use enums::*; 12pub use enums::*;
13use stm32_metapac::octospi::vals::{PhaseMode, SizeInBits}; 13use stm32_metapac::octospi::vals::{PhaseMode, SizeInBits};
14 14
15use crate::dma::{word, ChannelAndRequest}; 15use crate::dma::{ChannelAndRequest, word};
16use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; 16use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
17use crate::mode::{Async, Blocking, Mode as PeriMode}; 17use crate::mode::{Async, Blocking, Mode as PeriMode};
18use crate::pac::octospi::{vals, Octospi as Regs}; 18use crate::pac::octospi::{Octospi as Regs, vals};
19#[cfg(octospim_v1)] 19#[cfg(octospim_v1)]
20use crate::pac::octospim::Octospim; 20use crate::pac::octospim::Octospim;
21use crate::rcc::{self, RccPeripheral}; 21use crate::rcc::{self, RccPeripheral};
22use crate::{peripherals, Peri}; 22use crate::{Peri, peripherals};
23 23
24/// OPSI driver config. 24/// OPSI driver config.
25#[derive(Clone, Copy)] 25#[derive(Clone, Copy)]
diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs
index b03cd9009..bb4f4f1d0 100644
--- a/embassy-stm32/src/qspi/mod.rs
+++ b/embassy-stm32/src/qspi/mod.rs
@@ -14,7 +14,7 @@ use crate::gpio::{AfType, AnyPin, OutputType, Pull, Speed};
14use crate::mode::{Async, Blocking, Mode as PeriMode}; 14use crate::mode::{Async, Blocking, Mode as PeriMode};
15use crate::pac::quadspi::Quadspi as Regs; 15use crate::pac::quadspi::Quadspi as Regs;
16use crate::rcc::{self, RccPeripheral}; 16use crate::rcc::{self, RccPeripheral};
17use crate::{peripherals, Peri}; 17use crate::{Peri, peripherals};
18 18
19/// QSPI transfer configuration. 19/// QSPI transfer configuration.
20#[derive(Clone, Copy)] 20#[derive(Clone, Copy)]
diff --git a/embassy-stm32/src/rcc/bd.rs b/embassy-stm32/src/rcc/bd.rs
index 63fc195dd..3b2a10581 100644
--- a/embassy-stm32/src/rcc/bd.rs
+++ b/embassy-stm32/src/rcc/bd.rs
@@ -1,6 +1,6 @@
1use core::sync::atomic::{compiler_fence, Ordering}; 1use core::sync::atomic::{Ordering, compiler_fence};
2 2
3use crate::pac::common::{Reg, RW}; 3use crate::pac::common::{RW, Reg};
4pub use crate::pac::rcc::vals::Rtcsel as RtcClockSource; 4pub use crate::pac::rcc::vals::Rtcsel as RtcClockSource;
5use crate::time::Hertz; 5use crate::time::Hertz;
6 6
diff --git a/embassy-stm32/src/rcc/f247.rs b/embassy-stm32/src/rcc/f247.rs
index 8f2e8db5f..d941054cd 100644
--- a/embassy-stm32/src/rcc/f247.rs
+++ b/embassy-stm32/src/rcc/f247.rs
@@ -1,13 +1,13 @@
1use stm32_metapac::flash::vals::Latency; 1use stm32_metapac::flash::vals::Latency;
2 2
3#[cfg(any(stm32f4, stm32f7))]
4use crate::pac::PWR;
3#[cfg(any(stm32f413, stm32f423, stm32f412))] 5#[cfg(any(stm32f413, stm32f423, stm32f412))]
4pub use crate::pac::rcc::vals::Plli2ssrc as Plli2sSource; 6pub use crate::pac::rcc::vals::Plli2ssrc as Plli2sSource;
5pub use crate::pac::rcc::vals::{ 7pub use crate::pac::rcc::vals::{
6 Hpre as AHBPrescaler, Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv, 8 Hpre as AHBPrescaler, Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv,
7 Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk, 9 Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk,
8}; 10};
9#[cfg(any(stm32f4, stm32f7))]
10use crate::pac::PWR;
11use crate::pac::{FLASH, RCC}; 11use crate::pac::{FLASH, RCC};
12use crate::time::Hertz; 12use crate::time::Hertz;
13 13
diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs
index 331bab7a0..485edd390 100644
--- a/embassy-stm32/src/rcc/h.rs
+++ b/embassy-stm32/src/rcc/h.rs
@@ -597,7 +597,10 @@ pub(crate) unsafe fn init(config: Config) {
597 Hertz(24_000_000) => Usbrefcksel::MHZ24, 597 Hertz(24_000_000) => Usbrefcksel::MHZ24,
598 Hertz(26_000_000) => Usbrefcksel::MHZ26, 598 Hertz(26_000_000) => Usbrefcksel::MHZ26,
599 Hertz(32_000_000) => Usbrefcksel::MHZ32, 599 Hertz(32_000_000) => Usbrefcksel::MHZ32,
600 _ => panic!("cannot select USBPHYC reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz", clk_val), 600 _ => panic!(
601 "cannot select USBPHYC reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz",
602 clk_val
603 ),
601 }, 604 },
602 None => Usbrefcksel::MHZ24, 605 None => Usbrefcksel::MHZ24,
603 }; 606 };
diff --git a/embassy-stm32/src/rcc/l.rs b/embassy-stm32/src/rcc/l.rs
index 81b89046e..2e1cbd702 100644
--- a/embassy-stm32/src/rcc/l.rs
+++ b/embassy-stm32/src/rcc/l.rs
@@ -499,9 +499,9 @@ pub use pll::*;
499 499
500#[cfg(any(stm32l0, stm32l1))] 500#[cfg(any(stm32l0, stm32l1))]
501mod pll { 501mod pll {
502 use super::{pll_enable, PllInstance}; 502 use super::{PllInstance, pll_enable};
503 pub use crate::pac::rcc::vals::{Plldiv as PllDiv, Pllmul as PllMul, Pllsrc as PllSource};
504 use crate::pac::RCC; 503 use crate::pac::RCC;
504 pub use crate::pac::rcc::vals::{Plldiv as PllDiv, Pllmul as PllMul, Pllsrc as PllSource};
505 use crate::time::Hertz; 505 use crate::time::Hertz;
506 506
507 #[derive(Clone, Copy)] 507 #[derive(Clone, Copy)]
@@ -563,11 +563,11 @@ mod pll {
563 563
564#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl, stm32u0))] 564#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl, stm32u0))]
565mod pll { 565mod pll {
566 use super::{pll_enable, PllInstance}; 566 use super::{PllInstance, pll_enable};
567 use crate::pac::RCC;
567 pub use crate::pac::rcc::vals::{ 568 pub use crate::pac::rcc::vals::{
568 Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv, Pllsrc as PllSource, 569 Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv, Pllsrc as PllSource,
569 }; 570 };
570 use crate::pac::RCC;
571 use crate::time::Hertz; 571 use crate::time::Hertz;
572 572
573 #[derive(Clone, Copy)] 573 #[derive(Clone, Copy)]
diff --git a/embassy-stm32/src/rcc/mco.rs b/embassy-stm32/src/rcc/mco.rs
index 59ccc8cb5..3d961df03 100644
--- a/embassy-stm32/src/rcc/mco.rs
+++ b/embassy-stm32/src/rcc/mco.rs
@@ -3,6 +3,7 @@ use core::marker::PhantomData;
3use embassy_hal_internal::PeripheralType; 3use embassy_hal_internal::PeripheralType;
4 4
5use crate::gpio::{AfType, OutputType, Speed}; 5use crate::gpio::{AfType, OutputType, Speed};
6use crate::pac::RCC;
6#[cfg(not(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37)))] 7#[cfg(not(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37)))]
7pub use crate::pac::rcc::vals::Mcopre as McoPrescaler; 8pub use crate::pac::rcc::vals::Mcopre as McoPrescaler;
8#[cfg(not(any( 9#[cfg(not(any(
@@ -31,8 +32,7 @@ pub use crate::pac::rcc::vals::Mcosel as McoSource;
31 rcc_h7rs 32 rcc_h7rs
32))] 33))]
33pub use crate::pac::rcc::vals::{Mco1sel as Mco1Source, Mco2sel as Mco2Source}; 34pub use crate::pac::rcc::vals::{Mco1sel as Mco1Source, Mco2sel as Mco2Source};
34use crate::pac::RCC; 35use crate::{Peri, peripherals};
35use crate::{peripherals, Peri};
36 36
37#[cfg(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37))] 37#[cfg(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37))]
38#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 38#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
@@ -91,12 +91,29 @@ pub struct Mco<'d, T: McoInstance> {
91 91
92impl<'d, T: McoInstance> Mco<'d, T> { 92impl<'d, T: McoInstance> Mco<'d, T> {
93 /// Create a new MCO instance. 93 /// Create a new MCO instance.
94 pub fn new(_peri: Peri<'d, T>, pin: Peri<'d, impl McoPin<T>>, source: T::Source, prescaler: McoPrescaler) -> Self { 94 pub fn new(_peri: Peri<'d, T>, pin: Peri<'d, impl McoPin<T>>, source: T::Source, config: McoConfig) -> Self {
95 critical_section::with(|_| unsafe { 95 critical_section::with(|_| unsafe {
96 T::_apply_clock_settings(source, prescaler); 96 T::_apply_clock_settings(source, config.prescaler);
97 set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); 97 set_as_af!(pin, AfType::output(OutputType::PushPull, config.speed));
98 }); 98 });
99 99
100 Self { phantom: PhantomData } 100 Self { phantom: PhantomData }
101 } 101 }
102} 102}
103
104#[non_exhaustive]
105pub struct McoConfig {
106 /// Master Clock Out prescaler
107 pub prescaler: McoPrescaler,
108 /// IO Drive Strength
109 pub speed: Speed,
110}
111
112impl Default for McoConfig {
113 fn default() -> Self {
114 Self {
115 prescaler: McoPrescaler::DIV1,
116 speed: Speed::VeryHigh,
117 }
118 }
119}
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index c41f81816..addfca3c3 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -33,7 +33,7 @@ mod _version;
33pub use _version::*; 33pub use _version::*;
34use stm32_metapac::RCC; 34use stm32_metapac::RCC;
35 35
36pub use crate::_generated::{mux, Clocks}; 36pub use crate::_generated::{Clocks, mux};
37use crate::time::Hertz; 37use crate::time::Hertz;
38 38
39#[cfg(feature = "low-power")] 39#[cfg(feature = "low-power")]
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs
index 06895a99a..7b0dcb63f 100644
--- a/embassy-stm32/src/rcc/u5.rs
+++ b/embassy-stm32/src/rcc/u5.rs
@@ -6,9 +6,9 @@ pub use crate::pac::rcc::vals::{
6 Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk, 6 Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk,
7}; 7};
8use crate::pac::rcc::vals::{Hseext, Msipllfast, Msipllsel, Msirgsel, Pllmboost, Pllrge}; 8use crate::pac::rcc::vals::{Hseext, Msipllfast, Msipllsel, Msirgsel, Pllmboost, Pllrge};
9#[cfg(all(peri_usb_otg_hs))]
10pub use crate::pac::{syscfg::vals::Usbrefcksel, SYSCFG};
11use crate::pac::{FLASH, PWR, RCC}; 9use crate::pac::{FLASH, PWR, RCC};
10#[cfg(all(peri_usb_otg_hs))]
11pub use crate::pac::{SYSCFG, syscfg::vals::Usbrefcksel};
12use crate::rcc::LSI_FREQ; 12use crate::rcc::LSI_FREQ;
13use crate::time::Hertz; 13use crate::time::Hertz;
14 14
@@ -442,7 +442,10 @@ pub(crate) unsafe fn init(config: Config) {
442 Hertz(24_000_000) => Usbrefcksel::MHZ24, 442 Hertz(24_000_000) => Usbrefcksel::MHZ24,
443 Hertz(26_000_000) => Usbrefcksel::MHZ26, 443 Hertz(26_000_000) => Usbrefcksel::MHZ26,
444 Hertz(32_000_000) => Usbrefcksel::MHZ32, 444 Hertz(32_000_000) => Usbrefcksel::MHZ32,
445 _ => panic!("cannot select OTG_HS reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz", clk_val), 445 _ => panic!(
446 "cannot select OTG_HS reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz",
447 clk_val
448 ),
446 }, 449 },
447 None => Usbrefcksel::MHZ24, 450 None => Usbrefcksel::MHZ24,
448 }; 451 };
diff --git a/embassy-stm32/src/rcc/wba.rs b/embassy-stm32/src/rcc/wba.rs
index 481437939..2528996d5 100644
--- a/embassy-stm32/src/rcc/wba.rs
+++ b/embassy-stm32/src/rcc/wba.rs
@@ -7,9 +7,9 @@ pub use crate::pac::rcc::vals::{
7 Hdiv5, Hpre as AHBPrescaler, Hpre5 as AHB5Prescaler, Hsepre as HsePrescaler, Plldiv as PllDiv, Pllm as PllPreDiv, 7 Hdiv5, Hpre as AHBPrescaler, Hpre5 as AHB5Prescaler, Hsepre as HsePrescaler, Plldiv as PllDiv, Pllm as PllPreDiv,
8 Plln as PllMul, Pllsrc as PllSource, Ppre as APBPrescaler, Sai1sel, Sw as Sysclk, 8 Plln as PllMul, Pllsrc as PllSource, Ppre as APBPrescaler, Sai1sel, Sw as Sysclk,
9}; 9};
10#[cfg(all(peri_usb_otg_hs))]
11pub use crate::pac::{syscfg::vals::Usbrefcksel, SYSCFG};
12use crate::pac::{FLASH, RCC}; 10use crate::pac::{FLASH, RCC};
11#[cfg(all(peri_usb_otg_hs))]
12pub use crate::pac::{SYSCFG, syscfg::vals::Usbrefcksel};
13use crate::rcc::LSI_FREQ; 13use crate::rcc::LSI_FREQ;
14use crate::time::Hertz; 14use crate::time::Hertz;
15 15
@@ -245,7 +245,10 @@ pub(crate) unsafe fn init(config: Config) {
245 Hertz(24_000_000) => Usbrefcksel::MHZ24, 245 Hertz(24_000_000) => Usbrefcksel::MHZ24,
246 Hertz(26_000_000) => Usbrefcksel::MHZ26, 246 Hertz(26_000_000) => Usbrefcksel::MHZ26,
247 Hertz(32_000_000) => Usbrefcksel::MHZ32, 247 Hertz(32_000_000) => Usbrefcksel::MHZ32,
248 _ => panic!("cannot select OTG_HS reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz", clk_val), 248 _ => panic!(
249 "cannot select OTG_HS reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz",
250 clk_val
251 ),
249 }, 252 },
250 None => Usbrefcksel::MHZ24, 253 None => Usbrefcksel::MHZ24,
251 }; 254 };
diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs
index 63654639e..dada9bda1 100644
--- a/embassy-stm32/src/rng.rs
+++ b/embassy-stm32/src/rng.rs
@@ -9,7 +9,7 @@ use embassy_hal_internal::PeripheralType;
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10 10
11use crate::interrupt::typelevel::Interrupt; 11use crate::interrupt::typelevel::Interrupt;
12use crate::{interrupt, pac, peripherals, rcc, Peri}; 12use crate::{Peri, interrupt, pac, peripherals, rcc};
13 13
14static RNG_WAKER: AtomicWaker = AtomicWaker::new(); 14static RNG_WAKER: AtomicWaker = AtomicWaker::new();
15 15
diff --git a/embassy-stm32/src/rtc/low_power.rs b/embassy-stm32/src/rtc/low_power.rs
index a81ac6746..999f24714 100644
--- a/embassy-stm32/src/rtc/low_power.rs
+++ b/embassy-stm32/src/rtc/low_power.rs
@@ -1,7 +1,7 @@
1#[cfg(feature = "time")] 1#[cfg(feature = "time")]
2use embassy_time::{Duration, TICK_HZ}; 2use embassy_time::{Duration, TICK_HZ};
3 3
4use super::{bcd2_to_byte, DateTimeError, Rtc, RtcError}; 4use super::{DateTimeError, Rtc, RtcError, bcd2_to_byte};
5use crate::interrupt::typelevel::Interrupt; 5use crate::interrupt::typelevel::Interrupt;
6use crate::peripherals::RTC; 6use crate::peripherals::RTC;
7use crate::rtc::SealedInstance; 7use crate::rtc::SealedInstance;
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs
index 92dec0960..bc6df528b 100644
--- a/embassy-stm32/src/rtc/mod.rs
+++ b/embassy-stm32/src/rtc/mod.rs
@@ -8,12 +8,12 @@ mod low_power;
8use core::cell::Cell; 8use core::cell::Cell;
9 9
10#[cfg(feature = "low-power")] 10#[cfg(feature = "low-power")]
11use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
12#[cfg(feature = "low-power")]
13use embassy_sync::blocking_mutex::Mutex; 11use embassy_sync::blocking_mutex::Mutex;
12#[cfg(feature = "low-power")]
13use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
14 14
15use self::datetime::{day_of_week_from_u8, day_of_week_to_u8};
16pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError}; 15pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError};
16use self::datetime::{day_of_week_from_u8, day_of_week_to_u8};
17use crate::pac::rtc::regs::{Dr, Tr}; 17use crate::pac::rtc::regs::{Dr, Tr};
18use crate::time::Hertz; 18use crate::time::Hertz;
19 19
@@ -25,8 +25,8 @@ mod _version;
25#[allow(unused_imports)] 25#[allow(unused_imports)]
26pub use _version::*; 26pub use _version::*;
27 27
28use crate::peripherals::RTC;
29use crate::Peri; 28use crate::Peri;
29use crate::peripherals::RTC;
30 30
31/// Errors that can occur on methods on [RtcClock] 31/// Errors that can occur on methods on [RtcClock]
32#[non_exhaustive] 32#[non_exhaustive]
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs
index d0b52049e..01da5d70a 100644
--- a/embassy-stm32/src/rtc/v3.rs
+++ b/embassy-stm32/src/rtc/v3.rs
@@ -1,4 +1,4 @@
1use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Key, Osel, Pol, TampalrmType}; 1use stm32_metapac::rtc::vals::{Calp, Calw8, Calw16, Fmt, Key, Osel, Pol, TampalrmType};
2 2
3use super::RtcCalibrationCyclePeriod; 3use super::RtcCalibrationCyclePeriod;
4use crate::pac::rtc::Rtc; 4use crate::pac::rtc::Rtc;
diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs
index fb8b23b79..726d1729a 100644
--- a/embassy-stm32/src/sai/mod.rs
+++ b/embassy-stm32/src/sai/mod.rs
@@ -6,12 +6,12 @@ use core::marker::PhantomData;
6use embassy_hal_internal::PeripheralType; 6use embassy_hal_internal::PeripheralType;
7 7
8pub use crate::dma::word; 8pub use crate::dma::word;
9use crate::dma::{ringbuffer, Channel, ReadableRingBuffer, Request, TransferOptions, WritableRingBuffer}; 9use crate::dma::{Channel, ReadableRingBuffer, Request, TransferOptions, WritableRingBuffer, ringbuffer};
10use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; 10use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
11pub use crate::pac::sai::vals::Mckdiv as MasterClockDivider; 11pub use crate::pac::sai::vals::Mckdiv as MasterClockDivider;
12use crate::pac::sai::{vals, Sai as Regs}; 12use crate::pac::sai::{Sai as Regs, vals};
13use crate::rcc::{self, RccPeripheral}; 13use crate::rcc::{self, RccPeripheral};
14use crate::{peripherals, Peri}; 14use crate::{Peri, peripherals};
15 15
16/// SAI error 16/// SAI error
17#[derive(Debug, PartialEq, Eq, Clone, Copy)] 17#[derive(Debug, PartialEq, Eq, Clone, Copy)]
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs
index ccbd16cbf..408d1b764 100644
--- a/embassy-stm32/src/sdmmc/mod.rs
+++ b/embassy-stm32/src/sdmmc/mod.rs
@@ -11,9 +11,9 @@ use embassy_hal_internal::drop::OnDrop;
11use embassy_hal_internal::{Peri, PeripheralType}; 11use embassy_hal_internal::{Peri, PeripheralType};
12use embassy_sync::waitqueue::AtomicWaker; 12use embassy_sync::waitqueue::AtomicWaker;
13use sdio_host::common_cmd::{self, Resp, ResponseLen}; 13use sdio_host::common_cmd::{self, Resp, ResponseLen};
14use sdio_host::emmc::{ExtCSD, EMMC}; 14use sdio_host::emmc::{EMMC, ExtCSD};
15use sdio_host::sd::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CIC, CID, CSD, OCR, RCA, SCR, SD}; 15use sdio_host::sd::{BusWidth, CIC, CID, CSD, CardCapacity, CardStatus, CurrentState, OCR, RCA, SCR, SD, SDStatus};
16use sdio_host::{emmc_cmd, sd_cmd, Cmd}; 16use sdio_host::{Cmd, emmc_cmd, sd_cmd};
17 17
18#[cfg(sdmmc_v1)] 18#[cfg(sdmmc_v1)]
19use crate::dma::ChannelAndRequest; 19use crate::dma::ChannelAndRequest;
diff --git a/embassy-stm32/src/spdifrx/mod.rs b/embassy-stm32/src/spdifrx/mod.rs
index b0a32d5d1..6f2d24560 100644
--- a/embassy-stm32/src/spdifrx/mod.rs
+++ b/embassy-stm32/src/spdifrx/mod.rs
@@ -13,7 +13,7 @@ use crate::gpio::{AfType, AnyPin, Pull, SealedPin as _};
13use crate::interrupt::typelevel::Interrupt; 13use crate::interrupt::typelevel::Interrupt;
14use crate::pac::spdifrx::Spdifrx as Regs; 14use crate::pac::spdifrx::Spdifrx as Regs;
15use crate::rcc::{RccInfo, SealedRccPeripheral}; 15use crate::rcc::{RccInfo, SealedRccPeripheral};
16use crate::{interrupt, peripherals, Peri}; 16use crate::{Peri, interrupt, peripherals};
17 17
18/// Possible S/PDIF preamble types. 18/// Possible S/PDIF preamble types.
19#[allow(dead_code)] 19#[allow(dead_code)]
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index c5373a54d..c27d09ea7 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -6,15 +6,15 @@ use core::ptr;
6 6
7use embassy_embedded_hal::SetConfig; 7use embassy_embedded_hal::SetConfig;
8use embassy_futures::join::join; 8use embassy_futures::join::join;
9pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 9pub use embedded_hal_02::spi::{MODE_0, MODE_1, MODE_2, MODE_3, Mode, Phase, Polarity};
10 10
11use crate::dma::{word, ChannelAndRequest}; 11use crate::Peri;
12use crate::dma::{ChannelAndRequest, word};
12use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; 13use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
13use crate::mode::{Async, Blocking, Mode as PeriMode}; 14use crate::mode::{Async, Blocking, Mode as PeriMode};
14use crate::pac::spi::{regs, vals, Spi as Regs}; 15use crate::pac::spi::{Spi as Regs, regs, vals};
15use crate::rcc::{RccInfo, SealedRccPeripheral}; 16use crate::rcc::{RccInfo, SealedRccPeripheral};
16use crate::time::Hertz; 17use crate::time::Hertz;
17use crate::Peri;
18 18
19/// SPI error. 19/// SPI error.
20#[derive(Debug, PartialEq, Eq, Clone, Copy)] 20#[derive(Debug, PartialEq, Eq, Clone, Copy)]
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs
index 7db74bdf6..74b10a183 100644
--- a/embassy-stm32/src/time_driver.rs
+++ b/embassy-stm32/src/time_driver.rs
@@ -1,14 +1,14 @@
1#![allow(non_snake_case)] 1#![allow(non_snake_case)]
2 2
3use core::cell::{Cell, RefCell}; 3use core::cell::{Cell, RefCell};
4use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; 4use core::sync::atomic::{AtomicU32, Ordering, compiler_fence};
5 5
6use critical_section::CriticalSection; 6use critical_section::CriticalSection;
7use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
8use embassy_sync::blocking_mutex::Mutex; 7use embassy_sync::blocking_mutex::Mutex;
8use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
9use embassy_time_driver::{Driver, TICK_HZ}; 9use embassy_time_driver::{Driver, TICK_HZ};
10use embassy_time_queue_utils::Queue; 10use embassy_time_queue_utils::Queue;
11use stm32_metapac::timer::{regs, TimGp16}; 11use stm32_metapac::timer::{TimGp16, regs};
12 12
13use crate::interrupt::typelevel::Interrupt; 13use crate::interrupt::typelevel::Interrupt;
14use crate::pac::timer::vals; 14use crate::pac::timer::vals;
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs
index 484aae1d0..75a83629c 100644
--- a/embassy-stm32/src/timer/complementary_pwm.rs
+++ b/embassy-stm32/src/timer/complementary_pwm.rs
@@ -7,11 +7,11 @@ pub use stm32_metapac::timer::vals::{Ckd, Ossi, Ossr};
7use super::low_level::{CountingMode, OutputPolarity, Timer}; 7use super::low_level::{CountingMode, OutputPolarity, Timer};
8use super::simple_pwm::PwmPin; 8use super::simple_pwm::PwmPin;
9use super::{AdvancedInstance4Channel, Ch1, Ch2, Ch3, Ch4, Channel, TimerComplementaryPin}; 9use super::{AdvancedInstance4Channel, Ch1, Ch2, Ch3, Ch4, Channel, TimerComplementaryPin};
10use crate::Peri;
10use crate::gpio::{AnyPin, OutputType}; 11use crate::gpio::{AnyPin, OutputType};
11use crate::time::Hertz; 12use crate::time::Hertz;
12use crate::timer::low_level::OutputCompareMode;
13use crate::timer::TimerChannel; 13use crate::timer::TimerChannel;
14use crate::Peri; 14use crate::timer::low_level::OutputCompareMode;
15 15
16/// Complementary PWM pin wrapper. 16/// Complementary PWM pin wrapper.
17/// 17///
@@ -388,7 +388,7 @@ fn compute_dead_time_value(value: u16) -> (Ckd, u8) {
388 388
389#[cfg(test)] 389#[cfg(test)]
390mod tests { 390mod tests {
391 use super::{compute_dead_time_value, Ckd}; 391 use super::{Ckd, compute_dead_time_value};
392 392
393 #[test] 393 #[test]
394 fn test_compute_dead_time_value() { 394 fn test_compute_dead_time_value() {
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs
index 7a25e6c21..2a4ec2db0 100644
--- a/embassy-stm32/src/timer/input_capture.rs
+++ b/embassy-stm32/src/timer/input_capture.rs
@@ -8,11 +8,11 @@ use core::task::{Context, Poll};
8use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; 8use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer};
9use super::{CaptureCompareInterruptHandler, Channel, GeneralInstance4Channel, TimerPin}; 9use super::{CaptureCompareInterruptHandler, Channel, GeneralInstance4Channel, TimerPin};
10pub use super::{Ch1, Ch2, Ch3, Ch4}; 10pub use super::{Ch1, Ch2, Ch3, Ch4};
11use crate::Peri;
11use crate::gpio::{AfType, AnyPin, Pull}; 12use crate::gpio::{AfType, AnyPin, Pull};
12use crate::interrupt::typelevel::{Binding, Interrupt}; 13use crate::interrupt::typelevel::{Binding, Interrupt};
13use crate::time::Hertz; 14use crate::time::Hertz;
14use crate::timer::TimerChannel; 15use crate::timer::TimerChannel;
15use crate::Peri;
16 16
17/// Capture pin wrapper. 17/// Capture pin wrapper.
18/// 18///
diff --git a/embassy-stm32/src/timer/one_pulse.rs b/embassy-stm32/src/timer/one_pulse.rs
index a75b41bd7..fe8681356 100644
--- a/embassy-stm32/src/timer/one_pulse.rs
+++ b/embassy-stm32/src/timer/one_pulse.rs
@@ -11,12 +11,12 @@ use super::low_level::{
11}; 11};
12use super::{CaptureCompareInterruptHandler, Channel, ExternalTriggerPin, GeneralInstance4Channel, TimerPin}; 12use super::{CaptureCompareInterruptHandler, Channel, ExternalTriggerPin, GeneralInstance4Channel, TimerPin};
13pub use super::{Ch1, Ch2}; 13pub use super::{Ch1, Ch2};
14use crate::Peri;
14use crate::gpio::{AfType, AnyPin, Pull}; 15use crate::gpio::{AfType, AnyPin, Pull};
15use crate::interrupt::typelevel::{Binding, Interrupt}; 16use crate::interrupt::typelevel::{Binding, Interrupt};
16use crate::pac::timer::vals::Etp; 17use crate::pac::timer::vals::Etp;
17use crate::time::Hertz; 18use crate::time::Hertz;
18use crate::timer::TimerChannel; 19use crate::timer::TimerChannel;
19use crate::Peri;
20 20
21/// External input marker type. 21/// External input marker type.
22pub enum Ext {} 22pub enum Ext {}
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs
index 159b5a177..da8a79b09 100644
--- a/embassy-stm32/src/timer/pwm_input.rs
+++ b/embassy-stm32/src/timer/pwm_input.rs
@@ -2,9 +2,9 @@
2 2
3use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; 3use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource};
4use super::{Ch1, Ch2, Channel, GeneralInstance4Channel, TimerPin}; 4use super::{Ch1, Ch2, Channel, GeneralInstance4Channel, TimerPin};
5use crate::Peri;
5use crate::gpio::{AfType, Pull}; 6use crate::gpio::{AfType, Pull};
6use crate::time::Hertz; 7use crate::time::Hertz;
7use crate::Peri;
8 8
9/// PWM Input driver. 9/// PWM Input driver.
10/// 10///
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs
index 82b5968b0..a547a2a19 100644
--- a/embassy-stm32/src/timer/qei.rs
+++ b/embassy-stm32/src/timer/qei.rs
@@ -1,45 +1,67 @@
1//! Quadrature decoder using a timer. 1//! Quadrature decoder using a timer.
2 2
3use core::marker::PhantomData; 3use stm32_metapac::timer::vals::{self, Sms};
4
5use stm32_metapac::timer::vals;
6 4
7use super::low_level::Timer; 5use super::low_level::Timer;
8pub use super::{Ch1, Ch2}; 6pub use super::{Ch1, Ch2};
9use super::{GeneralInstance4Channel, TimerPin}; 7use super::{GeneralInstance4Channel, TimerPin};
8use crate::Peri;
10use crate::gpio::{AfType, AnyPin, Pull}; 9use crate::gpio::{AfType, AnyPin, Pull};
11use crate::timer::TimerChannel; 10use crate::timer::TimerChannel;
12use crate::Peri;
13 11
14/// Counting direction 12/// Qei driver config.
15pub enum Direction { 13#[cfg_attr(feature = "defmt", derive(defmt::Format))]
16 /// Counting up. 14#[derive(Clone, Copy)]
17 Upcounting, 15pub struct Config {
18 /// Counting down. 16 /// Configures the internal pull up/down resistor for Qei's channel 1 pin.
19 Downcounting, 17 pub ch1_pull: Pull,
18 /// Configures the internal pull up/down resistor for Qei's channel 2 pin.
19 pub ch2_pull: Pull,
20 /// Specifies the encoder mode to use for the Qei peripheral.
21 pub mode: QeiMode,
20} 22}
21 23
22/// Wrapper for using a pin with QEI. 24impl Default for Config {
23pub struct QeiPin<'d, T, Channel, #[cfg(afio)] A> { 25 /// Arbitrary defaults to preserve backwards compatibility
24 #[allow(unused)] 26 fn default() -> Self {
25 pin: Peri<'d, AnyPin>, 27 Self {
26 phantom: PhantomData<if_afio!((T, Channel, A))>, 28 ch1_pull: Pull::None,
29 ch2_pull: Pull::None,
30 mode: QeiMode::Mode3,
31 }
32 }
27} 33}
28 34
29impl<'d, T: GeneralInstance4Channel, C: QeiChannel, #[cfg(afio)] A> if_afio!(QeiPin<'d, T, C, A>) { 35/// See STMicro AN4013 for §2.3 for more information
30 /// Create a new QEI pin instance. 36#[cfg_attr(feature = "defmt", derive(defmt::Format))]
31 pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>) -> Self { 37#[derive(Clone, Copy)]
32 critical_section::with(|_| { 38pub enum QeiMode {
33 pin.set_low(); 39 /// Direct alias for [`Sms::ENCODER_MODE_1`]
34 set_as_af!(pin, AfType::input(Pull::None)); 40 Mode1,
35 }); 41 /// Direct alias for [`Sms::ENCODER_MODE_2`]
36 QeiPin { 42 Mode2,
37 pin: pin.into(), 43 /// Direct alias for [`Sms::ENCODER_MODE_3`]
38 phantom: PhantomData, 44 Mode3,
45}
46
47impl From<QeiMode> for Sms {
48 fn from(mode: QeiMode) -> Self {
49 match mode {
50 QeiMode::Mode1 => Sms::ENCODER_MODE_1,
51 QeiMode::Mode2 => Sms::ENCODER_MODE_2,
52 QeiMode::Mode3 => Sms::ENCODER_MODE_3,
39 } 53 }
40 } 54 }
41} 55}
42 56
57/// Counting direction
58pub enum Direction {
59 /// Counting up.
60 Upcounting,
61 /// Counting down.
62 Downcounting,
63}
64
43trait SealedQeiChannel: TimerChannel {} 65trait SealedQeiChannel: TimerChannel {}
44 66
45/// Marker trait for a timer channel eligible for use with QEI. 67/// Marker trait for a timer channel eligible for use with QEI.
@@ -55,20 +77,28 @@ impl SealedQeiChannel for Ch2 {}
55/// Quadrature decoder driver. 77/// Quadrature decoder driver.
56pub struct Qei<'d, T: GeneralInstance4Channel> { 78pub struct Qei<'d, T: GeneralInstance4Channel> {
57 inner: Timer<'d, T>, 79 inner: Timer<'d, T>,
80 _ch1: Peri<'d, AnyPin>,
81 _ch2: Peri<'d, AnyPin>,
58} 82}
59 83
60impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { 84impl<'d, T: GeneralInstance4Channel> Qei<'d, T> {
61 /// Create a new quadrature decoder driver. 85 /// Create a new quadrature decoder driver, with a given [`Config`].
62 #[allow(unused)] 86 #[allow(unused)]
63 pub fn new<#[cfg(afio)] A>( 87 pub fn new<CH1: QeiChannel, CH2: QeiChannel, #[cfg(afio)] A>(
64 tim: Peri<'d, T>, 88 tim: Peri<'d, T>,
65 ch1: if_afio!(QeiPin<'d, T, Ch1, A>), 89 ch1: Peri<'d, if_afio!(impl TimerPin<T, CH1, A>)>,
66 ch2: if_afio!(QeiPin<'d, T, Ch2, A>), 90 ch2: Peri<'d, if_afio!(impl TimerPin<T, CH2, A>)>,
91 config: Config,
67 ) -> Self { 92 ) -> Self {
68 Self::new_inner(tim) 93 // Configure the pins to be used for the QEI peripheral.
69 } 94 critical_section::with(|_| {
95 ch1.set_low();
96 set_as_af!(ch1, AfType::input(config.ch1_pull));
97
98 ch2.set_low();
99 set_as_af!(ch2, AfType::input(config.ch2_pull));
100 });
70 101
71 fn new_inner(tim: Peri<'d, T>) -> Self {
72 let inner = Timer::new(tim); 102 let inner = Timer::new(tim);
73 let r = inner.regs_gp16(); 103 let r = inner.regs_gp16();
74 104
@@ -88,13 +118,17 @@ impl<'d, T: GeneralInstance4Channel> Qei<'d, T> {
88 }); 118 });
89 119
90 r.smcr().modify(|w| { 120 r.smcr().modify(|w| {
91 w.set_sms(vals::Sms::ENCODER_MODE_3); 121 w.set_sms(config.mode.into());
92 }); 122 });
93 123
94 r.arr().modify(|w| w.set_arr(u16::MAX)); 124 r.arr().modify(|w| w.set_arr(u16::MAX));
95 r.cr1().modify(|w| w.set_cen(true)); 125 r.cr1().modify(|w| w.set_cen(true));
96 126
97 Self { inner } 127 Self {
128 inner,
129 _ch1: ch1.into(),
130 _ch2: ch2.into(),
131 }
98 } 132 }
99 133
100 /// Get direction. 134 /// Get direction.
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs
index e60bb5b06..36303aeb4 100644
--- a/embassy-stm32/src/timer/simple_pwm.rs
+++ b/embassy-stm32/src/timer/simple_pwm.rs
@@ -5,11 +5,11 @@ use core::mem::ManuallyDrop;
5 5
6use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; 6use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer};
7use super::{Ch1, Ch2, Ch3, Ch4, Channel, GeneralInstance4Channel, TimerBits, TimerChannel, TimerPin}; 7use super::{Ch1, Ch2, Ch3, Ch4, Channel, GeneralInstance4Channel, TimerBits, TimerChannel, TimerPin};
8use crate::Peri;
8#[cfg(gpio_v2)] 9#[cfg(gpio_v2)]
9use crate::gpio::Pull; 10use crate::gpio::Pull;
10use crate::gpio::{AfType, AnyPin, OutputType, Speed}; 11use crate::gpio::{AfType, AnyPin, OutputType, Speed};
11use crate::time::Hertz; 12use crate::time::Hertz;
12use crate::Peri;
13 13
14/// PWM pin wrapper. 14/// PWM pin wrapper.
15/// 15///
diff --git a/embassy-stm32/src/tsc/acquisition_banks.rs b/embassy-stm32/src/tsc/acquisition_banks.rs
index 7d6442b48..097cf7942 100644
--- a/embassy-stm32/src/tsc/acquisition_banks.rs
+++ b/embassy-stm32/src/tsc/acquisition_banks.rs
@@ -1,11 +1,11 @@
1use super::TSC_NUM_GROUPS;
1use super::io_pin::*; 2use super::io_pin::*;
2#[cfg(any(tsc_v2, tsc_v3))] 3#[cfg(any(tsc_v2, tsc_v3))]
3use super::pin_groups::G7; 4use super::pin_groups::G7;
4#[cfg(tsc_v3)] 5#[cfg(tsc_v3)]
5use super::pin_groups::G8; 6use super::pin_groups::G8;
6use super::pin_groups::{pin_roles, G1, G2, G3, G4, G5, G6}; 7use super::pin_groups::{G1, G2, G3, G4, G5, G6, pin_roles};
7use super::types::{Group, GroupStatus}; 8use super::types::{Group, GroupStatus};
8use super::TSC_NUM_GROUPS;
9 9
10/// Represents a collection of TSC (Touch Sensing Controller) pins for an acquisition bank. 10/// Represents a collection of TSC (Touch Sensing Controller) pins for an acquisition bank.
11/// 11///
diff --git a/embassy-stm32/src/tsc/pin_groups.rs b/embassy-stm32/src/tsc/pin_groups.rs
index 84421f7ff..9347e6bc0 100644
--- a/embassy-stm32/src/tsc/pin_groups.rs
+++ b/embassy-stm32/src/tsc/pin_groups.rs
@@ -1,11 +1,11 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::ops::BitOr; 2use core::ops::BitOr;
3 3
4use super::Instance;
4use super::errors::GroupError; 5use super::errors::GroupError;
5use super::io_pin::*; 6use super::io_pin::*;
6use super::Instance;
7use crate::gpio::{AfType, AnyPin, OutputType, Speed};
8use crate::Peri; 7use crate::Peri;
8use crate::gpio::{AfType, AnyPin, OutputType, Speed};
9 9
10/// Pin type definition to control IO parameters 10/// Pin type definition to control IO parameters
11#[derive(PartialEq, Clone, Copy)] 11#[derive(PartialEq, Clone, Copy)]
diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs
index 18aff4fbd..8f259a917 100644
--- a/embassy-stm32/src/ucpd.rs
+++ b/embassy-stm32/src/ucpd.rs
@@ -19,8 +19,8 @@ use core::marker::PhantomData;
19use core::sync::atomic::{AtomicBool, Ordering}; 19use core::sync::atomic::{AtomicBool, Ordering};
20use core::task::Poll; 20use core::task::Poll;
21 21
22use embassy_hal_internal::drop::OnDrop;
23use embassy_hal_internal::PeripheralType; 22use embassy_hal_internal::PeripheralType;
23use embassy_hal_internal::drop::OnDrop;
24use embassy_sync::waitqueue::AtomicWaker; 24use embassy_sync::waitqueue::AtomicWaker;
25 25
26use crate::dma::{ChannelAndRequest, TransferOptions}; 26use crate::dma::{ChannelAndRequest, TransferOptions};
@@ -28,7 +28,7 @@ use crate::interrupt::typelevel::Interrupt;
28use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode}; 28use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode};
29pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, Rxordset, TypecVstateCc as CcVState}; 29pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, Rxordset, TypecVstateCc as CcVState};
30use crate::rcc::{self, RccPeripheral}; 30use crate::rcc::{self, RccPeripheral};
31use crate::{interrupt, Peri}; 31use crate::{Peri, interrupt};
32 32
33pub(crate) fn init( 33pub(crate) fn init(
34 _cs: critical_section::CriticalSection, 34 _cs: critical_section::CriticalSection,
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs
index c734eed49..69c3a740f 100644
--- a/embassy-stm32/src/usart/buffered.rs
+++ b/embassy-stm32/src/usart/buffered.rs
@@ -1,20 +1,20 @@
1use core::future::poll_fn; 1use core::future::poll_fn;
2use core::marker::PhantomData; 2use core::marker::PhantomData;
3use core::slice; 3use core::slice;
4use core::sync::atomic::{AtomicBool, AtomicU8, Ordering}; 4use core::sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering};
5use core::task::Poll; 5use core::task::Poll;
6 6
7use embassy_embedded_hal::SetConfig; 7use embassy_embedded_hal::SetConfig;
8use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
9use embassy_hal_internal::Peri; 8use embassy_hal_internal::Peri;
9use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
10use embassy_sync::waitqueue::AtomicWaker; 10use embassy_sync::waitqueue::AtomicWaker;
11 11
12#[cfg(not(any(usart_v1, usart_v2)))] 12#[cfg(not(any(usart_v1, usart_v2)))]
13use super::DePin; 13use super::DePin;
14use super::{ 14use super::{
15 Config, ConfigError, CtsPin, Duplex, Error, HalfDuplexReadback, Info, Instance, Regs, RtsPin, RxPin, TxPin,
15 clear_interrupt_flags, configure, half_duplex_set_rx_tx_before_write, rdr, reconfigure, send_break, set_baudrate, 16 clear_interrupt_flags, configure, half_duplex_set_rx_tx_before_write, rdr, reconfigure, send_break, set_baudrate,
16 sr, tdr, Config, ConfigError, CtsPin, Duplex, Error, HalfDuplexReadback, Info, Instance, Regs, RtsPin, RxPin, 17 sr, tdr,
17 TxPin,
18}; 18};
19use crate::gpio::{AfType, AnyPin, Pull, SealedPin as _}; 19use crate::gpio::{AfType, AnyPin, Pull, SealedPin as _};
20use crate::interrupt::{self, InterruptExt}; 20use crate::interrupt::{self, InterruptExt};
@@ -68,8 +68,15 @@ unsafe fn on_interrupt(r: Regs, state: &'static State) {
68 // FIXME: Should we disable any further RX interrupts when the buffer becomes full. 68 // FIXME: Should we disable any further RX interrupts when the buffer becomes full.
69 } 69 }
70 70
71 if !state.rx_buf.is_empty() { 71 let eager = state.eager_reads.load(Ordering::Relaxed);
72 state.rx_waker.wake(); 72 if eager > 0 {
73 if state.rx_buf.available() >= eager {
74 state.rx_waker.wake();
75 }
76 } else {
77 if state.rx_buf.is_half_full() {
78 state.rx_waker.wake();
79 }
73 } 80 }
74 } 81 }
75 82
@@ -132,6 +139,7 @@ pub(super) struct State {
132 tx_done: AtomicBool, 139 tx_done: AtomicBool,
133 tx_rx_refcount: AtomicU8, 140 tx_rx_refcount: AtomicU8,
134 half_duplex_readback: AtomicBool, 141 half_duplex_readback: AtomicBool,
142 eager_reads: AtomicUsize,
135} 143}
136 144
137impl State { 145impl State {
@@ -144,6 +152,7 @@ impl State {
144 tx_done: AtomicBool::new(true), 152 tx_done: AtomicBool::new(true),
145 tx_rx_refcount: AtomicU8::new(0), 153 tx_rx_refcount: AtomicU8::new(0),
146 half_duplex_readback: AtomicBool::new(false), 154 half_duplex_readback: AtomicBool::new(false),
155 eager_reads: AtomicUsize::new(0),
147 } 156 }
148 } 157 }
149} 158}
@@ -419,6 +428,9 @@ impl<'d> BufferedUart<'d> {
419 let state = T::buffered_state(); 428 let state = T::buffered_state();
420 let kernel_clock = T::frequency(); 429 let kernel_clock = T::frequency();
421 430
431 state
432 .eager_reads
433 .store(config.eager_reads.unwrap_or(0), Ordering::Relaxed);
422 state.half_duplex_readback.store( 434 state.half_duplex_readback.store(
423 config.duplex == Duplex::Half(HalfDuplexReadback::Readback), 435 config.duplex == Duplex::Half(HalfDuplexReadback::Readback),
424 Ordering::Relaxed, 436 Ordering::Relaxed,
@@ -456,6 +468,9 @@ impl<'d> BufferedUart<'d> {
456 let info = self.rx.info; 468 let info = self.rx.info;
457 let state = self.rx.state; 469 let state = self.rx.state;
458 state.tx_rx_refcount.store(2, Ordering::Relaxed); 470 state.tx_rx_refcount.store(2, Ordering::Relaxed);
471 state
472 .eager_reads
473 .store(config.eager_reads.unwrap_or(0), Ordering::Relaxed);
459 474
460 info.rcc.enable_and_reset(); 475 info.rcc.enable_and_reset();
461 476
@@ -527,6 +542,11 @@ impl<'d> BufferedUart<'d> {
527 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { 542 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
528 reconfigure(self.rx.info, self.rx.kernel_clock, config)?; 543 reconfigure(self.rx.info, self.rx.kernel_clock, config)?;
529 544
545 self.rx
546 .state
547 .eager_reads
548 .store(config.eager_reads.unwrap_or(0), Ordering::Relaxed);
549
530 self.rx.info.regs.cr1().modify(|w| { 550 self.rx.info.regs.cr1().modify(|w| {
531 w.set_rxneie(true); 551 w.set_rxneie(true);
532 w.set_idleie(true); 552 w.set_idleie(true);
@@ -553,24 +573,30 @@ impl<'d> BufferedUartRx<'d> {
553 poll_fn(move |cx| { 573 poll_fn(move |cx| {
554 let state = self.state; 574 let state = self.state;
555 let mut rx_reader = unsafe { state.rx_buf.reader() }; 575 let mut rx_reader = unsafe { state.rx_buf.reader() };
556 let data = rx_reader.pop_slice(); 576 let mut buf_len = 0;
577 let mut data = rx_reader.pop_slice();
557 578
558 if !data.is_empty() { 579 while !data.is_empty() && buf_len < buf.len() {
559 let len = data.len().min(buf.len()); 580 let data_len = data.len().min(buf.len() - buf_len);
560 buf[..len].copy_from_slice(&data[..len]); 581 buf[buf_len..buf_len + data_len].copy_from_slice(&data[..data_len]);
582 buf_len += data_len;
561 583
562 let do_pend = state.rx_buf.is_full(); 584 let do_pend = state.rx_buf.is_full();
563 rx_reader.pop_done(len); 585 rx_reader.pop_done(data_len);
564 586
565 if do_pend { 587 if do_pend {
566 self.info.interrupt.pend(); 588 self.info.interrupt.pend();
567 } 589 }
568 590
569 return Poll::Ready(Ok(len)); 591 data = rx_reader.pop_slice();
570 } 592 }
571 593
572 state.rx_waker.register(cx.waker()); 594 if buf_len != 0 {
573 Poll::Pending 595 Poll::Ready(Ok(buf_len))
596 } else {
597 state.rx_waker.register(cx.waker());
598 Poll::Pending
599 }
574 }) 600 })
575 .await 601 .await
576 } 602 }
@@ -579,21 +605,24 @@ impl<'d> BufferedUartRx<'d> {
579 loop { 605 loop {
580 let state = self.state; 606 let state = self.state;
581 let mut rx_reader = unsafe { state.rx_buf.reader() }; 607 let mut rx_reader = unsafe { state.rx_buf.reader() };
582 let data = rx_reader.pop_slice(); 608 let mut buf_len = 0;
609 let mut data = rx_reader.pop_slice();
583 610
584 if !data.is_empty() { 611 while !data.is_empty() && buf_len < buf.len() {
585 let len = data.len().min(buf.len()); 612 let data_len = data.len().min(buf.len() - buf_len);
586 buf[..len].copy_from_slice(&data[..len]); 613 buf[buf_len..buf_len + data_len].copy_from_slice(&data[..data_len]);
614 buf_len += data_len;
587 615
588 let do_pend = state.rx_buf.is_full(); 616 let do_pend = state.rx_buf.is_full();
589 rx_reader.pop_done(len); 617 rx_reader.pop_done(data_len);
590 618
591 if do_pend { 619 if do_pend {
592 self.info.interrupt.pend(); 620 self.info.interrupt.pend();
593 } 621 }
594 622
595 return Ok(len); 623 data = rx_reader.pop_slice();
596 } 624 }
625 return Ok(buf_len);
597 } 626 }
598 } 627 }
599 628
@@ -633,6 +662,10 @@ impl<'d> BufferedUartRx<'d> {
633 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { 662 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
634 reconfigure(self.info, self.kernel_clock, config)?; 663 reconfigure(self.info, self.kernel_clock, config)?;
635 664
665 self.state
666 .eager_reads
667 .store(config.eager_reads.unwrap_or(0), Ordering::Relaxed);
668
636 self.info.regs.cr1().modify(|w| { 669 self.info.regs.cr1().modify(|w| {
637 w.set_rxneie(true); 670 w.set_rxneie(true);
638 w.set_idleie(true); 671 w.set_idleie(true);
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index ff211e0c9..0e7da634d 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -4,15 +4,16 @@
4 4
5use core::future::poll_fn; 5use core::future::poll_fn;
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::sync::atomic::{compiler_fence, AtomicU8, Ordering}; 7use core::sync::atomic::{AtomicU8, AtomicUsize, Ordering, compiler_fence};
8use core::task::Poll; 8use core::task::Poll;
9 9
10use embassy_embedded_hal::SetConfig; 10use embassy_embedded_hal::SetConfig;
11use embassy_hal_internal::drop::OnDrop;
12use embassy_hal_internal::PeripheralType; 11use embassy_hal_internal::PeripheralType;
12use embassy_hal_internal::drop::OnDrop;
13use embassy_sync::waitqueue::AtomicWaker; 13use embassy_sync::waitqueue::AtomicWaker;
14use futures_util::future::{select, Either}; 14use futures_util::future::{Either, select};
15 15
16use crate::Peri;
16use crate::dma::ChannelAndRequest; 17use crate::dma::ChannelAndRequest;
17use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; 18use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
18use crate::interrupt::typelevel::Interrupt as _; 19use crate::interrupt::typelevel::Interrupt as _;
@@ -25,7 +26,6 @@ use crate::pac::usart::Usart as Regs;
25use crate::pac::usart::{regs, vals}; 26use crate::pac::usart::{regs, vals};
26use crate::rcc::{RccInfo, SealedRccPeripheral}; 27use crate::rcc::{RccInfo, SealedRccPeripheral};
27use crate::time::Hertz; 28use crate::time::Hertz;
28use crate::Peri;
29 29
30/// Interrupt handler. 30/// Interrupt handler.
31pub struct InterruptHandler<T: Instance> { 31pub struct InterruptHandler<T: Instance> {
@@ -185,6 +185,12 @@ pub enum ConfigError {
185 RxOrTxNotEnabled, 185 RxOrTxNotEnabled,
186 /// Data bits and parity combination not supported 186 /// Data bits and parity combination not supported
187 DataParityNotSupported, 187 DataParityNotSupported,
188 /// DE assertion time too high
189 #[cfg(not(any(usart_v1, usart_v2)))]
190 DeAssertionTimeTooHigh,
191 /// DE deassertion time too high
192 #[cfg(not(any(usart_v1, usart_v2)))]
193 DeDeassertionTimeTooHigh,
188} 194}
189 195
190#[non_exhaustive] 196#[non_exhaustive]
@@ -206,6 +212,21 @@ pub struct Config {
206 /// If false: the error is ignored and cleared 212 /// If false: the error is ignored and cleared
207 pub detect_previous_overrun: bool, 213 pub detect_previous_overrun: bool,
208 214
215 /// If `None` (the default) then read-like calls on `BufferedUartRx` and `RingBufferedUartRx`
216 /// typically only wake/return after line idle or after the buffer is at least half full
217 /// (for `BufferedUartRx`) or the DMA buffer is written at the half or full positions
218 /// (for `RingBufferedUartRx`), though it may also wake/return earlier in some circumstances.
219 ///
220 /// If `Some(n)` then such reads are also woken/return as soon as at least `n` words are
221 /// available in the buffer, in addition to waking/returning when the conditions described
222 /// above are met. `Some(0)` is treated as `None`. Setting this for `RingBufferedUartRx`
223 /// will trigger an interrupt for every received word to check the buffer level, which may
224 /// impact performance at high data rates.
225 ///
226 /// Has no effect on plain `Uart` or `UartRx` reads, which are specified to either
227 /// return a single word, a full buffer, or after line idle.
228 pub eager_reads: Option<usize>,
229
209 /// Set this to true if the line is considered noise free. 230 /// Set this to true if the line is considered noise free.
210 /// This will increase the receiver’s tolerance to clock deviations, 231 /// This will increase the receiver’s tolerance to clock deviations,
211 /// but will effectively disable noise detection. 232 /// but will effectively disable noise detection.
@@ -239,6 +260,14 @@ pub struct Config {
239 /// Set the pin configuration for the DE pin. 260 /// Set the pin configuration for the DE pin.
240 pub de_config: OutputConfig, 261 pub de_config: OutputConfig,
241 262
263 /// Set DE assertion time before the first start bit, 0-31 16ths of a bit period.
264 #[cfg(not(any(usart_v1, usart_v2)))]
265 pub de_assertion_time: u8,
266
267 /// Set DE deassertion time after the last stop bit, 0-31 16ths of a bit period.
268 #[cfg(not(any(usart_v1, usart_v2)))]
269 pub de_deassertion_time: u8,
270
242 // private: set by new_half_duplex, not by the user. 271 // private: set by new_half_duplex, not by the user.
243 duplex: Duplex, 272 duplex: Duplex,
244} 273}
@@ -270,6 +299,7 @@ impl Default for Config {
270 parity: Parity::ParityNone, 299 parity: Parity::ParityNone,
271 // historical behavior 300 // historical behavior
272 detect_previous_overrun: false, 301 detect_previous_overrun: false,
302 eager_reads: None,
273 #[cfg(not(usart_v1))] 303 #[cfg(not(usart_v1))]
274 assume_noise_free: false, 304 assume_noise_free: false,
275 #[cfg(any(usart_v3, usart_v4))] 305 #[cfg(any(usart_v3, usart_v4))]
@@ -283,6 +313,10 @@ impl Default for Config {
283 tx_config: OutputConfig::PushPull, 313 tx_config: OutputConfig::PushPull,
284 rts_config: OutputConfig::PushPull, 314 rts_config: OutputConfig::PushPull,
285 de_config: OutputConfig::PushPull, 315 de_config: OutputConfig::PushPull,
316 #[cfg(not(any(usart_v1, usart_v2)))]
317 de_assertion_time: 0,
318 #[cfg(not(any(usart_v1, usart_v2)))]
319 de_deassertion_time: 0,
286 duplex: Duplex::Full, 320 duplex: Duplex::Full,
287 } 321 }
288 } 322 }
@@ -966,6 +1000,9 @@ impl<'d, M: Mode> UartRx<'d, M> {
966 let info = self.info; 1000 let info = self.info;
967 let state = self.state; 1001 let state = self.state;
968 state.tx_rx_refcount.store(1, Ordering::Relaxed); 1002 state.tx_rx_refcount.store(1, Ordering::Relaxed);
1003 state
1004 .eager_reads
1005 .store(config.eager_reads.unwrap_or(0), Ordering::Relaxed);
969 1006
970 info.rcc.enable_and_reset(); 1007 info.rcc.enable_and_reset();
971 1008
@@ -982,6 +1019,9 @@ impl<'d, M: Mode> UartRx<'d, M> {
982 1019
983 /// Reconfigure the driver 1020 /// Reconfigure the driver
984 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { 1021 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
1022 self.state
1023 .eager_reads
1024 .store(config.eager_reads.unwrap_or(0), Ordering::Relaxed);
985 reconfigure(self.info, self.kernel_clock, config) 1025 reconfigure(self.info, self.kernel_clock, config)
986 } 1026 }
987 1027
@@ -1462,6 +1502,9 @@ impl<'d, M: Mode> Uart<'d, M> {
1462 let info = self.rx.info; 1502 let info = self.rx.info;
1463 let state = self.rx.state; 1503 let state = self.rx.state;
1464 state.tx_rx_refcount.store(2, Ordering::Relaxed); 1504 state.tx_rx_refcount.store(2, Ordering::Relaxed);
1505 state
1506 .eager_reads
1507 .store(config.eager_reads.unwrap_or(0), Ordering::Relaxed);
1465 1508
1466 info.rcc.enable_and_reset(); 1509 info.rcc.enable_and_reset();
1467 1510
@@ -1690,6 +1733,16 @@ fn configure(
1690 return Err(ConfigError::RxOrTxNotEnabled); 1733 return Err(ConfigError::RxOrTxNotEnabled);
1691 } 1734 }
1692 1735
1736 #[cfg(not(any(usart_v1, usart_v2)))]
1737 let dem = r.cr3().read().dem();
1738
1739 #[cfg(not(any(usart_v1, usart_v2)))]
1740 if config.de_assertion_time > 31 {
1741 return Err(ConfigError::DeAssertionTimeTooHigh);
1742 } else if config.de_deassertion_time > 31 {
1743 return Err(ConfigError::DeDeassertionTimeTooHigh);
1744 }
1745
1693 // UART must be disabled during configuration. 1746 // UART must be disabled during configuration.
1694 r.cr1().modify(|w| { 1747 r.cr1().modify(|w| {
1695 w.set_ue(false); 1748 w.set_ue(false);
@@ -1738,6 +1791,20 @@ fn configure(
1738 w.set_re(enable_rx); 1791 w.set_re(enable_rx);
1739 } 1792 }
1740 1793
1794 #[cfg(not(any(usart_v1, usart_v2)))]
1795 if dem {
1796 w.set_deat(if over8 {
1797 config.de_assertion_time / 2
1798 } else {
1799 config.de_assertion_time
1800 });
1801 w.set_dedt(if over8 {
1802 config.de_assertion_time / 2
1803 } else {
1804 config.de_assertion_time
1805 });
1806 }
1807
1741 // configure word size and parity, since the parity bit is inserted into the MSB position, 1808 // configure word size and parity, since the parity bit is inserted into the MSB position,
1742 // it increases the effective word size 1809 // it increases the effective word size
1743 match (config.parity, config.data_bits) { 1810 match (config.parity, config.data_bits) {
@@ -2022,6 +2089,7 @@ struct State {
2022 rx_waker: AtomicWaker, 2089 rx_waker: AtomicWaker,
2023 tx_waker: AtomicWaker, 2090 tx_waker: AtomicWaker,
2024 tx_rx_refcount: AtomicU8, 2091 tx_rx_refcount: AtomicU8,
2092 eager_reads: AtomicUsize,
2025} 2093}
2026 2094
2027impl State { 2095impl State {
@@ -2030,6 +2098,7 @@ impl State {
2030 rx_waker: AtomicWaker::new(), 2098 rx_waker: AtomicWaker::new(),
2031 tx_waker: AtomicWaker::new(), 2099 tx_waker: AtomicWaker::new(),
2032 tx_rx_refcount: AtomicU8::new(0), 2100 tx_rx_refcount: AtomicU8::new(0),
2101 eager_reads: AtomicUsize::new(0),
2033 } 2102 }
2034 } 2103 }
2035} 2104}
diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs
index 5f4e87834..20bfefd9e 100644
--- a/embassy-stm32/src/usart/ringbuffered.rs
+++ b/embassy-stm32/src/usart/ringbuffered.rs
@@ -1,19 +1,19 @@
1use core::future::poll_fn; 1use core::future::poll_fn;
2use core::mem; 2use core::mem;
3use core::sync::atomic::{compiler_fence, Ordering}; 3use core::sync::atomic::{Ordering, compiler_fence};
4use core::task::Poll; 4use core::task::Poll;
5 5
6use embassy_embedded_hal::SetConfig; 6use embassy_embedded_hal::SetConfig;
7use embedded_io_async::ReadReady; 7use embedded_io_async::ReadReady;
8use futures_util::future::{select, Either}; 8use futures_util::future::{Either, select};
9 9
10use super::{rdr, reconfigure, set_baudrate, sr, Config, ConfigError, Error, Info, State, UartRx}; 10use super::{Config, ConfigError, Error, Info, State, UartRx, rdr, reconfigure, set_baudrate, sr};
11use crate::Peri;
11use crate::dma::ReadableRingBuffer; 12use crate::dma::ReadableRingBuffer;
12use crate::gpio::{AnyPin, SealedPin as _}; 13use crate::gpio::{AnyPin, SealedPin as _};
13use crate::mode::Async; 14use crate::mode::Async;
14use crate::time::Hertz; 15use crate::time::Hertz;
15use crate::usart::Regs; 16use crate::usart::Regs;
16use crate::Peri;
17 17
18/// Rx-only Ring-buffered UART Driver 18/// Rx-only Ring-buffered UART Driver
19/// 19///
@@ -26,9 +26,9 @@ use crate::Peri;
26/// contain enough bytes to fill the buffer passed by the caller of 26/// contain enough bytes to fill the buffer passed by the caller of
27/// the function, or is empty. 27/// the function, or is empty.
28/// 28///
29/// Waiting for bytes operates in one of two modes, depending on 29/// Waiting for bytes operates in one of three modes, depending on
30/// the behavior of the sender and the size of the buffer passed 30/// the behavior of the sender, the size of the buffer passed
31/// to the function: 31/// to the function, and the configuration:
32/// 32///
33/// - If the sender sends intermittently, the 'idle line' 33/// - If the sender sends intermittently, the 'idle line'
34/// condition will be detected when the sender stops, and any 34/// condition will be detected when the sender stops, and any
@@ -47,7 +47,11 @@ use crate::Peri;
47/// interrupt when those specific buffer addresses have been 47/// interrupt when those specific buffer addresses have been
48/// written. 48/// written.
49/// 49///
50/// In both cases this will result in variable latency due to the 50/// - If `eager_reads` is enabled in `config`, the UART interrupt
51/// is enabled on all data reception and the call will only wait
52/// for at least one byte to be available before returning.
53///
54/// In the first two cases this will result in variable latency due to the
51/// buffering effect. For example, if the baudrate is 2400 bps, and 55/// buffering effect. For example, if the baudrate is 2400 bps, and
52/// the configuration is 8 data bits, no parity bit, and one stop bit, 56/// the configuration is 8 data bits, no parity bit, and one stop bit,
53/// then a byte will be received every ~4.16ms. If the ring buffer is 57/// then a byte will be received every ~4.16ms. If the ring buffer is
@@ -68,15 +72,10 @@ use crate::Peri;
68/// sending, but would be falsely triggered in the worst-case 72/// sending, but would be falsely triggered in the worst-case
69/// buffer delay scenario. 73/// buffer delay scenario.
70/// 74///
71/// Note: This latency is caused by the limited capabilities of the 75/// Note: Enabling `eager_reads` with `RingBufferedUartRx` will enable
72/// STM32 DMA controller; since it cannot generate an interrupt when 76/// an UART RXNE interrupt, which will cause an interrupt to occur on
73/// it stores a byte into an empty ring buffer, or in any other 77/// every received data byte. The data is still copied using DMA, but
74/// configurable conditions, it is not possible to take notice of the 78/// there is nevertheless additional processing overhead for each byte.
75/// contents of the ring buffer more quickly without introducing
76/// polling. As a result the latency can be reduced by calling the
77/// read functions repeatedly with smaller buffers to receive the
78/// available bytes, as each call to a read function will explicitly
79/// check the ring buffer for available bytes.
80pub struct RingBufferedUartRx<'d> { 79pub struct RingBufferedUartRx<'d> {
81 info: &'static Info, 80 info: &'static Info,
82 state: &'static State, 81 state: &'static State,
@@ -133,6 +132,9 @@ impl<'d> UartRx<'d, Async> {
133impl<'d> RingBufferedUartRx<'d> { 132impl<'d> RingBufferedUartRx<'d> {
134 /// Reconfigure the driver 133 /// Reconfigure the driver
135 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { 134 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
135 self.state
136 .eager_reads
137 .store(config.eager_reads.unwrap_or(0), Ordering::Relaxed);
136 reconfigure(self.info, self.kernel_clock, config) 138 reconfigure(self.info, self.kernel_clock, config)
137 } 139 }
138 140
@@ -148,8 +150,8 @@ impl<'d> RingBufferedUartRx<'d> {
148 let r = self.info.regs; 150 let r = self.info.regs;
149 // clear all interrupts and DMA Rx Request 151 // clear all interrupts and DMA Rx Request
150 r.cr1().modify(|w| { 152 r.cr1().modify(|w| {
151 // disable RXNE interrupt 153 // use RXNE only when returning reads early
152 w.set_rxneie(false); 154 w.set_rxneie(self.state.eager_reads.load(Ordering::Relaxed) > 0);
153 // enable parity interrupt if not ParityNone 155 // enable parity interrupt if not ParityNone
154 w.set_peie(w.pce()); 156 w.set_peie(w.pce());
155 // enable idle line interrupt 157 // enable idle line interrupt
@@ -248,39 +250,67 @@ impl<'d> RingBufferedUartRx<'d> {
248 async fn wait_for_data_or_idle(&mut self) -> Result<(), Error> { 250 async fn wait_for_data_or_idle(&mut self) -> Result<(), Error> {
249 compiler_fence(Ordering::SeqCst); 251 compiler_fence(Ordering::SeqCst);
250 252
251 // Future which completes when idle line is detected 253 loop {
252 let s = self.state; 254 // Future which completes when idle line is detected
253 let uart = poll_fn(|cx| { 255 let s = self.state;
254 s.rx_waker.register(cx.waker()); 256 let mut uart_init = false;
255 257 let uart = poll_fn(|cx| {
256 compiler_fence(Ordering::SeqCst); 258 s.rx_waker.register(cx.waker());
257 259
258 if check_idle_and_errors(self.info.regs)? { 260 compiler_fence(Ordering::SeqCst);
259 // Idle line is detected 261
260 Poll::Ready(Ok(())) 262 // We may have been woken by IDLE or, if eager_reads is set, by RXNE.
261 } else { 263 // However, DMA will clear RXNE, so we can't check directly, and because
262 Poll::Pending 264 // the other future borrows `ring_buf`, we can't check `len()` here either.
263 } 265 // Instead, return from this future and we'll check the length afterwards.
264 }); 266 let eager = s.eager_reads.load(Ordering::Relaxed) > 0;
267
268 let idle = check_idle_and_errors(self.info.regs)?;
269 if idle || (eager && uart_init) {
270 // Idle line is detected, or eager reads is set and some data is available.
271 Poll::Ready(Ok(idle))
272 } else {
273 uart_init = true;
274 Poll::Pending
275 }
276 });
265 277
266 let mut dma_init = false; 278 let mut dma_init = false;
267 // Future which completes when the DMA controller indicates it 279 // Future which completes when the DMA controller indicates it
268 // has written to the ring buffer's middle byte, or last byte 280 // has written to the ring buffer's middle byte, or last byte
269 let dma = poll_fn(|cx| { 281 let dma = poll_fn(|cx| {
270 self.ring_buf.set_waker(cx.waker()); 282 self.ring_buf.set_waker(cx.waker());
271 283
272 let status = match dma_init { 284 let status = match dma_init {
273 false => Poll::Pending, 285 false => Poll::Pending,
274 true => Poll::Ready(()), 286 true => Poll::Ready(()),
275 }; 287 };
276 288
277 dma_init = true; 289 dma_init = true;
278 status 290 status
279 }); 291 });
280 292
281 match select(uart, dma).await { 293 match select(uart, dma).await {
282 Either::Left((result, _)) => result, 294 // UART woke with line idle
283 Either::Right(((), _)) => Ok(()), 295 Either::Left((Ok(true), _)) => {
296 return Ok(());
297 }
298 // UART woke without idle or error: word received
299 Either::Left((Ok(false), _)) => {
300 let eager = self.state.eager_reads.load(Ordering::Relaxed);
301 if eager > 0 && self.ring_buf.len().unwrap_or(0) >= eager {
302 return Ok(());
303 } else {
304 continue;
305 }
306 }
307 // UART woke with error
308 Either::Left((Err(e), _)) => {
309 return Err(e);
310 }
311 // DMA woke
312 Either::Right(((), _)) => return Ok(()),
313 }
284 } 314 }
285 } 315 }
286 316
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs
index 5ce81b131..f6b1a81db 100644
--- a/embassy-stm32/src/usb/otg.rs
+++ b/embassy-stm32/src/usb/otg.rs
@@ -2,18 +2,18 @@ use core::marker::PhantomData;
2 2
3use embassy_hal_internal::PeripheralType; 3use embassy_hal_internal::PeripheralType;
4use embassy_usb_driver::{EndpointAddress, EndpointAllocError, EndpointType, Event, Unsupported}; 4use embassy_usb_driver::{EndpointAddress, EndpointAllocError, EndpointType, Event, Unsupported};
5use embassy_usb_synopsys_otg::otg_v1::vals::Dspd;
6use embassy_usb_synopsys_otg::otg_v1::Otg;
7pub use embassy_usb_synopsys_otg::Config; 5pub use embassy_usb_synopsys_otg::Config;
6use embassy_usb_synopsys_otg::otg_v1::Otg;
7use embassy_usb_synopsys_otg::otg_v1::vals::Dspd;
8use embassy_usb_synopsys_otg::{ 8use embassy_usb_synopsys_otg::{
9 on_interrupt as on_interrupt_impl, Bus as OtgBus, ControlPipe, Driver as OtgDriver, Endpoint, In, OtgInstance, Out, 9 Bus as OtgBus, ControlPipe, Driver as OtgDriver, Endpoint, In, OtgInstance, Out, PhyType, State,
10 PhyType, State, 10 on_interrupt as on_interrupt_impl,
11}; 11};
12 12
13use crate::gpio::{AfType, OutputType, Speed}; 13use crate::gpio::{AfType, OutputType, Speed};
14use crate::interrupt::typelevel::Interrupt; 14use crate::interrupt::typelevel::Interrupt;
15use crate::rcc::{self, RccPeripheral}; 15use crate::rcc::{self, RccPeripheral};
16use crate::{interrupt, Peri}; 16use crate::{Peri, interrupt};
17 17
18const MAX_EP_COUNT: usize = 9; 18const MAX_EP_COUNT: usize = 9;
19 19
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs
index 9e08d99b3..d405e4802 100644
--- a/embassy-stm32/src/usb/usb.rs
+++ b/embassy-stm32/src/usb/usb.rs
@@ -12,11 +12,11 @@ use embassy_usb_driver::{
12 Direction, EndpointAddress, EndpointAllocError, EndpointError, EndpointInfo, EndpointType, Event, Unsupported, 12 Direction, EndpointAddress, EndpointAllocError, EndpointError, EndpointInfo, EndpointType, Event, Unsupported,
13}; 13};
14 14
15use crate::pac::USBRAM;
15use crate::pac::usb::regs; 16use crate::pac::usb::regs;
16use crate::pac::usb::vals::{EpType, Stat}; 17use crate::pac::usb::vals::{EpType, Stat};
17use crate::pac::USBRAM;
18use crate::rcc::RccPeripheral; 18use crate::rcc::RccPeripheral;
19use crate::{interrupt, Peri}; 19use crate::{Peri, interrupt};
20 20
21/// Interrupt handler. 21/// Interrupt handler.
22pub struct InterruptHandler<T: Instance> { 22pub struct InterruptHandler<T: Instance> {
diff --git a/embassy-stm32/src/vrefbuf/mod.rs b/embassy-stm32/src/vrefbuf/mod.rs
index ccbd748d5..b061306a0 100644
--- a/embassy-stm32/src/vrefbuf/mod.rs
+++ b/embassy-stm32/src/vrefbuf/mod.rs
@@ -62,8 +62,7 @@ impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> {
62 } 62 }
63 trace!( 63 trace!(
64 "Vrefbuf configured with voltage scale {} and impedance mode {}", 64 "Vrefbuf configured with voltage scale {} and impedance mode {}",
65 voltage_scale as u8, 65 voltage_scale as u8, impedance_mode as u8,
66 impedance_mode as u8,
67 ); 66 );
68 VoltageReferenceBuffer { vrefbuf: PhantomData } 67 VoltageReferenceBuffer { vrefbuf: PhantomData }
69 } 68 }
diff --git a/embassy-stm32/src/wdg/mod.rs b/embassy-stm32/src/wdg/mod.rs
index fb5c3d930..1164739ff 100644
--- a/embassy-stm32/src/wdg/mod.rs
+++ b/embassy-stm32/src/wdg/mod.rs
@@ -4,8 +4,8 @@ use core::marker::PhantomData;
4use embassy_hal_internal::PeripheralType; 4use embassy_hal_internal::PeripheralType;
5use stm32_metapac::iwdg::vals::{Key, Pr}; 5use stm32_metapac::iwdg::vals::{Key, Pr};
6 6
7use crate::rcc::LSI_FREQ;
8use crate::Peri; 7use crate::Peri;
8use crate::rcc::LSI_FREQ;
9 9
10/// Independent watchdog (IWDG) driver. 10/// Independent watchdog (IWDG) driver.
11pub struct IndependentWatchdog<'d, T: Instance> { 11pub struct IndependentWatchdog<'d, T: Instance> {
diff --git a/embassy-stm32/src/xspi/mod.rs b/embassy-stm32/src/xspi/mod.rs
index 901569f64..a80a2692b 100644
--- a/embassy-stm32/src/xspi/mod.rs
+++ b/embassy-stm32/src/xspi/mod.rs
@@ -11,15 +11,15 @@ use embassy_embedded_hal::{GetConfig, SetConfig};
11use embassy_hal_internal::PeripheralType; 11use embassy_hal_internal::PeripheralType;
12pub use enums::*; 12pub use enums::*;
13 13
14use crate::dma::{word, ChannelAndRequest}; 14use crate::dma::{ChannelAndRequest, word};
15use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; 15use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
16use crate::mode::{Async, Blocking, Mode as PeriMode}; 16use crate::mode::{Async, Blocking, Mode as PeriMode};
17use crate::pac::xspi::vals::*;
18use crate::pac::xspi::Xspi as Regs; 17use crate::pac::xspi::Xspi as Regs;
18use crate::pac::xspi::vals::*;
19#[cfg(xspim_v1)] 19#[cfg(xspim_v1)]
20use crate::pac::xspim::Xspim; 20use crate::pac::xspim::Xspim;
21use crate::rcc::{self, RccPeripheral}; 21use crate::rcc::{self, RccPeripheral};
22use crate::{peripherals, Peri}; 22use crate::{Peri, peripherals};
23 23
24/// XPSI driver config. 24/// XPSI driver config.
25#[derive(Clone, Copy)] 25#[derive(Clone, Copy)]