Skip to content

Fix usb sleep for NRF #2868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ports/nrf/peripherals/nrf/nvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 14 additions & 1 deletion ports/nrf/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}

Expand Down
2 changes: 2 additions & 0 deletions supervisor/shared/usb/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down