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
This commit is contained in:
Torin Cooper-Bennun 2024-04-16 15:13:31 +01:00
parent 8e850de592
commit d928663bae

View File

@ -76,7 +76,12 @@ pub(crate) fn blocking_delay_us(us: u32) {
#[cfg(time)]
embassy_time::block_for(embassy_time::Duration::from_micros(us));
#[cfg(not(time))]
cortex_m::asm::delay(unsafe { crate::rcc::get_freqs() }.sys.unwrap().0 * us / 1_000_000);
{
let freq = unsafe { crate::rcc::get_freqs() }.sys.unwrap().0 as u64;
let us = us as u64;
let cycles = freq * us / 1_000_000;
cortex_m::asm::delay(cycles as u32);
}
}
/// ADC instance.