Skip to content

Commit 6bc50c4

Browse files
nevercastdpgeorge
authored andcommitted
stm32/systick: Always POLL_HOOK when delaying for milliseconds.
Call MICROPY_EVENT_POLL_HOOK even on very short delays so that busy loops that call sleep_ms still yield to events and other threads. See related issue micropython#5344.
1 parent a5221c4 commit 6bc50c4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ports/stm32/systick.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ void mp_hal_delay_ms(mp_uint_t Delay) {
9696
// IRQs enabled, so can use systick counter to do the delay
9797
uint32_t start = uwTick;
9898
// Wraparound of tick is taken care of by 2's complement arithmetic.
99-
while (uwTick - start < Delay) {
99+
do {
100100
// This macro will execute the necessary idle behaviour. It may
101101
// raise an exception, switch threads or enter sleep mode (waiting for
102102
// (at least) the SysTick interrupt).
103103
MICROPY_EVENT_POLL_HOOK
104-
}
104+
} while (uwTick - start < Delay);
105105
} else {
106106
// IRQs disabled, so need to use a busy loop for the delay.
107107
// To prevent possible overflow of the counter we use a double loop.

0 commit comments

Comments
 (0)