aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorin Cooper-Bennun <[email protected]>2024-04-16 15:13:31 +0100
committerTorin Cooper-Bennun <[email protected]>2024-04-16 15:13:31 +0100
commitd928663baeb851e830e04e469f3a338ad3f4bc15 (patch)
tree710104ee03fad309b0b436ae5403998c973c034e
parent8e850de5925f14f19524a8860b289eb751fb9bf9 (diff)
stm32: adc: fix blocking_delay_us() overflowing when sys freq is high
e.g. H503 running at 250 MHz resulted in an upper bound of 17 us here. casting up to u64 for intermediate calc allows the upper bound to be increased by a factor of 1e6
-rw-r--r--embassy-stm32/src/adc/mod.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs
index 12c5751bd..2ff2ed6a8 100644
--- a/embassy-stm32/src/adc/mod.rs
+++ b/embassy-stm32/src/adc/mod.rs
@@ -76,7 +76,12 @@ pub(crate) fn blocking_delay_us(us: u32) {
76 #[cfg(time)] 76 #[cfg(time)]
77 embassy_time::block_for(embassy_time::Duration::from_micros(us)); 77 embassy_time::block_for(embassy_time::Duration::from_micros(us));
78 #[cfg(not(time))] 78 #[cfg(not(time))]
79 cortex_m::asm::delay(unsafe { crate::rcc::get_freqs() }.sys.unwrap().0 * us / 1_000_000); 79 {
80 let freq = unsafe { crate::rcc::get_freqs() }.sys.unwrap().0 as u64;
81 let us = us as u64;
82 let cycles = freq * us / 1_000_000;
83 cortex_m::asm::delay(cycles as u32);
84 }
80} 85}
81 86
82/// ADC instance. 87/// ADC instance.