diff --git a/esp-hal-common/src/delay.rs b/esp-hal-common/src/delay.rs index ff64eaecb38..b8fea440571 100644 --- a/esp-hal-common/src/delay.rs +++ b/esp-hal-common/src/delay.rs @@ -67,7 +67,7 @@ mod delay { let t0 = SystemTimer::now(); let clocks = (us as u64 * self.freq.raw()) / HertzU64::MHz(1).raw(); - while SystemTimer::now().wrapping_sub(t0) <= clocks {} + while SystemTimer::now().wrapping_sub(t0) & SystemTimer::BIT_MASK <= clocks {} } } } diff --git a/esp-hal-common/src/systimer.rs b/esp-hal-common/src/systimer.rs index 86b1b44ac71..a7c8962db90 100644 --- a/esp-hal-common/src/systimer.rs +++ b/esp-hal-common/src/systimer.rs @@ -23,6 +23,11 @@ pub struct SystemTimer { } impl SystemTimer { + #[cfg(esp32s2)] + pub const BIT_MASK: u64 = u64::MAX; + #[cfg(any(esp32c2, esp32c3, esp32s3))] + pub const BIT_MASK: u64 = 0xFFFFFFFFFFFFF; + #[cfg(esp32s2)] pub const TICKS_PER_SECOND: u64 = 80_000_000; // TODO this can change when we have support for changing APB frequency #[cfg(any(esp32c2, esp32c3, esp32s3))]