@@ -76,6 +76,17 @@ void usb_softdevice_post_enable(void)
7676 sd_power_usbdetected_enable (true );
7777 sd_power_usbpwrrdy_enable (true );
7878 sd_power_usbremoved_enable (true );
79+
80+ uint32_t usb_reg;
81+ sd_power_usbregstatus_get (&usb_reg);
82+
83+ // Note: Detect event is possibly handled by usb_hardware_init() however depending on how fast
84+ // Bluefruit.begin() is called, Ready event may or may not be handled before we disable the nrfx_power.
85+ // USBPULLUP not enabled -> Ready event not yet handled
86+ if ( (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk) && (NRF_USBD->USBPULLUP == 0 ) )
87+ {
88+ tusb_hal_nrf_power_event (NRFX_POWER_USB_EVT_READY);
89+ }
7990}
8091
8192#endif
@@ -163,7 +174,7 @@ AdafruitBluefruit::AdafruitBluefruit(void)
163174 _ble_event_sem = NULL ;
164175 _soc_event_sem = NULL ;
165176#ifdef ANT_LICENSE_KEY
166- _mprot_event_sem = NULL ; // additiona semaphore for multiprotocol
177+ _mprot_event_sem = NULL ;
167178#endif
168179
169180 _led_blink_th = NULL ;
@@ -294,34 +305,31 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
294305#if defined( USE_LFXO )
295306 nrf_clock_lf_cfg_t clock_cfg =
296307 {
297- // LFXO
298- .source = NRF_CLOCK_LF_SRC_XTAL,
299- .rc_ctiv = 0 ,
300- .rc_temp_ctiv = 0 ,
301- .accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
308+ // LFXO
309+ .source = NRF_CLOCK_LF_SRC_XTAL,
310+ .rc_ctiv = 0 ,
311+ .rc_temp_ctiv = 0 ,
312+ .accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
302313 };
303314#elif defined( USE_LFRC )
304315 nrf_clock_lf_cfg_t clock_cfg =
305316 {
306- // LXRC
307- .source = NRF_CLOCK_LF_SRC_RC,
308- .rc_ctiv = 16 ,
309- .rc_temp_ctiv = 2 ,
310- .accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
317+ // LXRC
318+ .source = NRF_CLOCK_LF_SRC_RC,
319+ .rc_ctiv = 16 ,
320+ .rc_temp_ctiv = 2 ,
321+ .accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
311322 };
312323#else
313324 #error Clock Source is not configured, define USE_LFXO or USE_LFRC according to your board in variant.h
314325#endif
315326
316- /* ------------------------------------------------------------------
317- ** BLE only Softdevices have 2-args sd_softdevice_enable()
318- ** BLE & ANT+ Softdevices have 3-args sd_softdevice_enable()
319- */
320- #ifdef ANT_LICENSE_KEY
327+ // Enable SoftDevice
328+ #ifdef ANT_LICENSE_KEY
321329 VERIFY_STATUS ( sd_softdevice_enable (&clock_cfg, nrf_error_cb, ANT_LICENSE_KEY), false );
322- #else // #ifdef ANT_LICENSE_KEY
330+ #else
323331 VERIFY_STATUS ( sd_softdevice_enable (&clock_cfg, nrf_error_cb), false );
324- #endif // #ifdef ANT_LICENSE_KEY
332+ #endif
325333
326334#ifdef USE_TINYUSB
327335 usb_softdevice_post_enable ();
@@ -464,13 +472,6 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
464472 ble_gap_conn_sec_mode_t sec_mode = BLE_SECMODE_OPEN;
465473 VERIFY_STATUS (sd_ble_gap_device_name_set (&sec_mode, (uint8_t const *) CFG_DEFAULT_NAME, strlen (CFG_DEFAULT_NAME)), false );
466474
467- // ------------- USB -------------//
468- #ifdef USE_TINYUSB
469- sd_power_usbdetected_enable (true );
470- sd_power_usbpwrrdy_enable (true );
471- sd_power_usbremoved_enable (true );
472- #endif
473-
474475 // Init Central role
475476 if (_central_count) Central.begin ();
476477
@@ -684,13 +685,21 @@ bool AdafruitBluefruit::setPIN(const char* pin)
684685 *------------------------------------------------------------------*/
685686void SD_EVT_IRQHandler(void )
686687{
687- // Notify both BLE & SOC Task
688+ #if CFG_SYSVIEW
689+ SEGGER_SYSVIEW_RecordEnterISR ();
690+ #endif
691+
692+ // Notify both BLE & SOC & MultiProtocol (if any) Task
688693 xSemaphoreGiveFromISR (Bluefruit._soc_event_sem , NULL );
689694 xSemaphoreGiveFromISR (Bluefruit._ble_event_sem , NULL );
695+
690696#ifdef ANT_LICENSE_KEY
691- // Notify parallel multiprotocol Task, if any
692697 if (Bluefruit._mprot_event_sem ) xSemaphoreGiveFromISR (Bluefruit._mprot_event_sem , NULL );
693698#endif
699+
700+ #if CFG_SYSVIEW
701+ SEGGER_SYSVIEW_RecordExitISR ();
702+ #endif
694703}
695704
696705/* *
0 commit comments