Skip to content

Commit a2edb22

Browse files
committed
Prevent underflow when calling delay(n) with n<2
Calling delay(1) causes a very long wait (freeze) otherwise. 86cd463 introduced this behaviour by changing the cycle count from n / 4 + 1 to n / 2 which forces an underflow when n<2.
1 parent c714cdf commit a2edb22

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

asm/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub unsafe fn __delay(cyc: u32) {
5555
// The loop will normally take 3 to 4 CPU cycles per iteration, but superscalar cores
5656
// (eg. Cortex-M7) can potentially do it in 2, so we use that as the lower bound, since delaying
5757
// for more cycles is okay.
58-
let real_cyc = cyc / 2;
58+
let real_cyc = 1 + cyc / 2;
5959
asm!(
6060
// Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m.
6161
"1:",

0 commit comments

Comments
 (0)