Просмотр исходного кода

Merge pull request #1221 from kasjer/kasjer/fix-nrf5x-vbus-race-condition

nrf5x: Fix race condition during startup
Ha Thach 4 лет назад
Родитель
Сommit
6bf7fba2a4
1 измененных файлов с 7 добавлено и 1 удалено
  1. 7 1
      src/portable/nordic/nrf5x/dcd_nrf5x.c

+ 7 - 1
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() ) { }