From 6bc50c4fa9da1d97f1ff14b1331d8d497962ed17 Mon Sep 17 00:00:00 2001 From: Josh Lloyd Date: Wed, 20 Nov 2019 17:18:09 +1300 Subject: [PATCH] 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 #5344. --- ports/stm32/systick.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/stm32/systick.c b/ports/stm32/systick.c index d70fc00539..7d1e318ac0 100644 --- a/ports/stm32/systick.c +++ b/ports/stm32/systick.c @@ -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.