aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/adc/mod.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs
index 22ed8295f..ea7341f75 100644
--- a/embassy-stm32/src/adc/mod.rs
+++ b/embassy-stm32/src/adc/mod.rs
@@ -87,14 +87,18 @@ pub(crate) trait SealedAdcChannel<T> {
87/// Performs a busy-wait delay for a specified number of microseconds. 87/// Performs a busy-wait delay for a specified number of microseconds.
88#[allow(unused)] 88#[allow(unused)]
89pub(crate) fn blocking_delay_us(us: u32) { 89pub(crate) fn blocking_delay_us(us: u32) {
90 #[cfg(feature = "time")] 90 cfg_if::cfg_if! {
91 embassy_time::block_for(embassy_time::Duration::from_micros(us as u64)); 91 // this does strange things on stm32wlx in low power mode depending on exactly when it's called
92 #[cfg(not(feature = "time"))] 92 // as in sometimes 15 us (1 tick) would take > 20 seconds.
93 { 93 if #[cfg(all(feature = "time", all(not(feature = "low-power"), not(stm32wlex))))] {
94 let freq = unsafe { crate::rcc::get_freqs() }.sys.to_hertz().unwrap().0 as u64; 94 let duration = embassy_time::Duration::from_micros(us as u64);
95 let us = us as u64; 95 embassy_time::block_for(duration);
96 let cycles = freq * us / 1_000_000; 96 } else {
97 cortex_m::asm::delay(cycles as u32); 97 let freq = unsafe { crate::rcc::get_freqs() }.sys.to_hertz().unwrap().0 as u64;
98 let us = us as u64;
99 let cycles = freq * us / 1_000_000;
100 cortex_m::asm::delay(cycles as u32);
101 }
98 } 102 }
99} 103}
100 104