From 4df0e15513a46abcbee52093d6b7f018d3da9445 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Tue, 1 Jul 2025 19:17:20 +0800 Subject: [PATCH] fix(ble): keep the log of the bluetooth sleep clock source consistent --- components/bt/controller/esp32/bt.c | 2 ++ components/bt/controller/esp32c3/Kconfig.in | 4 ++-- components/bt/controller/esp32c3/bt.c | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/components/bt/controller/esp32/bt.c b/components/bt/controller/esp32/bt.c index 82be12c087..966275dc38 100644 --- a/components/bt/controller/esp32/bt.c +++ b/components/bt/controller/esp32/bt.c @@ -1536,12 +1536,14 @@ static esp_err_t btdm_low_power_mode_init(void) bool select_src_ret __attribute__((unused)); bool set_div_ret __attribute__((unused)); if (btdm_lpclk_sel == ESP_BT_SLEEP_CLOCK_MAIN_XTAL) { + ESP_LOGI(BTDM_LOG_TAG, "Using main XTAL as clock source"); select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL); set_div_ret = btdm_lpclk_set_div(esp_clk_xtal_freq() * 2 / MHZ - 1); assert(select_src_ret && set_div_ret); btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT; btdm_lpcycle_us = 2 << (btdm_lpcycle_us_frac); } else { // btdm_lpclk_sel == BTDM_LPCLK_SEL_XTAL32K + ESP_LOGI(BTDM_LOG_TAG, "Using external 32.768 kHz crystal/oscillator as clock source"); select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL32K); set_div_ret = btdm_lpclk_set_div(0); assert(select_src_ret && set_div_ret); diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index 7265a164de..6af7d6a6f2 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -414,10 +414,10 @@ menu "MODEM SLEEP Options" modem sleep to be used with both DFS and light sleep. config BT_CTRL_LPCLK_SEL_RTC_SLOW - bool "Internal 150kHz RC oscillator" + bool "Internal 136kHz RC oscillator" depends on RTC_CLK_SRC_INT_RC help - Internal 150kHz RC oscillator. The accuracy of this clock is a lot larger than 500ppm which is required + Internal 136kHz RC oscillator. The accuracy of this clock is a lot larger than 500ppm which is required in Bluetooth communication, so don't select this option in scenarios such as BLE connection state. endchoice diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 98a220adca..7061954de9 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -1648,15 +1648,11 @@ static esp_err_t btdm_low_power_mode_init(esp_bt_controller_config_t *cfg) #endif } } else if (s_lp_cntl.lpclk_sel == ESP_BT_SLEEP_CLOCK_RTC_SLOW) { // Internal 136kHz RC oscillator - if (rtc_clk_slow_src_get() == SOC_RTC_SLOW_CLK_SRC_RC_SLOW) { - ESP_LOGW(BT_LOG_TAG, "Internal 136kHz RC oscillator. The accuracy of this clock is a lot larger than 500ppm which is " - "required in Bluetooth communication, so don't select this option in scenarios such as BLE connection state."); - } else { + if (rtc_clk_slow_src_get() != SOC_RTC_SLOW_CLK_SRC_RC_SLOW) { ESP_LOGW(BT_LOG_TAG, "Internal 136kHz RC oscillator not detected."); assert(0); } } else if (s_lp_cntl.lpclk_sel == ESP_BT_SLEEP_CLOCK_MAIN_XTAL) { - ESP_LOGI(BT_LOG_TAG, "Bluetooth will use main XTAL as Bluetooth sleep clock."); #if !CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP s_lp_cntl.no_light_sleep = 1; #endif @@ -1668,6 +1664,7 @@ static esp_err_t btdm_low_power_mode_init(esp_bt_controller_config_t *cfg) bool select_src_ret __attribute__((unused)); bool set_div_ret __attribute__((unused)); if (s_lp_cntl.lpclk_sel == ESP_BT_SLEEP_CLOCK_MAIN_XTAL) { + ESP_LOGI(BT_LOG_TAG, "Using main XTAL as clock source"); #ifdef CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_ON)); s_lp_cntl.main_xtal_pu = 1; @@ -1678,6 +1675,7 @@ static esp_err_t btdm_low_power_mode_init(esp_bt_controller_config_t *cfg) btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT; btdm_lpcycle_us = 1 << (btdm_lpcycle_us_frac); } else if (s_lp_cntl.lpclk_sel == ESP_BT_SLEEP_CLOCK_EXT_32K_XTAL) { + ESP_LOGI(BT_LOG_TAG, "Using external 32.768 kHz crystal/oscillator as clock source"); select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL32K); set_div_ret = btdm_lpclk_set_div(0); assert(select_src_ret && set_div_ret); @@ -1686,6 +1684,8 @@ static esp_err_t btdm_low_power_mode_init(esp_bt_controller_config_t *cfg) (1000000 >> (15 - RTC_CLK_CAL_FRACT)); assert(btdm_lpcycle_us != 0); } else if (s_lp_cntl.lpclk_sel == ESP_BT_SLEEP_CLOCK_RTC_SLOW) { + ESP_LOGW(BT_LOG_TAG, "Using 136 kHz RC as clock source. The accuracy of this clock is a lot larger than 500ppm which is " + "required in Bluetooth communication, so don't select this option in scenarios such as BLE connection state."); select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW); set_div_ret = btdm_lpclk_set_div(0); assert(select_src_ret && set_div_ret);