From 669c7bb80f1e9ea378c8bd52a4b3de114f467d0e Mon Sep 17 00:00:00 2001 From: Jin Chen Date: Fri, 6 Mar 2026 10:13:20 +0800 Subject: [PATCH 1/5] fix(ble): use apb max state for bt and enable should skip on ESP32-C2 (cherry picked from commit 9de0235a9f893fff66cbdbca0783c56b54ac28e3) Co-authored-by: cjin --- components/bt/controller/esp32c2/bt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index 148c3087c1..1fea1a19ae 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -779,7 +779,7 @@ esp_err_t controller_sleep_init(modem_clock_lpclk_src_t slow_clk_src) // enable light sleep #ifdef CONFIG_PM_ENABLE - rc = esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "bt", &s_pm_lock); + rc = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock); if (rc != ESP_OK) { goto error; } From ad2b8c7d4f4a75eb08e823c84b9d4b91fc9e5b0a Mon Sep 17 00:00:00 2001 From: Jin Chen Date: Fri, 6 Mar 2026 10:13:20 +0800 Subject: [PATCH 2/5] fix(ble): use apb max state for bt and enable should skip on ESP32-C5 (cherry picked from commit 8365eb324fbe0a18ca1f46073bf816b1e71d380b) Co-authored-by: cjin --- components/bt/controller/esp32c5/bt.c | 30 +++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/components/bt/controller/esp32c5/bt.c b/components/bt/controller/esp32c5/bt.c index 2b1945ccd9..d16dcddc65 100644 --- a/components/bt/controller/esp32c5/bt.c +++ b/components/bt/controller/esp32c5/bt.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -47,6 +47,7 @@ #if CONFIG_FREERTOS_USE_TICKLESS_IDLE #include "esp_private/sleep_modem.h" #include "esp_private/sleep_retention.h" +#include "esp_private/pm_impl.h" #endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE #include "freertos/FreeRTOS.h" @@ -165,6 +166,7 @@ extern void esp_ble_controller_flash_only_param_config(void); #endif // CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY #if CONFIG_FREERTOS_USE_TICKLESS_IDLE extern sleep_retention_entries_config_t *r_esp_ble_mac_retention_link_get(uint8_t *size, uint8_t extra); +extern bool r_ble_lll_sleep_should_skip_light_sleep_check(void); extern void r_esp_ble_set_wakeup_overhead(uint32_t overhead); #endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */ #if CONFIG_BT_LE_LL_PEER_SCA_SET_ENABLE @@ -802,7 +804,7 @@ esp_err_t controller_sleep_init(void) #endif // CONFIG_BT_LE_SLEEP_ENABLE #ifdef CONFIG_PM_ENABLE - rc = esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "bt", &s_pm_lock); + rc = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock); if (rc != ESP_OK) { goto error; } @@ -816,15 +818,17 @@ esp_err_t controller_sleep_init(void) esp_sleep_enable_bt_wakeup(); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "Enable light sleep, the wake up source is BLE timer"); + rc = esp_pm_register_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); + if (rc != ESP_OK) { + ESP_LOGE(NIMBLE_PORT_LOG_TAG, "Should skip cb register error"); + goto error; + } + rc = esp_pm_register_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set); if (rc != ESP_OK) { goto error; } -#if SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD - sleep_modem_register_mac_bb_module_prepare_callback(sleep_modem_mac_bb_power_down_prepare, - sleep_modem_mac_bb_power_up_prepare); -#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD #endif /* CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE */ return rc; @@ -832,12 +836,9 @@ esp_err_t controller_sleep_init(void) error: #endif // CONFIG_PM_ENABLE #if CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE -#if SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD - sleep_modem_unregister_mac_bb_module_prepare_callback(sleep_modem_mac_bb_power_down_prepare, - sleep_modem_mac_bb_power_up_prepare); -#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD - esp_sleep_disable_bt_wakeup(); + esp_pm_unregister_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); esp_pm_unregister_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set); + esp_sleep_disable_bt_wakeup(); #endif /* CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE */ #ifdef CONFIG_PM_ENABLE /*lock should release first and then delete*/ @@ -853,14 +854,11 @@ error: void controller_sleep_deinit(void) { #if CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE -#if SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD - sleep_modem_unregister_mac_bb_module_prepare_callback(sleep_modem_mac_bb_power_down_prepare, - sleep_modem_mac_bb_power_up_prepare); -#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD r_ble_rtc_wake_up_state_clr(); + esp_pm_unregister_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); + esp_pm_unregister_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set); esp_sleep_disable_bt_wakeup(); sleep_modem_ble_mac_modem_state_deinit(); - esp_pm_unregister_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set); #endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */ #ifdef CONFIG_PM_ENABLE /* lock should be released first */ From 5304090fd9082e5e6e5f6b3aa2857d06e1fb9f18 Mon Sep 17 00:00:00 2001 From: Jin Chen Date: Fri, 6 Mar 2026 10:13:21 +0800 Subject: [PATCH 3/5] fix(ble): use apb max state for bt and enable should skip on ESP32-C6 (cherry picked from commit 73191cb5f94ae09cff356de88cbd039460918268) Co-authored-by: cjin --- components/bt/controller/esp32c6/bt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 018f06ff6f..6531b7059f 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -48,6 +48,7 @@ #if CONFIG_FREERTOS_USE_TICKLESS_IDLE #include "esp_private/sleep_modem.h" #include "esp_private/sleep_retention.h" +#include "esp_private/pm_impl.h" #endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE #include "freertos/FreeRTOS.h" @@ -176,6 +177,7 @@ extern void esp_ble_controller_flash_only_param_config(void); #endif // CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY #if CONFIG_FREERTOS_USE_TICKLESS_IDLE extern sleep_retention_entries_config_t *r_esp_ble_mac_retention_link_get(uint8_t *size, uint8_t extra); +extern bool r_ble_lll_sleep_should_skip_light_sleep_check(void); extern void r_esp_ble_set_wakeup_overhead(uint32_t overhead); #endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */ #if CONFIG_BT_LE_LL_PEER_SCA_SET_ENABLE @@ -862,7 +864,7 @@ esp_err_t controller_sleep_init(void) #endif // CONFIG_BT_LE_SLEEP_ENABLE #ifdef CONFIG_PM_ENABLE - rc = esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "bt", &s_pm_lock); + rc = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock); if (rc != ESP_OK) { goto error; } @@ -883,6 +885,12 @@ esp_err_t controller_sleep_init(void) esp_sleep_enable_bt_wakeup(); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "Enable light sleep, the wake up source is BLE timer"); + rc = esp_pm_register_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); + if (rc != ESP_OK) { + ESP_LOGE(NIMBLE_PORT_LOG_TAG, "Should skip cb register error"); + goto error; + } + rc = esp_pm_register_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set); if (rc != ESP_OK) { goto error; @@ -899,6 +907,7 @@ esp_err_t controller_sleep_init(void) error: #endif // CONFIG_PM_ENABLE #if CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE + esp_pm_unregister_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); #if SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD sleep_modem_unregister_mac_bb_module_prepare_callback(sleep_modem_mac_bb_power_down_prepare, sleep_modem_mac_bb_power_up_prepare); @@ -920,6 +929,7 @@ error: void controller_sleep_deinit(void) { #if CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE + esp_pm_unregister_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); #if SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD sleep_modem_unregister_mac_bb_module_prepare_callback(sleep_modem_mac_bb_power_down_prepare, sleep_modem_mac_bb_power_up_prepare); From 3994d5351f1148dffad1c512b03f0abcfb90dc3b Mon Sep 17 00:00:00 2001 From: Jin Chen Date: Fri, 6 Mar 2026 10:13:21 +0800 Subject: [PATCH 4/5] fix(ble): use apb max state for bt and enable should skip on ESP32-H2 (cherry picked from commit ac8fe378a067899fc87896f8b5fc62bc6815ebb4) Co-authored-by: cjin --- components/bt/controller/esp32h2/bt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 9fb20c0f57..b266cb5279 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -45,6 +45,7 @@ #if CONFIG_FREERTOS_USE_TICKLESS_IDLE #include "esp_private/sleep_modem.h" #include "esp_private/sleep_retention.h" +#include "esp_private/pm_impl.h" #endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE #include "freertos/FreeRTOS.h" @@ -169,6 +170,7 @@ extern void esp_ble_controller_flash_only_param_config(void); #endif // CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY #if CONFIG_FREERTOS_USE_TICKLESS_IDLE extern sleep_retention_entries_config_t *r_esp_ble_mac_retention_link_get(uint8_t *size, uint8_t extra); +extern bool r_ble_lll_sleep_should_skip_light_sleep_check(void); extern void r_esp_ble_set_wakeup_overhead(uint32_t overhead); #endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */ #if CONFIG_PM_ENABLE @@ -830,7 +832,7 @@ esp_err_t controller_sleep_init(void) #endif // CONFIG_BT_LE_SLEEP_ENABLE #ifdef CONFIG_PM_ENABLE - rc = esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "bt", &s_pm_lock); + rc = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock); if (rc != ESP_OK) { goto error; } @@ -848,6 +850,12 @@ esp_err_t controller_sleep_init(void) esp_sleep_enable_bt_wakeup(); ESP_LOGW(NIMBLE_PORT_LOG_TAG, "Enable light sleep, the wake up source is BLE timer"); + rc = esp_pm_register_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); + if (rc != ESP_OK) { + ESP_LOGE(NIMBLE_PORT_LOG_TAG, "Should skip cb register error"); + goto error; + } + rc = esp_pm_register_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set); if (rc != ESP_OK) { goto error; @@ -859,6 +867,7 @@ esp_err_t controller_sleep_init(void) error: #endif // CONFIG_PM_ENABLE #if CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE + esp_pm_unregister_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); esp_sleep_disable_bt_wakeup(); esp_pm_unregister_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set); #endif /* CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE */ @@ -878,6 +887,7 @@ void controller_sleep_deinit(void) { #if CONFIG_BT_LE_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE r_ble_rtc_wake_up_state_clr(); + esp_pm_unregister_skip_light_sleep_callback(r_ble_lll_sleep_should_skip_light_sleep_check); esp_sleep_disable_bt_wakeup(); sleep_modem_ble_mac_modem_state_deinit(); esp_pm_unregister_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set); From fcaa68aca9a20f4c71b76757f0755cbf6a5880be Mon Sep 17 00:00:00 2001 From: cjin Date: Fri, 13 Mar 2026 17:18:38 +0800 Subject: [PATCH 5/5] fix(pm): expand the number of skip light sleep number --- components/esp_pm/pm_impl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_pm/pm_impl.c b/components/esp_pm/pm_impl.c index 9d48750c73..cc85ff17a7 100644 --- a/components/esp_pm/pm_impl.c +++ b/components/esp_pm/pm_impl.c @@ -133,7 +133,7 @@ static uint32_t s_mode_mask; #if CONFIG_FREERTOS_USE_TICKLESS_IDLE -#define PERIPH_SKIP_LIGHT_SLEEP_NO 2 +#define PERIPH_SKIP_LIGHT_SLEEP_NO 3 /* Indicates if light sleep should be skipped by peripherals. */ static skip_light_sleep_cb_t s_periph_skip_light_sleep_cb[PERIPH_SKIP_LIGHT_SLEEP_NO];