Skip to content

Commit ed86fdb

Browse files
robert-hhdpgeorge
authored andcommitted
samd/mphalport: Fix an execution order bug in mp_hal_ticks_us_64().
The upper 32 bit of the 64 bit ticks register was taken before disabling the interrupts. That may have caused a wrong return values. Besides that, the function may cause trouble when called in an IRQ context, because it unconditionally enables IRQ. Signed-off-by: robert-hh <[email protected]>
1 parent 3294606 commit ed86fdb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ports/samd/mphalport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ void mp_hal_delay_us(mp_uint_t us) {
9494
}
9595

9696
uint64_t mp_hal_ticks_us_64(void) {
97-
uint32_t us64_upper = ticks_us64_upper;
9897
uint32_t us64_lower;
9998
uint8_t intflag;
10099
__disable_irq();
100+
uint32_t us64_upper = ticks_us64_upper;
101101
#if defined(MCU_SAMD21)
102102
us64_lower = REG_TC4_COUNT32_COUNT;
103103
intflag = TC4->COUNT32.INTFLAG.reg;

0 commit comments

Comments
 (0)