Skip to content

Commit 86a698a

Browse files
committed
[delay] Fix register constraints for subs.n instruction
1 parent 3ecad35 commit 86a698a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/modm/platform/core/cortex/delay_impl.hpp.in

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ extern uint16_t delay_fcpu_MHz;
3333

3434
inline void modm_fastcode delay_ns(uint32_t ns)
3535
{
36-
volatile uint32_t overhead_cycles;
36+
volatile uint32_t cycles;
3737
// ns_per_loop = nanoseconds per cycle times cycles per loop ({{loop}} cycles)
3838
asm volatile (
39-
".syntax unified" "\n\t"
40-
"muls.n %0, %0, %2" "\n\t" // multiply the overhead cycles with the ns per cycle: 1-2 cycles on cm3, up to 32 cycles on cm0
41-
"subs.n %1, %1, %0" "\n\t" // subtract the overhead in ns from the input: 1 cycle
42-
"1: subs.n %1, %1, %2" "\n\t" // subtract the ns per loop from the input: 1 cycle
43-
"bpl.n 1b" "\n\t" // keep doing that while result is still positive: 2 cycles (when taken)
44-
: "=r" (overhead_cycles) : "r" (ns), "r" (platform::delay_ns_per_loop), "0" ({{ (overhead / loop) | int}}));
39+
".syntax unified \n\t"
40+
".align 4 \n\t"
41+
"muls.n %[cyc], %[cyc], %[dnpl] \n\t" // multiply the overhead cycles with the ns per cycle: 1-2 cycles on cm3, up to 32 cycles on cm0
42+
"subs.n %[cyc], %[cyc], %[ovhd] \n\t" // subtract the overhead in ns from the input: 1 cycle
43+
"1: subs.n %[cyc], %[cyc], %[dnpl] \n\t" // subtract the ns per loop from the input: 1 cycle
44+
"bpl.n 1b" // keep doing that while result is still positive: 2 cycles (when taken)
45+
: [cyc] "=l" (cycles) : "0" (ns), [dnpl] "l" (platform::delay_ns_per_loop), [ovhd] "l" ({{(overhead / loop) | int}}));
4546
// => loop is {{loop}} cycles long
4647
}
4748
void delay_us(uint32_t us);

0 commit comments

Comments
 (0)