From 213dca167e7b192c63fbbdfe551e4b40c10c5999 Mon Sep 17 00:00:00 2001 From: Shen Wei Long Date: Thu, 11 Jun 2026 12:23:35 +0000 Subject: [PATCH 1/2] fix(bt): fixed the npl callout stop issue (cherry picked from commit bb4eeb8edc65308be85c3f26a9eb2fb2b93e4467) Co-authored-by: ShenWeilong --- .../npl/freertos/include/nimble/npl_freertos.h | 3 ++- .../bt/porting/npl/freertos/src/npl_os_freertos.c | 13 +++++++++++++ .../btdm_common/include/btdm_osal_freertos.h | 3 ++- .../controller/btdm_common/src/btdm_osal_freertos.c | 13 +++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/components/bt/porting/npl/freertos/include/nimble/npl_freertos.h b/components/bt/porting/npl/freertos/include/nimble/npl_freertos.h index 57c2db43e20..6cec8d98228 100644 --- a/components/bt/porting/npl/freertos/include/nimble/npl_freertos.h +++ b/components/bt/porting/npl/freertos/include/nimble/npl_freertos.h @@ -19,7 +19,8 @@ extern "C" { /* Use esp timer instead of FreeRTOS timer to implement the callout. */ #define BLE_NPL_USE_ESP_TIMER (1) #else -#define BLE_NPL_USE_ESP_TIMER (0) +/* Always use esp timer */ +#define BLE_NPL_USE_ESP_TIMER (1) #endif typedef struct { diff --git a/components/bt/porting/npl/freertos/src/npl_os_freertos.c b/components/bt/porting/npl/freertos/src/npl_os_freertos.c index d4b8fc883c5..5430647bb3e 100644 --- a/components/bt/porting/npl/freertos/src/npl_os_freertos.c +++ b/components/bt/porting/npl/freertos/src/npl_os_freertos.c @@ -787,6 +787,9 @@ IRAM_ATTR npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co; #if BLE_NPL_USE_ESP_TIMER esp_timer_stop(callout->handle); + if (callout->evq) { + npl_freertos_eventq_remove(callout->evq, &callout->ev); + } return esp_err_to_npl_error(esp_timer_start_once(callout->handle, ticks*1000)); #else @@ -798,6 +801,9 @@ IRAM_ATTR npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t } if (in_isr()) { xTimerStopFromISR(callout->handle, &woken1); + if (callout->evq) { + npl_freertos_eventq_remove(callout->evq, &callout->ev); + } xTimerChangePeriodFromISR(callout->handle, ticks, &woken2); xTimerResetFromISR(callout->handle, &woken3); @@ -806,6 +812,9 @@ IRAM_ATTR npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t } } else { xTimerStop(callout->handle, portMAX_DELAY); + if (callout->evq) { + npl_freertos_eventq_remove(callout->evq, &callout->ev); + } xTimerChangePeriod(callout->handle, ticks, portMAX_DELAY); xTimerReset(callout->handle, portMAX_DELAY); } @@ -828,6 +837,10 @@ IRAM_ATTR npl_freertos_callout_stop(struct ble_npl_callout *co) #else xTimerStop(callout->handle, portMAX_DELAY); #endif + + if (callout->evq) { + npl_freertos_eventq_remove(callout->evq, &callout->ev); + } } bool diff --git a/components/bt/porting_btdm/controller/btdm_common/include/btdm_osal_freertos.h b/components/bt/porting_btdm/controller/btdm_common/include/btdm_osal_freertos.h index 789f03a1930..cc184f9afb2 100644 --- a/components/bt/porting_btdm/controller/btdm_common/include/btdm_osal_freertos.h +++ b/components/bt/porting_btdm/controller/btdm_common/include/btdm_osal_freertos.h @@ -28,7 +28,8 @@ extern "C" { /* Use esp timer instead of FreeRTOS timer to implement the callout. */ #define BTDM_OSAL_USE_ESP_TIMER (1) #else -#define BTDM_OSAL_USE_ESP_TIMER (0) +/* Always use esp timer */ +#define BTDM_OSAL_USE_ESP_TIMER (1) #endif struct btdm_osal_event_freertos { diff --git a/components/bt/porting_btdm/controller/btdm_common/src/btdm_osal_freertos.c b/components/bt/porting_btdm/controller/btdm_common/src/btdm_osal_freertos.c index 41a522685b3..b9220767d18 100644 --- a/components/bt/porting_btdm/controller/btdm_common/src/btdm_osal_freertos.c +++ b/components/bt/porting_btdm/controller/btdm_common/src/btdm_osal_freertos.c @@ -795,6 +795,9 @@ wr_btdm_osal_callout_reset(struct btdm_osal_callout *co, btdm_osal_time_t ticks) struct btdm_osal_callout_freertos *callout = (struct btdm_osal_callout_freertos *)co->co; #if BTDM_OSAL_USE_ESP_TIMER esp_timer_stop(callout->handle); + if (callout->evq) { + btdm_osal_eventq_remove(callout->evq, &callout->ev); + } return esp_err_to_npl_error(esp_timer_start_once(callout->handle, ticks * 1000)); #else @@ -806,6 +809,9 @@ wr_btdm_osal_callout_reset(struct btdm_osal_callout *co, btdm_osal_time_t ticks) } if (in_isr()) { xTimerStopFromISR(callout->handle, &woken1); + if (callout->evq) { + btdm_osal_eventq_remove(callout->evq, &callout->ev); + } xTimerChangePeriodFromISR(callout->handle, ticks, &woken2); xTimerResetFromISR(callout->handle, &woken3); @@ -814,6 +820,9 @@ wr_btdm_osal_callout_reset(struct btdm_osal_callout *co, btdm_osal_time_t ticks) } } else { xTimerStop(callout->handle, portMAX_DELAY); + if (callout->evq) { + btdm_osal_eventq_remove(callout->evq, &callout->ev); + } xTimerChangePeriod(callout->handle, ticks, portMAX_DELAY); xTimerReset(callout->handle, portMAX_DELAY); } @@ -844,6 +853,10 @@ wr_btdm_osal_callout_stop(struct btdm_osal_callout *co) #else xTimerStop(callout->handle, portMAX_DELAY); #endif + + if (callout->evq) { + btdm_osal_eventq_remove(callout->evq, &callout->ev); + } } bool IRAM_ATTR From 30458851b3ec6e429d828ab2c7d702412a714f99 Mon Sep 17 00:00:00 2001 From: ShenWeilong Date: Thu, 4 Jun 2026 22:05:19 +0800 Subject: [PATCH 2/2] feat(ble): updated libble to 71d180a4 for esp32h4 and esp32s31 --- components/bt/controller/lib_esp32h4/esp32h4-bt-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/lib_esp32h4/esp32h4-bt-lib b/components/bt/controller/lib_esp32h4/esp32h4-bt-lib index c731689655d..09b1bc34cec 160000 --- a/components/bt/controller/lib_esp32h4/esp32h4-bt-lib +++ b/components/bt/controller/lib_esp32h4/esp32h4-bt-lib @@ -1 +1 @@ -Subproject commit c731689655dc07cf1d3010aaa16b42ac1a3dd826 +Subproject commit 09b1bc34cec46e256a96242803e855caddac9f05