Skip to content

Commit 592c241

Browse files
committed
nrf5x fix race condition where init usb hardware cause USB IRQ to trigger before tusb is inited
1 parent 6fee649 commit 592c241

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/arduino/ports/nrf/Adafruit_TinyUSB_nrf.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ static void usb_hardware_init(void);
6464
static void usb_device_task(void *param) {
6565
(void)param;
6666

67+
// Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
68+
// 2 is highest for application
69+
NVIC_SetPriority(USBD_IRQn, 2);
70+
6771
tusb_init();
6872

73+
usb_hardware_init();
74+
6975
// RTOS forever loop
7076
while (1) {
7177
tud_task();
@@ -75,8 +81,6 @@ static void usb_device_task(void *param) {
7581
void TinyUSB_Port_InitDevice(uint8_t rhport) {
7682
(void)rhport;
7783

78-
usb_hardware_init();
79-
8084
// Create a task for tinyusb device stack
8185
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SZ, NULL, TASK_PRIO_HIGH,
8286
NULL);
@@ -111,10 +115,6 @@ static void power_event_handler(nrfx_power_usb_evt_t event) {
111115

112116
// Init usb hardware when starting up. Softdevice is not enabled yet
113117
static void usb_hardware_init(void) {
114-
// Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
115-
// 2 is highest for application
116-
NVIC_SetPriority(USBD_IRQn, 2);
117-
118118
// USB power may already be ready at this time -> no event generated
119119
// We need to invoke the handler based on the status initially
120120
uint32_t usb_reg = NRF_POWER->USBREGSTATUS;

0 commit comments

Comments
 (0)