diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index 4679d13565..1d78f00320 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -228,15 +228,6 @@ extern const struct _mp_obj_module_t mp_module_time; #define MICROPY_MPHALPORT_H "windows_mphal.h" -#if MICROPY_ENABLE_SCHEDULER -#define MICROPY_EVENT_POLL_HOOK \ - do { \ - extern void mp_handle_pending(bool); \ - mp_handle_pending(true); \ - mp_hal_delay_us(500); \ - } while (0); -#endif - // We need to provide a declaration/definition of alloca() #include @@ -244,6 +235,17 @@ extern const struct _mp_obj_module_t mp_module_time; #include "init.h" #include "sleep.h" +#if MICROPY_ENABLE_SCHEDULER +// Use 1mSec sleep to make sure there is effectively a wait period: +// something like usleep(500) truncates and ends up calling Sleep(0). +#define MICROPY_EVENT_POLL_HOOK \ + do { \ + extern void mp_handle_pending(bool); \ + mp_handle_pending(true); \ + msec_sleep(1.0); \ + } while (0); +#endif + #ifdef __GNUC__ #define MP_NOINLINE __attribute__((noinline)) #endif diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index 7913435f75..17b20c3031 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -280,7 +280,6 @@ void mp_hal_delay_ms(mp_uint_t ms) { #ifdef MICROPY_EVENT_POLL_HOOK mp_uint_t start = mp_hal_ticks_ms(); while (mp_hal_ticks_ms() - start < ms) { - // MICROPY_EVENT_POLL_HOOK does mp_hal_delay_us(500) (i.e. usleep(500)). MICROPY_EVENT_POLL_HOOK } #else