diff --git a/cortex-m/src/asm.rs b/cortex-m/src/asm.rs index 756899f8..47b286a4 100644 --- a/cortex-m/src/asm.rs +++ b/cortex-m/src/asm.rs @@ -33,6 +33,10 @@ pub fn delay(cycles: u32) { let real_cycles = 1 + cycles / 2; unsafe { asm!( + // The `bne` on some cores (eg Cortex-M4) will take a different number of instructions + // depending on the alignment of the branch target. Set the alignment of the top of the + // loop to prevent surprising timing changes when the alignment of the delay() changes. + ".p2align 3", // Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m. "1:", "subs {}, #1",