Skip to content

Commit 77cf4dc

Browse files
committed
nrf: disable interrupts before running wfi
In order to ensure we don't have any outstanding requests, disable interrupts prior to issuing `WFI`. As part of this process, check to see if there are any pending USB requests, and only execute the `WFI` if there is no pending data. This fixes #2855 on NRF. Signed-off-by: Sean Cross <[email protected]>
1 parent d1a7fdd commit 77cf4dc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ports/nrf/supervisor/port.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@
5151
#include "common-hal/rtc/RTC.h"
5252
#include "common-hal/neopixel_write/__init__.h"
5353

54+
#include "shared-bindings/microcontroller/__init__.h"
5455
#include "shared-bindings/rtc/__init__.h"
5556

57+
#include "lib/tinyusb/src/device/usbd.h"
58+
5659
#ifdef CIRCUITPY_AUDIOBUSIO
5760
#include "common-hal/audiobusio/I2SOut.h"
5861
#endif
@@ -264,7 +267,15 @@ void port_sleep_until_interrupt(void) {
264267
sd_app_evt_wait();
265268
} else {
266269
// Call wait for interrupt ourselves if the SD isn't enabled.
267-
__WFI();
270+
// Note that `wfi` should be called with interrupts disabled,
271+
// to ensure that the queue is properly drained. The `wfi`
272+
// instruction will returned as long as an interrupt is
273+
// available, even though the actual handler won't fire until
274+
// we re-enable interrupts.
275+
common_hal_mcu_disable_interrupts();
276+
if (!tud_task_event_ready())
277+
__WFI();
278+
common_hal_mcu_enable_interrupts();
268279
}
269280
}
270281

0 commit comments

Comments
 (0)