Skip to content

Commit c37ae2c

Browse files
committed
Fix asm::delay() variability due to alignment
1 parent 898b11c commit c37ae2c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cortex-m/src/asm.rs

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub fn delay(cycles: u32) {
3333
let real_cycles = 1 + cycles / 2;
3434
unsafe {
3535
asm!(
36+
// The `bne` on some cores (eg Cortex-M4) will take a different number of instructions
37+
// depending on the alignment of the branch target. Set the alignment of the top of the
38+
// loop to prevent surprising timing changes when the alignment of the delay() changes.
39+
".p2align 3",
3640
// Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m.
3741
"1:",
3842
"subs {}, #1",

0 commit comments

Comments
 (0)