From ac88f5b20c302bbde66f765e71e00a33c88aba06 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Tue, 20 Jan 2026 19:55:01 +0800 Subject: [PATCH 1/2] fix(bt): Replace 32k_xtal with rtc_slow --- components/bt/controller/esp32/bt.c | 6 +++++- components/bt/controller/esp32c3/bt.c | 22 ++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/components/bt/controller/esp32/bt.c b/components/bt/controller/esp32/bt.c index 4a465e7f14d..f92a0789056 100644 --- a/components/bt/controller/esp32/bt.c +++ b/components/bt/controller/esp32/bt.c @@ -1559,7 +1559,11 @@ static esp_err_t btdm_low_power_mode_init(void) 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); + /* The enabling of the 32k crystal/oscillator depends on the RTC slow clock. + * Therefore, if the 32k crystal/oscillator is enabled, selecting BTDM_LPCLK_SEL_RTC_SLOW + * and BTDM_LPCLK_SEL_XTAL32K as the lp clock source is equivalent. + */ + 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); btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT; diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 21512343d0c..53a17e4bab1 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -1694,11 +1694,16 @@ static esp_err_t btdm_low_power_mode_init(esp_bt_controller_config_t *cfg) #if !CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP s_lp_cntl.no_light_sleep = 1; #endif + } else { + ESP_LOGI(BT_LOG_TAG, "Using external 32.768 kHz crystal/oscillator as clock source"); } } 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 not detected."); assert(0); + } else { + 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."); } } else if (s_lp_cntl.lpclk_sel == ESP_BT_SLEEP_CLOCK_MAIN_XTAL) { #if !CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP @@ -1722,18 +1727,11 @@ static esp_err_t btdm_low_power_mode_init(esp_bt_controller_config_t *cfg) assert(select_src_ret && set_div_ret); 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); - btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT; - btdm_lpcycle_us = (RTC_CLK_CAL_FRACT > 15) ? (1000000 << (RTC_CLK_CAL_FRACT - 15)) : - (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."); + } else if (s_lp_cntl.lpclk_sel == ESP_BT_SLEEP_CLOCK_RTC_SLOW || s_lp_cntl.lpclk_sel == ESP_BT_SLEEP_CLOCK_EXT_32K_XTAL) { + /* The enabling of the 32k crystal/oscillator depends on the RTC slow clock. + * Therefore, if the 32k crystal/oscillator is enabled, selecting BTDM_LPCLK_SEL_RTC_SLOW + * and BTDM_LPCLK_SEL_XTAL32K as the lp clock source is equivalent. + */ 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); From cce31f05e646b58e39f21c5bdee21359cb39f961 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Mon, 19 Jan 2026 16:55:26 +0800 Subject: [PATCH 2/2] fix(bt): Add some debug logs during A2DP sink decoding --- .../host/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c index 4a1f060fea5..f389a524816 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -577,6 +577,10 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg) p_msg->offset += (p_msg->len - 1) - sbc_frame_len; p_msg->len = sbc_frame_len + 1; } + if (count != num_sbc_frames || sbc_frame_len) { + APPL_TRACE_WARNING("Potential decoding error, cnt:%d, num:%d, len:%d. Please ignore if playback is normal.", + count, num_sbc_frames, sbc_frame_len); + } btc_a2d_data_cb_to_app((uint8_t *)a2dp_sink_local_param.pcmData, (sizeof(a2dp_sink_local_param.pcmData) - availPcmBytes)); } @@ -669,7 +673,7 @@ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt) return 0; } - if (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/ + if (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enqueue*/ return fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ); }