Skip to content

Commit

Permalink
stm32/systick: Always POLL_HOOK when delaying for milliseconds.
Browse files Browse the repository at this point in the history
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 #5344.
  • Loading branch information
nevercast authored and dpgeorge committed Jul 21, 2021
1 parent a5221c4 commit 6bc50c4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ports/stm32/systick.c
Expand Up @@ -96,12 +96,12 @@ void mp_hal_delay_ms(mp_uint_t Delay) {
// IRQs enabled, so can use systick counter to do the delay
uint32_t start = uwTick;
// Wraparound of tick is taken care of by 2's complement arithmetic.
while (uwTick - start < Delay) {
do {
// This macro will execute the necessary idle behaviour. It may
// raise an exception, switch threads or enter sleep mode (waiting for
// (at least) the SysTick interrupt).
MICROPY_EVENT_POLL_HOOK
}
} while (uwTick - start < Delay);
} else {
// IRQs disabled, so need to use a busy loop for the delay.
// To prevent possible overflow of the counter we use a double loop.
Expand Down

0 comments on commit 6bc50c4

Please sign in to comment.