summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-05-21 10:24:11 -0700
committerGitHub <noreply@github.com>2020-05-21 10:24:11 -0700
commiteea01c32b8c7727989774f0bb08a5efafc45911e (patch)
treea78193a084a8772f3e98b19b918e3e45e5f75b53
parentedc5d8938e0360a61fcea03344d3c525d836048d (diff)
parent67cf005ee545df6b1d6f2a4947c58d6c2afb0f51 (diff)
Merge pull request #2868 from xobs/fix-usb-sleep-nrf
Fix usb sleep for NRF
m---------lib/tinyusb0
-rw-r--r--ports/nrf/peripherals/nrf/nvm.c2
-rw-r--r--ports/nrf/supervisor/port.c15
-rw-r--r--supervisor/shared/usb/tusb_config.h2
4 files changed, 18 insertions, 1 deletions
diff --git a/lib/tinyusb b/lib/tinyusb
-Subproject 76bf96bcb0c12ba241ee4ecc175afb257e550d1
+Subproject dc5445e2f45cb348a44fe24fc1be4bc8b5ba5ba
diff --git a/ports/nrf/peripherals/nrf/nvm.c b/ports/nrf/peripherals/nrf/nvm.c
index 63b168f14..dc50e2eef 100644
--- a/ports/nrf/peripherals/nrf/nvm.c
+++ b/ports/nrf/peripherals/nrf/nvm.c
@@ -40,6 +40,8 @@
STATIC bool sd_is_enabled(void) {
uint8_t sd_en = 0;
+ if (__get_PRIMASK())
+ return false;
(void) sd_softdevice_is_enabled(&sd_en);
return sd_en;
}
diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c
index ea09115f7..36725293c 100644
--- a/ports/nrf/supervisor/port.c
+++ b/ports/nrf/supervisor/port.c
@@ -51,8 +51,11 @@
#include "common-hal/rtc/RTC.h"
#include "common-hal/neopixel_write/__init__.h"
+#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/rtc/__init__.h"
+#include "lib/tinyusb/src/device/usbd.h"
+
#ifdef CIRCUITPY_AUDIOBUSIO
#include "common-hal/audiobusio/I2SOut.h"
#endif
@@ -264,7 +267,17 @@ void port_sleep_until_interrupt(void) {
sd_app_evt_wait();
} else {
// Call wait for interrupt ourselves if the SD isn't enabled.
- __WFI();
+ // Note that `wfi` should be called with interrupts disabled,
+ // to ensure that the queue is properly drained. The `wfi`
+ // instruction will returned as long as an interrupt is
+ // available, even though the actual handler won't fire until
+ // we re-enable interrupts.
+ common_hal_mcu_disable_interrupts();
+ if (!tud_task_event_ready()) {
+ __DSB();
+ __WFI();
+ }
+ common_hal_mcu_enable_interrupts();
}
}
diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h
index 627de743e..5b7230983 100644
--- a/supervisor/shared/usb/tusb_config.h
+++ b/supervisor/shared/usb/tusb_config.h
@@ -49,7 +49,9 @@
//--------------------------------------------------------------------+
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
+#ifndef CFG_TUSB_DEBUG
#define CFG_TUSB_DEBUG 0
+#endif
/*------------- RTOS -------------*/
#ifndef CFG_TUSB_OS