Skip to content

Commit 24a29b1

Browse files
ianrreesadamgreig
authored andcommitted
Fix asm::delay() variability due to alignment (#587)
1 parent 9801539 commit 24a29b1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cortex-m/asm/inline.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ pub unsafe fn __delay(cyc: u32) {
6060
// Add 1 to prevent an integer underflow which would cause a long freeze
6161
let real_cyc = 1 + cyc / 2;
6262
asm!(
63+
// The `bne` on some cores (eg Cortex-M4) will take a different number of instructions
64+
// depending on the alignment of the branch target. Set the alignment of the top of the
65+
// loop to prevent surprising timing changes when the alignment of the delay() changes.
66+
".p2align 3",
6367
// Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m.
6468
"1:",
6569
"subs {}, #1",

0 commit comments

Comments
 (0)