From 95a101d3597e53939a29dc9fd8604676253ce22c Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Tue, 18 Feb 2025 10:23:33 +0800 Subject: [PATCH 1/9] change(ble): [AUTO_MR] Update lib_esp32h2 to 1d7eebaf (cherry picked from commit 4f0e0f371afaade59ae26a1dd2e2f836ebf00276) Co-authored-by: Zhou Xiao --- components/bt/controller/lib_esp32h2/esp32h2-bt-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib index 092666b0f4..7d35fc30e8 160000 --- a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib +++ b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib @@ -1 +1 @@ -Subproject commit 092666b0f427e4226325389fc53e4b8df4a8a1fc +Subproject commit 7d35fc30e8cada9567f97378e24608bc63b080e4 From 553992e1fa08fe1c2bed21c8b985898c3a52e9d7 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Tue, 18 Feb 2025 10:23:36 +0800 Subject: [PATCH 2/9] change(ble): [AUTO_MR] Update lib_esp32c6 to 1d7eebaf (cherry picked from commit 4579e083ef46d00afb27a9fcd2d2c89868ac7a05) Co-authored-by: Zhou Xiao --- components/bt/controller/lib_esp32c6/esp32c6-bt-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib index 9cf1bbd021..4cb60b2cd1 160000 --- a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib +++ b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib @@ -1 +1 @@ -Subproject commit 9cf1bbd021d98b3da9ad8465e7fbfca8085f3a1d +Subproject commit 4cb60b2cd1c560a85effde18465b0412e715b048 From b9616fdd7f5b1a50f865db26de4acffd237430ca Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Tue, 18 Feb 2025 10:23:39 +0800 Subject: [PATCH 3/9] feat(ble): add channel assessment and enhanced connect function on ESP32-C6 (cherry picked from commit 821e587fda0bf2292842d6d39306b5dbda5943ac) Co-authored-by: zwl --- components/bt/controller/esp32c6/Kconfig.in | 45 +++++++++++++++++++ components/bt/controller/esp32c6/esp_bt_cfg.h | 40 ++++++++++++++++- .../bt/include/esp32c6/include/esp_bt.h | 21 ++++++++- 3 files changed, 103 insertions(+), 3 deletions(-) diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 893a210daf..16a520b466 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -748,3 +748,48 @@ config BT_CTRL_RUN_IN_FLASH_ONLY Move most IRAM into flash. This will increase the usage of flash and reduce ble performance. Because the code is moved to the flash, the execution speed of the code is reduced. To have a small impact on performance, you need to enable flash suspend (SPI_FLASH_AUTO_SUSPEND). + +menu "BLE disconnects when Instant Passed (0x28) occurs" + config BT_LE_CTRL_LLCP_CONN_UPDATE + bool "BLE ACL connection update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs during connection update procedure. + + config BT_LE_CTRL_LLCP_CHAN_MAP_UPDATE + bool "BLE ACL channel map update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs in channel map update procedure. + + config BT_LE_CTRL_LLCP_PHY_UPDATE + bool "BLE ACL PHY update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs in PHY update procedure. +endmenu + +config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX + int "The value of upperlimitmax during scan backoff procedure" + range 1 256 + default 32 + help + The value of upperlimitmax needs to be a power of 2. + +config BT_LE_CTRL_CHAN_ASS_EN + bool "Enable channel assessment" + default n + help + If this option is enabled, The Controller will records the communication quality + for each channel and then start a timer to check and update the channel map every 4 seconds. + +config BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX + bool "Enable aux packet when ext adv data length is zero" + default y + help + When this option is enabled, auxiliary packets will be present in the events of + 'Non-Connectable and Non-Scannable' regardless of whether the advertising length is 0. + If this option is not enabled, auxiliary packets will only be present when the advertising length is not 0. diff --git a/components/bt/controller/esp32c6/esp_bt_cfg.h b/components/bt/controller/esp32c6/esp_bt_cfg.h index 3634a40c3c..10ede46757 100644 --- a/components/bt/controller/esp32c6/esp_bt_cfg.h +++ b/components/bt/controller/esp32c6/esp_bt_cfg.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -154,6 +154,44 @@ extern "C" { #define DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS (0) #endif +#ifdef CONFIG_BT_LE_CTRL_LLCP_CONN_UPDATE +#define BT_CTRL_BLE_LLCP_CONN_UPDATE (1<<0) +#else +#define BT_CTRL_BLE_LLCP_CONN_UPDATE (0<<0) +#endif + +#ifdef CONFIG_BT_LE_CTRL_LLCP_CHAN_MAP_UPDATE +#define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (1<<1) +#else +#define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (0<<1) +#endif + +#ifdef CONFIG_BT_LE_CTRL_LLCP_PHY_UPDATE +#define BT_CTRL_BLE_LLCP_PHY_UPDATE (1<<2) +#else +#define BT_CTRL_BLE_LLCP_PHY_UPDATE (0<<2) +#endif + +#define BT_LE_CTRL_LLCP_DISC_FLAG (BT_CTRL_BLE_LLCP_CONN_UPDATE | BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE | BT_CTRL_BLE_LLCP_PHY_UPDATE) + +#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX +#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX (CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX) +#else +#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX (256) +#endif + +#if defined(CONFIG_BT_LE_CTRL_CHAN_ASS_EN) +#define DEFAULT_BT_LE_CTRL_CHAN_ASS_EN (CONFIG_BT_LE_CTRL_CHAN_ASS_EN) +#else +#define DEFAULT_BT_LE_CTRL_CHAN_ASS_EN (0) +#endif + +#if defined(CONFIG_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX) +#define DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX (CONFIG_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX) +#else +#define DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX (0) +#endif + #ifdef CONFIG_BT_LE_HCI_INTERFACE_USE_UART #define HCI_UART_EN CONFIG_BT_LE_HCI_INTERFACE_USE_UART #else diff --git a/components/bt/include/esp32c6/include/esp_bt.h b/components/bt/include/esp32c6/include/esp_bt.h index 663e025f9f..980118f668 100644 --- a/components/bt/include/esp32c6/include/esp_bt.h +++ b/components/bt/include/esp32c6/include/esp_bt.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -156,7 +156,7 @@ esp_err_t esp_ble_tx_power_set_enhanced(esp_ble_enhanced_power_type_t power_type */ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle); -#define CONFIG_VERSION 0x20241121 +#define CONFIG_VERSION 0x20250104 #define CONFIG_MAGIC 0x5A5AA5A5 /** @@ -215,6 +215,15 @@ typedef struct { uint8_t csa2_select; /*!< Select CSA#2*/ uint8_t enable_csr; /*!< Enable CSR */ uint8_t ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */ + uint8_t ble_llcp_disc_flag; /*!< Flag indicating whether the Controller disconnects after Instant Passed (0x28) error occurs. Configurable in menuconfig. + - The Controller does not disconnect after Instant Passed (0x28) by default. */ + uint16_t scan_backoff_upperlimitmax; /*!< The value of upperlimitmax is 2^n, The maximum value is 256 */ + uint8_t ble_chan_ass_en; /*!< Enable / disable BLE channel assessment. Configurable in menuconfig. + - 0 - Disable + - 1 - Enable (default) */ + uint8_t ble_data_lenth_zero_aux; /*!< Enable / disable auxiliary packets when the extended ADV data length is zero. Configurable in menuconfig. + - 0 - Disable (default) + - 1 - Enable */ uint32_t config_magic; /*!< Magic number for configuration validation */ } esp_bt_controller_config_t; @@ -266,6 +275,10 @@ typedef struct { .csa2_select = DEFAULT_BT_LE_50_FEATURE_SUPPORT, \ .enable_csr = 0, \ .ble_aa_check = DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS, \ + .ble_llcp_disc_flag = BT_LE_CTRL_LLCP_DISC_FLAG, \ + .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ + .ble_chan_ass_en = DEFAULT_BT_LE_CTRL_CHAN_ASS_EN, \ + .ble_data_lenth_zero_aux = DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX, \ .config_magic = CONFIG_MAGIC, \ } #elif CONFIG_IDF_TARGET_ESP32C61 @@ -315,6 +328,10 @@ typedef struct { .csa2_select = DEFAULT_BT_LE_50_FEATURE_SUPPORT, \ .enable_csr = 0, \ .ble_aa_check = DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS, \ + .ble_llcp_disc_flag = BT_LE_CTRL_LLCP_DISC_FLAG, \ + .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ + .ble_chan_ass_en = DEFAULT_BT_LE_CTRL_CHAN_ASS_EN, \ + .ble_data_lenth_zero_aux = DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX, \ .config_magic = CONFIG_MAGIC, \ } #endif From e6b590b243fdff6e2fa4db8b1d93c5138d3bf4b5 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Tue, 18 Feb 2025 10:23:41 +0800 Subject: [PATCH 4/9] feat(ble): add channel assessment and enhanced connect function on ESP32-H2 (cherry picked from commit 0ffac9258680588ff60cb4602048e6fa8638e3a5) Co-authored-by: zwl --- components/bt/controller/esp32h2/Kconfig.in | 47 ++++++++++++++++++- components/bt/controller/esp32h2/esp_bt_cfg.h | 40 +++++++++++++++- .../bt/include/esp32h2/include/esp_bt.h | 37 ++++++++++----- 3 files changed, 110 insertions(+), 14 deletions(-) diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index a05ecb77c4..4de022be5d 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -658,7 +658,7 @@ config BT_LE_SCAN_DUPL_CACHE_REFRESH_PERIOD again. config BT_LE_MSYS_INIT_IN_CONTROLLER - bool + bool "Msys Mbuf Init in Controller" default y config BT_LE_TX_CCA_ENABLED @@ -749,3 +749,48 @@ config BT_CTRL_RUN_IN_FLASH_ONLY Move most IRAM into flash. This will increase the usage of flash and reduce ble performance. Because the code is moved to the flash, the execution speed of the code is reduced. To have a small impact on performance, you need to enable flash suspend (SPI_FLASH_AUTO_SUSPEND). + +menu "BLE disconnects when Instant Passed (0x28) occurs" + config BT_LE_CTRL_LLCP_CONN_UPDATE + bool "BLE ACL connection update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs during connection update procedure. + + config BT_LE_CTRL_LLCP_CHAN_MAP_UPDATE + bool "BLE ACL channel map update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs in channel map update procedure. + + config BT_LE_CTRL_LLCP_PHY_UPDATE + bool "BLE ACL PHY update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs in PHY update procedure. +endmenu + +config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX + int "The value of upperlimitmax during scan backoff procedure" + range 1 256 + default 32 + help + The value of upperlimitmax needs to be a power of 2. + +config BT_LE_CTRL_CHAN_ASS_EN + bool "Enable channel assessment" + default n + help + If this option is enabled, The Controller will records the communication quality + for each channel and then start a timer to check and update the channel map every 4 seconds. + +config BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX + bool "Enable aux packet when ext adv data length is zero" + default y + help + When this option is enabled, auxiliary packets will be present in the events of + 'Non-Connectable and Non-Scannable' regardless of whether the advertising length is 0. + If this option is not enabled, auxiliary packets will only be present when the advertising length is not 0. diff --git a/components/bt/controller/esp32h2/esp_bt_cfg.h b/components/bt/controller/esp32h2/esp_bt_cfg.h index 3634a40c3c..10ede46757 100644 --- a/components/bt/controller/esp32h2/esp_bt_cfg.h +++ b/components/bt/controller/esp32h2/esp_bt_cfg.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -154,6 +154,44 @@ extern "C" { #define DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS (0) #endif +#ifdef CONFIG_BT_LE_CTRL_LLCP_CONN_UPDATE +#define BT_CTRL_BLE_LLCP_CONN_UPDATE (1<<0) +#else +#define BT_CTRL_BLE_LLCP_CONN_UPDATE (0<<0) +#endif + +#ifdef CONFIG_BT_LE_CTRL_LLCP_CHAN_MAP_UPDATE +#define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (1<<1) +#else +#define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (0<<1) +#endif + +#ifdef CONFIG_BT_LE_CTRL_LLCP_PHY_UPDATE +#define BT_CTRL_BLE_LLCP_PHY_UPDATE (1<<2) +#else +#define BT_CTRL_BLE_LLCP_PHY_UPDATE (0<<2) +#endif + +#define BT_LE_CTRL_LLCP_DISC_FLAG (BT_CTRL_BLE_LLCP_CONN_UPDATE | BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE | BT_CTRL_BLE_LLCP_PHY_UPDATE) + +#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX +#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX (CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX) +#else +#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX (256) +#endif + +#if defined(CONFIG_BT_LE_CTRL_CHAN_ASS_EN) +#define DEFAULT_BT_LE_CTRL_CHAN_ASS_EN (CONFIG_BT_LE_CTRL_CHAN_ASS_EN) +#else +#define DEFAULT_BT_LE_CTRL_CHAN_ASS_EN (0) +#endif + +#if defined(CONFIG_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX) +#define DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX (CONFIG_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX) +#else +#define DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX (0) +#endif + #ifdef CONFIG_BT_LE_HCI_INTERFACE_USE_UART #define HCI_UART_EN CONFIG_BT_LE_HCI_INTERFACE_USE_UART #else diff --git a/components/bt/include/esp32h2/include/esp_bt.h b/components/bt/include/esp32h2/include/esp_bt.h index c21a1bc854..7c460b10c9 100644 --- a/components/bt/include/esp32h2/include/esp_bt.h +++ b/components/bt/include/esp32h2/include/esp_bt.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -109,14 +109,6 @@ typedef enum { ESP_BLE_ENHANCED_PWR_TYPE_MAX, } esp_ble_enhanced_power_type_t; -/** - * @brief Address type and address value. - */ -typedef struct { - uint8_t type; /*!< Type of the Bluetooth address (public, random, etc.) */ - uint8_t val[6]; /*!< Array containing the 6-byte Bluetooth address value */ -} esp_ble_addr_t; - /** * @brief Select buffers */ @@ -125,6 +117,14 @@ typedef enum { ESP_BLE_LOG_BUF_CONTROLLER = 0x05, } esp_ble_log_buf_t; +/** + * @brief Address type and address value. + */ +typedef struct { + uint8_t type; /*!< Type of the Bluetooth address (public, random, etc.) */ + uint8_t val[6]; /*!< Array containing the 6-byte Bluetooth address value */ +} esp_ble_addr_t; + /** * @brief Set BLE TX power * Connection Tx power should only be set after connection created. @@ -161,7 +161,7 @@ esp_err_t esp_ble_tx_power_set_enhanced(esp_ble_enhanced_power_type_t power_type */ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle); -#define CONFIG_VERSION 0x20241121 +#define CONFIG_VERSION 0x20250104 #define CONFIG_MAGIC 0x5A5AA5A5 /** @@ -217,7 +217,16 @@ typedef struct { uint8_t csa2_select; /*!< Select CSA#2*/ uint8_t enable_csr; /*!< Enable CSR */ uint8_t ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */ - uint32_t config_magic; /*!< Configuration magic value */ + uint8_t ble_llcp_disc_flag; /*!< Flag indicating whether the Controller disconnects after Instant Passed (0x28) error occurs. Configurable in menuconfig. + - The Controller does not disconnect after Instant Passed (0x28) by default. */ + uint16_t scan_backoff_upperlimitmax; /*!< The value of upperlimitmax is 2^n, The maximum value is 256 */ + uint8_t ble_chan_ass_en; /*!< Enable / disable BLE channel assessment. Configurable in menuconfig. + - 0 - Disable + - 1 - Enable (default) */ + uint8_t ble_data_lenth_zero_aux; /*!< Enable / disable auxiliary packets when the extended ADV data length is zero. Configurable in menuconfig. + - 0 - Disable (default) + - 1 - Enable */ + uint32_t config_magic; /*!< Configuration magic value */ } esp_bt_controller_config_t; @@ -263,10 +272,14 @@ typedef struct { .main_xtal_freq = CONFIG_XTAL_FREQ, \ .cpu_freq_mhz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ, \ .ignore_wl_for_direct_adv = 0, \ - .enable_pcl = 0, \ + .enable_pcl = DEFAULT_BT_LE_POWER_CONTROL_ENABLED, \ .csa2_select = DEFAULT_BT_LE_50_FEATURE_SUPPORT, \ .enable_csr = 0, \ .ble_aa_check = DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS, \ + .ble_llcp_disc_flag = BT_LE_CTRL_LLCP_DISC_FLAG, \ + .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ + .ble_chan_ass_en = DEFAULT_BT_LE_CTRL_CHAN_ASS_EN, \ + .ble_data_lenth_zero_aux = DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX, \ .config_magic = CONFIG_MAGIC, \ } From de1cbf7f2f12b87ed6a10eb03c4f91d6dcbbaafd Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Tue, 18 Feb 2025 10:23:44 +0800 Subject: [PATCH 5/9] feat(ble): support enhanced controller log capabilities on ESP32-C6 and ESP32-H2 (cherry picked from commit f598976c6bfadec961414f8713884cb2333256cb) Co-authored-by: zwl --- components/bt/CMakeLists.txt | 3 +++ components/bt/controller/esp32c6/Kconfig.in | 30 +++++++++++++++++++++ components/bt/controller/esp32c6/bt.c | 24 ++++++++++++++++- components/bt/controller/esp32h2/Kconfig.in | 30 +++++++++++++++++++++ components/bt/controller/esp32h2/bt.c | 25 +++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 537583e0f0..519cf42cb8 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -889,6 +889,9 @@ if(CONFIG_BT_ENABLED) target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app) endif() elseif(CONFIG_BT_CONTROLLER_ENABLED) + if(CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=esp_panic_handler") + endif() if(CONFIG_IDF_TARGET_ESP32C6) add_prebuilt_library(libble_app "${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c6/esp32c6-bt-lib/esp32c6/libble_app.a") diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 16a520b466..20f8459c6d 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -424,6 +424,36 @@ config BT_LE_LOG_HCI_BUF_SIZE help Configure the size of the BLE HCI LOG buffer. +config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE + bool "Enable wrap panic handler" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. + +config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + bool "Enable esp_task_wdt_isr_user_handler implementation" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. + +config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL + int "The output level of controller log" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 5 + default 1 + help + The output level of controller log. + +config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH + hex "The switch of module log output" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 0xFFFFFFFF + default 0xFFFFFFFF + help + The switch of module log output, this is an unsigned 32-bit hexadecimal value. + config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" range 1 5 diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index a4aadbfd9d..54b09ca762 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -120,6 +120,8 @@ extern int r_ble_log_deinit_async(void); extern void r_ble_log_async_select_dump_buffers(uint8_t buffers); extern void r_ble_log_async_output_dump_all(bool output); extern void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms); +extern int r_ble_log_ctrl_level_and_mod(uint8_t log_level, uint32_t mod_switch); +extern int r_ble_ctrl_mod_type(uint16_t mod, uint32_t mod_type_switch); #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int r_ble_controller_deinit(void); extern int r_ble_controller_enable(uint8_t mode); @@ -269,10 +271,14 @@ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) } ret = r_ble_log_init_async(bt_controller_log_interface, task_create, buffers, (uint32_t *)log_bufs_size); + if (ret != ESP_OK) { + return ret; + } + + ret = r_ble_log_ctrl_level_and_mod(CONFIG_BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL, CONFIG_BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH); if (ret == ESP_OK) { log_is_inited = true; } - return ret; } @@ -406,6 +412,22 @@ void esp_bt_read_ctrl_log_from_flash(bool output) assert(err == ESP_OK); } #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + +#if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE +void esp_task_wdt_isr_user_handler(void) +{ + esp_ble_controller_log_dump_all(true); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + +#if CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE +void __real_esp_panic_handler(void *info); +void __wrap_esp_panic_handler (void *info) +{ + esp_ble_controller_log_dump_all(true); + __real_esp_panic_handler(info); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* This variable tells if BLE is running */ diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index 4de022be5d..f1679bc654 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -415,6 +415,36 @@ config BT_LE_LOG_HCI_BUF_SIZE help Configure the size of the BLE HCI LOG buffer. +config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE + bool "Enable wrap panic handler" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. + +config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + bool "Enable esp_task_wdt_isr_user_handler implementation" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. + +config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL + int "The output level of controller log" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 5 + default 1 + help + The output level of controller log. + +config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH + hex "The switch of module log output" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 0xFFFFFFFF + default 0xFFFFFFFF + help + The switch of module log output, this is an unsigned 32-bit hexadecimal value. + config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" range 1 5 diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 9aea7bf585..4599263193 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -115,6 +115,8 @@ extern int r_ble_log_deinit_async(void); extern void r_ble_log_async_select_dump_buffers(uint8_t buffers); extern void r_ble_log_async_output_dump_all(bool output); extern void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms); +extern int r_ble_log_ctrl_level_and_mod(uint8_t log_level, uint32_t mod_switch); +extern int r_ble_ctrl_mod_type(uint16_t mod, uint32_t mod_type_switch); #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int r_ble_controller_deinit(void); extern int r_ble_controller_enable(uint8_t mode); @@ -267,6 +269,11 @@ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) } ret = r_ble_log_init_async(bt_controller_log_interface, task_create, buffers, (uint32_t *)log_bufs_size); + if (ret != ESP_OK) { + return ret; + } + + ret = r_ble_log_ctrl_level_and_mod(CONFIG_BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL, CONFIG_BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH); if (ret == ESP_OK) { log_is_inited = true; } @@ -403,6 +410,22 @@ void esp_bt_read_ctrl_log_from_flash(bool output) assert(err == ESP_OK); } #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + +#if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE +void esp_task_wdt_isr_user_handler(void) +{ + esp_ble_controller_log_dump_all(true); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + +#if CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE +void __real_esp_panic_handler(void *info); +void __wrap_esp_panic_handler (void *info) +{ + esp_ble_controller_log_dump_all(true); + __real_esp_panic_handler(info); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* This variable tells if BLE is running */ @@ -937,6 +960,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) ESP_LOGW(NIMBLE_PORT_LOG_TAG, "controller_sleep_init failed %d", ret); goto free_controller; } + ESP_ERROR_CHECK(esp_read_mac((uint8_t *)mac, ESP_MAC_BT)); ESP_LOGI(NIMBLE_PORT_LOG_TAG, "Bluetooth MAC: %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -1047,6 +1071,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) #if CONFIG_SW_COEXIST_ENABLE coex_enable(); #endif // CONFIG_SW_COEXIST_ENABLE + #if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY r_ble_ll_scan_start_time_init_compensation(500); r_priv_sdk_config_insert_proc_time_set(500); From 9912a9c029b953e3e2f66c81f1b6632853cd32dd Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Tue, 18 Feb 2025 10:23:47 +0800 Subject: [PATCH 6/9] feat(ble): support enhanced controller log capabilities on ESP32-C2 (cherry picked from commit bbcb4a2e1f9c9bc13d59364d42c70bdf02ae14ef) Co-authored-by: zwl --- components/bt/controller/esp32c2/Kconfig.in | 13 +++++++++++++ components/bt/controller/esp32c2/bt.c | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/components/bt/controller/esp32c2/Kconfig.in b/components/bt/controller/esp32c2/Kconfig.in index d0f9407b2e..df15b6f314 100644 --- a/components/bt/controller/esp32c2/Kconfig.in +++ b/components/bt/controller/esp32c2/Kconfig.in @@ -390,6 +390,19 @@ config BT_LE_LOG_HCI_BUF_SIZE help Configure the size of the BLE HCI LOG buffer. +config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE + bool "Enable wrap panic handler" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. + +config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + bool "Enable esp_task_wdt_isr_user_handler implementation" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" range 1 5 diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index 7ae9ca30cd..991b5889f2 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -456,6 +456,21 @@ void esp_ble_controller_log_dump_all(bool output) portEXIT_CRITICAL_SAFE(&spinlock); } } +#if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE +void esp_task_wdt_isr_user_handler(void) +{ + esp_ble_controller_log_dump_all(true); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + +#if CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE +void __real_esp_panic_handler(void *info); +void __wrap_esp_panic_handler (void *info) +{ + esp_ble_controller_log_dump_all(true); + __real_esp_panic_handler(info); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* This variable tells if BLE is running */ From 8eb5c153760ce29e9ac6749d6f1ea98ba123fd66 Mon Sep 17 00:00:00 2001 From: zwl Date: Tue, 18 Feb 2025 10:32:09 +0800 Subject: [PATCH 7/9] change(ble): [AUTO_MR] Update lib_esp32c5 to 1d7eebaf --- components/bt/controller/lib_esp32c5/esp32c5-bt-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/lib_esp32c5/esp32c5-bt-lib b/components/bt/controller/lib_esp32c5/esp32c5-bt-lib index ea98e86d72..5fedf4bb0e 160000 --- a/components/bt/controller/lib_esp32c5/esp32c5-bt-lib +++ b/components/bt/controller/lib_esp32c5/esp32c5-bt-lib @@ -1 +1 @@ -Subproject commit ea98e86d725558a277e39bd3f5c1b492d000b659 +Subproject commit 5fedf4bb0e11e11d54d5f712ec17b72cc2c95fdc From 3c6236df502902ff1debd709f3aa4421049ea3c3 Mon Sep 17 00:00:00 2001 From: zwl Date: Tue, 11 Feb 2025 16:28:16 +0800 Subject: [PATCH 8/9] feat(ble): add channel assessment and enhanced connect function on ESP32-C5 --- components/bt/controller/esp32c5/Kconfig.in | 46 +++++++++++++++++++ components/bt/controller/esp32c5/esp_bt_cfg.h | 38 +++++++++++++++ .../bt/include/esp32c5/include/esp_bt.h | 19 +++++++- 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/components/bt/controller/esp32c5/Kconfig.in b/components/bt/controller/esp32c5/Kconfig.in index 677016becd..1e6fab1fef 100644 --- a/components/bt/controller/esp32c5/Kconfig.in +++ b/components/bt/controller/esp32c5/Kconfig.in @@ -495,6 +495,7 @@ config BT_LE_USE_ESP_TIMER help Set this option to use Esp Timer which has higher priority timer instead of FreeRTOS timer + config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP bool "BLE adv report flow control supported" default y @@ -679,3 +680,48 @@ config BT_CTRL_RUN_IN_FLASH_ONLY Move most IRAM into flash. This will increase the usage of flash and reduce ble performance. Because the code is moved to the flash, the execution speed of the code is reduced. To have a small impact on performance, you need to enable flash suspend (SPI_FLASH_AUTO_SUSPEND). + +menu "BLE disconnects when Instant Passed (0x28) occurs" + config BT_LE_CTRL_LLCP_CONN_UPDATE + bool "BLE ACL connection update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs during connection update procedure. + + config BT_LE_CTRL_LLCP_CHAN_MAP_UPDATE + bool "BLE ACL channel map update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs in channel map update procedure. + + config BT_LE_CTRL_LLCP_PHY_UPDATE + bool "BLE ACL PHY update procedure" + default n + help + If this option is enabled, Controller will terminate the connection + when Instant Passed (0x28) error occurs in PHY update procedure. +endmenu + +config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX + int "The value of upperlimitmax during scan backoff procedure" + range 1 256 + default 32 + help + The value of upperlimitmax needs to be a power of 2. + +config BT_LE_CTRL_CHAN_ASS_EN + bool "Enable channel assessment" + default n + help + If this option is enabled, The Controller will records the communication quality + for each channel and then start a timer to check and update the channel map every 4 seconds. + +config BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX + bool "Enable aux packet when ext adv data length is zero" + default y + help + When this option is enabled, auxiliary packets will be present in the events of + 'Non-Connectable and Non-Scannable' regardless of whether the advertising length is 0. + If this option is not enabled, auxiliary packets will only be present when the advertising length is not 0. diff --git a/components/bt/controller/esp32c5/esp_bt_cfg.h b/components/bt/controller/esp32c5/esp_bt_cfg.h index cac3edc045..10ede46757 100644 --- a/components/bt/controller/esp32c5/esp_bt_cfg.h +++ b/components/bt/controller/esp32c5/esp_bt_cfg.h @@ -154,6 +154,44 @@ extern "C" { #define DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS (0) #endif +#ifdef CONFIG_BT_LE_CTRL_LLCP_CONN_UPDATE +#define BT_CTRL_BLE_LLCP_CONN_UPDATE (1<<0) +#else +#define BT_CTRL_BLE_LLCP_CONN_UPDATE (0<<0) +#endif + +#ifdef CONFIG_BT_LE_CTRL_LLCP_CHAN_MAP_UPDATE +#define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (1<<1) +#else +#define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (0<<1) +#endif + +#ifdef CONFIG_BT_LE_CTRL_LLCP_PHY_UPDATE +#define BT_CTRL_BLE_LLCP_PHY_UPDATE (1<<2) +#else +#define BT_CTRL_BLE_LLCP_PHY_UPDATE (0<<2) +#endif + +#define BT_LE_CTRL_LLCP_DISC_FLAG (BT_CTRL_BLE_LLCP_CONN_UPDATE | BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE | BT_CTRL_BLE_LLCP_PHY_UPDATE) + +#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX +#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX (CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX) +#else +#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX (256) +#endif + +#if defined(CONFIG_BT_LE_CTRL_CHAN_ASS_EN) +#define DEFAULT_BT_LE_CTRL_CHAN_ASS_EN (CONFIG_BT_LE_CTRL_CHAN_ASS_EN) +#else +#define DEFAULT_BT_LE_CTRL_CHAN_ASS_EN (0) +#endif + +#if defined(CONFIG_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX) +#define DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX (CONFIG_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX) +#else +#define DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX (0) +#endif + #ifdef CONFIG_BT_LE_HCI_INTERFACE_USE_UART #define HCI_UART_EN CONFIG_BT_LE_HCI_INTERFACE_USE_UART #else diff --git a/components/bt/include/esp32c5/include/esp_bt.h b/components/bt/include/esp32c5/include/esp_bt.h index ae97d9c8fb..aba89d1540 100644 --- a/components/bt/include/esp32c5/include/esp_bt.h +++ b/components/bt/include/esp32c5/include/esp_bt.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -159,7 +159,7 @@ esp_err_t esp_ble_tx_power_set_enhanced(esp_ble_enhanced_power_type_t power_type */ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle); -#define CONFIG_VERSION 0x20241121 +#define CONFIG_VERSION 0x20250104 #define CONFIG_MAGIC 0x5A5AA5A5 /** @@ -215,6 +215,15 @@ typedef struct { uint8_t csa2_select; /*!< Select CSA#2*/ uint8_t enable_csr; /*!< Enable CSR */ uint8_t ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */ + uint8_t ble_llcp_disc_flag; /*!< Flag indicating whether the Controller disconnects after Instant Passed (0x28) error occurs. Configurable in menuconfig. + - The Controller does not disconnect after Instant Passed (0x28) by default. */ + uint16_t scan_backoff_upperlimitmax; /*!< The value of upperlimitmax is 2^n, The maximum value is 256 */ + uint8_t ble_chan_ass_en; /*!< Enable / disable BLE channel assessment. Configurable in menuconfig. + - 0 - Disable + - 1 - Enable (default) */ + uint8_t ble_data_lenth_zero_aux; /*!< Enable / disable auxiliary packets when the extended ADV data length is zero. Configurable in menuconfig. + - 0 - Disable (default) + - 1 - Enable */ uint32_t config_magic; /*!< Magic number for configuration validation */ } esp_bt_controller_config_t; @@ -262,6 +271,12 @@ typedef struct { .ignore_wl_for_direct_adv = 0, \ .enable_pcl = DEFAULT_BT_LE_POWER_CONTROL_ENABLED, \ .csa2_select = DEFAULT_BT_LE_50_FEATURE_SUPPORT, \ + .enable_csr = 0, \ + .ble_aa_check = DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS, \ + .ble_llcp_disc_flag = BT_LE_CTRL_LLCP_DISC_FLAG, \ + .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ + .ble_chan_ass_en = DEFAULT_BT_LE_CTRL_CHAN_ASS_EN, \ + .ble_data_lenth_zero_aux = DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX, \ .config_magic = CONFIG_MAGIC, \ } From 8e5aee2261eea9ca8f317a239d0425cefef211f1 Mon Sep 17 00:00:00 2001 From: zwl Date: Tue, 11 Feb 2025 19:43:43 +0800 Subject: [PATCH 9/9] feat(ble): support enhanced controller log capabilities on ESP32-C5 --- components/bt/controller/esp32c5/Kconfig.in | 30 +++++++++++++++++++++ components/bt/controller/esp32c5/bt.c | 24 ++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/components/bt/controller/esp32c5/Kconfig.in b/components/bt/controller/esp32c5/Kconfig.in index 1e6fab1fef..0d2c78f1bf 100644 --- a/components/bt/controller/esp32c5/Kconfig.in +++ b/components/bt/controller/esp32c5/Kconfig.in @@ -349,6 +349,36 @@ config BT_LE_LOG_HCI_BUF_SIZE help Configure the size of the BLE HCI LOG buffer. +config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE + bool "Enable wrap panic handler" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. + +config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + bool "Enable esp_task_wdt_isr_user_handler implementation" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. + +config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL + int "The output level of controller log" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 5 + default 1 + help + The output level of controller log. + +config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH + hex "The switch of module log output" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 0xFFFFFFFF + default 0xFFFFFFFF + help + The switch of module log output, this is an unsigned 32-bit hexadecimal value. + config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" range 1 5 diff --git a/components/bt/controller/esp32c5/bt.c b/components/bt/controller/esp32c5/bt.c index 8466cd5bf0..d3a92bc81a 100644 --- a/components/bt/controller/esp32c5/bt.c +++ b/components/bt/controller/esp32c5/bt.c @@ -110,6 +110,8 @@ extern int r_ble_log_deinit_async(void); extern void r_ble_log_async_select_dump_buffers(uint8_t buffers); extern void r_ble_log_async_output_dump_all(bool output); extern void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms); +extern int r_ble_log_ctrl_level_and_mod(uint8_t log_level, uint32_t mod_switch); +extern int r_ble_ctrl_mod_type(uint16_t mod, uint32_t mod_type_switch); #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int r_ble_controller_deinit(void); extern int r_ble_controller_enable(uint8_t mode); @@ -249,10 +251,14 @@ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) } ret = r_ble_log_init_async(bt_controller_log_interface, task_create, buffers, (uint32_t *)log_bufs_size); + if (ret != ESP_OK) { + return ret; + } + + ret = r_ble_log_ctrl_level_and_mod(CONFIG_BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL, CONFIG_BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH); if (ret == ESP_OK) { log_is_inited = true; } - return ret; } @@ -383,6 +389,22 @@ void esp_bt_read_ctrl_log_from_flash(bool output) assert(err == ESP_OK); } #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + +#if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE +void esp_task_wdt_isr_user_handler(void) +{ + esp_ble_controller_log_dump_all(true); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + +#if CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE +void __real_esp_panic_handler(void *info); +void __wrap_esp_panic_handler (void *info) +{ + esp_ble_controller_log_dump_all(true); + __real_esp_panic_handler(info); +} +#endif // CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* This variable tells if BLE is running */