diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c index f014cb6bb..e90fcd1e6 100644 --- a/nimble/host/src/ble_hs.c +++ b/nimble/host/src/ble_hs.c @@ -212,6 +212,7 @@ static struct ble_npl_callout ble_hs_timer; static struct ble_mqueue ble_hs_rx_q; static struct ble_npl_mutex ble_hs_mutex; +static bool ble_hs_initialized; #endif // BLE_STATIC_TO_DYNAMIC STATS_SECT_DECL(ble_hs_stats) ble_hs_stats; @@ -1087,6 +1088,9 @@ ble_hs_init(void) #endif /* Initialize npl variables related to hs flow control */ ble_hs_flow_init(); +#if !MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC) + ble_hs_initialized = true; +#endif } /* Transport APIs for HS side */ @@ -1134,6 +1138,11 @@ ble_hs_deinit(void) if (ble_hs_ctx == NULL) { return; } +#else + if (!ble_hs_initialized) { + return; + } + ble_hs_initialized = false; #endif ble_hs_flow_deinit(); diff --git a/porting/nimble/src/nimble_port.c b/porting/nimble/src/nimble_port.c index 597f16e9a..87d93d9b9 100644 --- a/porting/nimble/src/nimble_port.c +++ b/porting/nimble/src/nimble_port.c @@ -457,6 +457,18 @@ IRAM_ATTR void nimble_port_run(void) { struct ble_npl_event *ev; + +#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC) + if (ble_npl_ctx == NULL) { + ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble context not initialized, host task exiting"); + return; + } +#endif + if (g_eventq_dflt.eventq == NULL) { + ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble event queue not initialized, host task exiting"); + return; + } + /* Snapshot stop_ev and stop_sem addresses before entering the loop. * When BLE_STATIC_TO_DYNAMIC is enabled, after ble_npl_sem_release(stop_sem) * at the end of stop-event handling, the caller of nimble_port_stop() can diff --git a/porting/npl/freertos/src/npl_os_freertos.c b/porting/npl/freertos/src/npl_os_freertos.c index 9c0810222..b30e18600 100644 --- a/porting/npl/freertos/src/npl_os_freertos.c +++ b/porting/npl/freertos/src/npl_os_freertos.c @@ -461,6 +461,10 @@ npl_freertos_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo) BaseType_t woken = pdFALSE; BaseType_t ret; + if (!eventq) { + return NULL; + } + if (in_isr()) { BLE_LL_ASSERT(tmo == 0); woken = pdFALSE;