Skip to content

Commit 5bf528a

Browse files
authored
Merge pull request #587 from ianrrees/align-delay
Fix asm::delay() variability due to alignment
2 parents 31a0e61 + 2e9892d commit 5bf528a

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)