Skip to content

Commit 0a5947c

Browse files
MabezDevjessebraham
authored andcommitted
Correct Systimer delay implementation
Closes #229
1 parent cc3c291 commit 0a5947c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

esp-hal-common/src/delay.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ mod delay {
6767
let t0 = SystemTimer::now();
6868
let clocks = (us as u64 * self.freq.raw()) / HertzU64::MHz(1).raw();
6969

70-
while SystemTimer::now().wrapping_sub(t0) <= clocks {}
70+
while SystemTimer::now().wrapping_sub(t0) & SystemTimer::BIT_MASK <= clocks {}
7171
}
7272
}
7373
}

esp-hal-common/src/systimer.rs

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ pub struct SystemTimer {
2323
}
2424

2525
impl SystemTimer {
26+
#[cfg(esp32s2)]
27+
pub const BIT_MASK: u64 = u64::MAX;
28+
#[cfg(any(esp32c2, esp32c3, esp32s3))]
29+
pub const BIT_MASK: u64 = 0xFFFFFFFFFFFFF;
30+
2631
#[cfg(esp32s2)]
2732
pub const TICKS_PER_SECOND: u64 = 80_000_000; // TODO this can change when we have support for changing APB frequency
2833
#[cfg(any(esp32c2, esp32c3, esp32s3))]

0 commit comments

Comments
 (0)