From e79340601fc051183d6cc243c43da7f2e75249ae Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 25 May 2020 20:51:02 +0700 Subject: [PATCH] fix racing issue for SAMD when executing WFI --- ports/atmel-samd/supervisor/port.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index eadd3e8f5374a..2b3e9826f8664 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -69,6 +69,7 @@ #include "samd/events.h" #include "samd/external_interrupts.h" #include "samd/dma.h" +#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/rtc/__init__.h" #include "reset.h" @@ -496,7 +497,12 @@ void port_sleep_until_interrupt(void) { (void) __get_FPSCR(); } #endif - __WFI(); + common_hal_mcu_disable_interrupts(); + if (!tud_task_event_ready()) { + __DSB(); + __WFI(); + } + common_hal_mcu_enable_interrupts(); } /**