Commit 3509e2d3 authored by Damien George's avatar Damien George
Browse files

stmhal/systick: Make mp_hal_delay_ms release the GIL when sleeping.

parent 2e3fc778
......@@ -51,24 +51,17 @@ void HAL_Delay(uint32_t Delay) {
}
// Core delay function that does an efficient sleep and may switch thread context.
// Note: Upon entering this function we may or may not have the GIL.
// If IRQs are enabled then we must have the GIL.
void mp_hal_delay_ms(mp_uint_t Delay) {
if (query_irq() == IRQ_STATE_ENABLED) {
// 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) {
// Enter sleep mode, waiting for (at least) the SysTick interrupt.
mp_handle_pending();
#if MICROPY_PY_THREAD
if (pyb_thread_enabled) {
pyb_thread_yield();
} else {
__WFI();
}
#else
__WFI();
#endif
// 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
}
} else {
// IRQs disabled, so need to use a busy loop for the delay.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment