diff options
| author | liebman <[email protected]> | 2025-10-26 11:46:12 -0700 |
|---|---|---|
| committer | liebman <[email protected]> | 2025-11-03 12:50:41 -0800 |
| commit | 9a10134df204875e9cf85b3113471c6b3c78e70c (patch) | |
| tree | 17a45eafcbeff619ed153fc43dd58582423d13d8 | |
| parent | 0d6e782b6405332ebc8251f18017d005dc3f370a (diff) | |
don't use embassy_time for blocking_delay_us on stm32wlex low-power
| -rw-r--r-- | embassy-stm32/src/adc/mod.rs | 20 |
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)] |
| 89 | pub(crate) fn blocking_delay_us(us: u32) { | 89 | pub(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 | ||
