summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJerzy Kasenberg <[email protected]>2021-12-01 13:38:20 +0100
committerJerzy Kasenberg <[email protected]>2021-12-08 08:27:27 +0100
commit21db2351fdd3edd560e14d2949b9b0d217a51f93 (patch)
treeb6a581834fc49e6fbbc017760ce2ee6df4a4a588 /src
parent6af58e3385837e8cbcee2fb4df42b62ad6772547 (diff)
nrf5x: Fix race condition during startup
When NRF5x device is reset by software (after DFU for example), power event is ready from the beginning. When power interrupt is triggered before tud_init() finished USBD_IRQn is enabled before it would be enabled in tud_init(). This in turn may result in BUS RESET event being sent from USB interrupt to USB task when queue is not initialized yet. This scenario often happens in Mynewt build where queue creation takes more time. To prevent this scenario USBD_IRQn is not enabled in power event interrupt handler before dcd_init() was called.
Diffstat (limited to 'src')
-rw-r--r--src/portable/nordic/nrf5x/dcd_nrf5x.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c
index 2bcd56b8a..ed597a34f 100644
--- a/src/portable/nordic/nrf5x/dcd_nrf5x.c
+++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c
@@ -1059,7 +1059,13 @@ void tusb_hal_nrf_power_event (uint32_t event)
// Enable interrupt, priorities should be set by application
NVIC_ClearPendingIRQ(USBD_IRQn);
- NVIC_EnableIRQ(USBD_IRQn);
+ // Don't enable USBD interrupt yet, if dcd_init() did not finish yet
+ // Interrupt will be enabled by tud_init(), when USB stack is ready
+ // to handle interrupts.
+ if (tud_inited())
+ {
+ NVIC_EnableIRQ(USBD_IRQn);
+ }
// Wait for HFCLK
while ( !hfclk_running() ) { }