diff --git a/pycardium/mphalport.c b/pycardium/mphalport.c index 2fa432eb57020c0ccb9627fd8b3b5dbeb1124de0..b17e9ca3245a120b69b16a319ce2896ffc5c391c 100644 --- a/pycardium/mphalport.c +++ b/pycardium/mphalport.c @@ -246,9 +246,18 @@ static void systick_delay(uint32_t us) while (final_time - systick_get_us() > SYSTICK_INTERVAL_US) { uint32_t sleep_time = (final_time - systick_get_us()) / 1000; - if (sleep_time > 100) - sleep_time = 100; + + /* We need to wake up at least in SYSTICK_INTERVAL_US to make + * sure we serve the systick interrupt. + * Add some error margin to avoid issues with the clock accuracy + * of epicardium */ + if (sleep_time > SYSTICK_INTERVAL_US / 1000 / 2) { + sleep_time = SYSTICK_INTERVAL_US / 1000 / 2; + } epic_sleep(sleep_time); + /* epic_sleep() can return early if there was an interrupt + * coming from epicardium side. + * Give MP a chance to handle them. */ mp_handle_pending(true); }