From bc5b61b56c75ae62993ef4714c003a9b639349e7 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Mon, 15 Sep 2025 14:55:51 +0800 Subject: [PATCH 1/8] fix(ble): fixed ble log v2 configuration issues --- components/bt/common/ble_log/Kconfig.in | 28 +++++++++++++++++-- .../src/internal_include/ble_log_lbm.h | 1 - .../src/internal_include/ble_log_util.h | 13 ++------- .../ble_log/src/prph/ble_log_prph_uart_dma.c | 4 +-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/components/bt/common/ble_log/Kconfig.in b/components/bt/common/ble_log/Kconfig.in index bf31e5259b..fe1a1a58ec 100644 --- a/components/bt/common/ble_log/Kconfig.in +++ b/components/bt/common/ble_log/Kconfig.in @@ -33,12 +33,32 @@ if BLE_LOG_ENABLED try to use the LBM with spin lock protection. So the more LBMs with atomic lock protection are created, the more ISRs can nest. + config BLE_LOG_IS_ESP_CONTROLLER + bool "Current BLE Controller is ESP BLE Controller" + depends on BT_CONTROLLER_ENABLED + depends on SOC_ESP_NIMBLE_CONTROLLER + default y + select BT_LE_CONTROLLER_LOG_ENABLED + select BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + select BLE_LOG_LL_ENABLED + help + Current BLE Controller is ESP BLE Controller + + config BLE_LOG_IS_ESP_LEGACY_CONTROLLER + bool "Current BLE Controller is ESP BLE Legacy Controller" + depends on BT_CONTROLLER_ENABLED + depends on !SOC_ESP_NIMBLE_CONTROLLER + depends on BT_CTRL_RUN_IN_FLASH_ONLY + default y + select BT_CTRL_LE_LOG_EN + select BLE_LOG_LL_ENABLED + help + Current BLE Controller is ESP BLE Legacy Controller + config BLE_LOG_LL_ENABLED bool "Enable BLE Log for Link Layer" depends on BT_CONTROLLER_ENABLED - default y - select BT_LE_CONTROLLER_LOG_ENABLED - select BT_LE_CONTROLLER_LOG_MODE_BLE_LOG + default n help Enable BLE Log for Link Layer @@ -96,11 +116,13 @@ if BLE_LOG_ENABLED config BLE_LOG_PRPH_SPI_MASTER_DMA bool "Utilize SPI master DMA driver as transport" + depends on SOC_GPSPI_SUPPORTED help Utilize SPI master DMA driver as transport config BLE_LOG_PRPH_UART_DMA bool "Utilize UART DMA driver as transport" + depends on SOC_UHCI_SUPPORTED help Utilize UART DMA driver as transport endchoice diff --git a/components/bt/common/ble_log/src/internal_include/ble_log_lbm.h b/components/bt/common/ble_log/src/internal_include/ble_log_lbm.h index 63d0172dbd..c3d79a6714 100644 --- a/components/bt/common/ble_log/src/internal_include/ble_log_lbm.h +++ b/components/bt/common/ble_log/src/internal_include/ble_log_lbm.h @@ -17,7 +17,6 @@ #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" -#include "freertos/portmacro.h" /* ------------------------- */ /* Log Frame Defines */ diff --git a/components/bt/common/ble_log/src/internal_include/ble_log_util.h b/components/bt/common/ble_log/src/internal_include/ble_log_util.h index 04c468ab0a..d0e7c460f0 100644 --- a/components/bt/common/ble_log/src/internal_include/ble_log_util.h +++ b/components/bt/common/ble_log/src/internal_include/ble_log_util.h @@ -17,11 +17,11 @@ #include #include "esp_bit_defs.h" +#include "freertos/FreeRTOS.h" #ifndef UNIT_TEST -#include "freertos/portmacro.h" #include "esp_heap_caps.h" -#include "esp_rom_serial_output.h" +#include "esp_rom_uart.h" #endif /* !UNIT_TEST */ /* MACRO */ @@ -47,18 +47,9 @@ #define BLE_LOG_MEMSET(ptr, value, len) memset(ptr, value, len) /* Critical section wrapper */ -#ifndef CONFIG_BLE_LOG_LL_ENABLED extern portMUX_TYPE ble_log_spin_lock; #define BLE_LOG_ENTER_CRITICAL() portENTER_CRITICAL_SAFE(&ble_log_spin_lock); #define BLE_LOG_EXIT_CRITICAL() portEXIT_CRITICAL_SAFE(&ble_log_spin_lock); -#else /* CONFIG_BLE_LOG_LL_ENABLED */ -/* Note - * It's mandatory to use the same spin lock with Link Layer in multi-core system */ -extern uint32_t npl_freertos_hw_enter_critical(void); -extern void npl_freertos_hw_exit_critical(uint32_t ctx); -#define BLE_LOG_ENTER_CRITICAL() npl_freertos_hw_enter_critical() -#define BLE_LOG_EXIT_CRITICAL() npl_freertos_hw_exit_critical(0) -#endif /* !CONFIG_BLE_LOG_LL_ENABLED */ #define BLE_LOG_ACQUIRE_SPIN_LOCK(spin_lock) portENTER_CRITICAL_SAFE(spin_lock) #define BLE_LOG_RELEASE_SPIN_LOCK(spin_lock) portEXIT_CRITICAL_SAFE(spin_lock) diff --git a/components/bt/common/ble_log/src/prph/ble_log_prph_uart_dma.c b/components/bt/common/ble_log/src/prph/ble_log_prph_uart_dma.c index c366c9b7ec..ea58b000e2 100644 --- a/components/bt/common/ble_log/src/prph/ble_log_prph_uart_dma.c +++ b/components/bt/common/ble_log/src/prph/ble_log_prph_uart_dma.c @@ -23,7 +23,7 @@ /* MACRO */ #define BLE_LOG_UART_MAX_TRANSFER_SIZE (10240) -#define BLE_LOG_UART_RX_BUF_SIZE (32) +#define BLE_LOG_UART_RX_BUF_SIZE (256) #define BLE_LOG_UART_DMA_BURST_SIZE (32) #if BLE_LOG_PRPH_UART_DMA_REDIR #define BLE_LOG_UART_REDIR_BUF_SIZE (512) @@ -95,8 +95,6 @@ bool ble_log_prph_init(size_t trans_cnt) .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS, - .rx_flow_ctrl_thresh = 122, }; if ((uart_param_config(CONFIG_BLE_LOG_PRPH_UART_DMA_PORT, &uart_config) != ESP_OK) || (uart_set_pin(CONFIG_BLE_LOG_PRPH_UART_DMA_PORT, From 67a511abc6eccead12bcd6993988fba534a2270c Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Mon, 15 Sep 2025 11:42:03 +0800 Subject: [PATCH 2/8] feat(ble): supported ble log v2 for ESP32-C6 --- components/bt/controller/esp32c6/Kconfig.in | 143 +++++++++++--------- components/bt/controller/esp32c6/bt.c | 54 +++++++- 2 files changed, 129 insertions(+), 68 deletions(-) diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 81a5b839f1..29072a1432 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -338,84 +338,93 @@ menu "Controller debug features" help Enable controller log - config BT_LE_CONTROLLER_LOG_CTRL_ENABLED - bool "enable controller log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED + config BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + bool "Utilize BLE Log v2 for controller log" + depends on BLE_LOG_ENABLED default y help - Enable controller log module + Utilize BLE Log v2 for controller log - config BT_LE_CONTROLLER_LOG_HCI_ENABLED - bool "enable HCI log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help - Enable hci log module + if !BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + config BT_LE_CONTROLLER_LOG_CTRL_ENABLED + bool "enable controller log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Enable controller log module - config BT_LE_CONTROLLER_LOG_DUMP_ONLY - bool "Controller log dump mode only" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help - Only operate in dump mode + config BT_LE_CONTROLLER_LOG_HCI_ENABLED + bool "enable HCI log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Enable hci log module - config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - bool "Output ble controller logs to SPI bus (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - select BT_BLE_LOG_SPI_OUT_ENABLED - default n - help - Output ble controller logs to SPI bus + config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Only operate in dump mode - config BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED - bool "Output ble controller logs via UART DMA (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on !BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - select BT_BLE_LOG_UHCI_OUT_ENABLED - default y - help - Output ble controller logs via UART DMA + config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + bool "Output ble controller logs to SPI bus (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + select BT_BLE_LOG_SPI_OUT_ENABLED + default n + help + Output ble controller logs to SPI bus - config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - bool "Store ble controller logs to flash(Experimental)" - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Store ble controller logs to flash memory. + config BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED + bool "Output ble controller logs via UART DMA (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on !BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + select BT_BLE_LOG_UHCI_OUT_ENABLED + default y + help + Output ble controller logs via UART DMA - config BT_LE_CONTROLLER_LOG_PARTITION_SIZE - int "size of ble controller log partition(Multiples of 4K)" - depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - default 65536 - help - The size of ble controller log partition shall be a multiples of 4K. - The name of log partition shall be "bt_ctrl_log". - The partition type shall be ESP_PARTITION_TYPE_DATA. - The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. + config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + bool "Store ble controller logs to flash(Experimental)" + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Store ble controller logs to flash memory. - config BT_LE_LOG_CTRL_BUF1_SIZE - int "size of the first BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help - Configure the size of the first BLE controller LOG buffer. + config BT_LE_CONTROLLER_LOG_PARTITION_SIZE + int "size of ble controller log partition(Multiples of 4K)" + depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + default 65536 + help + The size of ble controller log partition shall be a multiples of 4K. + The name of log partition shall be "bt_ctrl_log". + The partition type shall be ESP_PARTITION_TYPE_DATA. + The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. - config BT_LE_LOG_CTRL_BUF2_SIZE - int "size of the second BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 1024 - help - Configure the size of the second BLE controller LOG buffer. + config BT_LE_LOG_CTRL_BUF1_SIZE + int "size of the first BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help + Configure the size of the first BLE controller LOG buffer. - config BT_LE_LOG_HCI_BUF_SIZE - int "size of the BLE HCI LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help - Configure the size of the BLE HCI LOG buffer. + config BT_LE_LOG_CTRL_BUF2_SIZE + int "size of the second BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 1024 + help + Configure the size of the second BLE controller LOG buffer. + + config BT_LE_LOG_HCI_BUF_SIZE + int "size of the BLE HCI LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help + Configure the size of the BLE HCI LOG buffer. + endif config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE bool "Enable wrap panic handler" diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index f6cfa91854..f2c4790473 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -60,6 +60,9 @@ #include "soc/rtc.h" #include "modem/modem_syscon_struct.h" +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +#include "ble_log.h" +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #include "ble_log/ble_log_spi_out.h" #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED @@ -67,6 +70,7 @@ #if CONFIG_BT_BLE_LOG_UHCI_OUT_ENABLED #include "ble_log/ble_log_uhci_out.h" #endif // CONFIG_BT_BLE_LOG_UHCI_OUT_ENABLED +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ /* Macro definition ************************************************************************ @@ -208,12 +212,14 @@ static int esp_ecc_gen_key_pair(uint8_t *pub, uint8_t *priv); static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y, const uint8_t *our_priv_key, uint8_t *out_dhkey); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +#if !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag); #endif // !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE +#endif /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* Local variable definition *************************************************************************** @@ -222,9 +228,47 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED -const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; static bool log_is_inited = false; +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +/* TODO: Remove event handler dependency in lib */ +static void void_handler(void) {} + +/* TODO: Declare public interfaces in a public header */ +void esp_bt_controller_log_deinit(void) +{ + log_is_inited = false; + r_ble_log_deinit_simple(); + ble_log_deinit(); +} + +esp_err_t esp_bt_controller_log_init(void) +{ + if (log_is_inited) { + return ESP_OK; + } + + if (!ble_log_init()) { + goto exit; + } + + if (r_ble_log_init_simple(ble_log_write_hex_ll, void_handler) != 0) { + goto exit; + } + + if (r_ble_log_ctrl_level_and_mod(CONFIG_BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL, + CONFIG_BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH) != ESP_OK) { + goto exit; + } + log_is_inited = true; + return ESP_OK; + +exit: + esp_bt_controller_log_deinit(); + return ESP_FAIL; +} +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ +const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; esp_err_t esp_bt_controller_log_init(void) { if (log_is_inited) { @@ -318,6 +362,7 @@ void esp_bt_controller_log_deinit(void) log_is_inited = false; } +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE #include "esp_partition.h" @@ -1519,6 +1564,12 @@ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t po } #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +void esp_ble_controller_log_dump_all(bool output) +{ + ble_log_dump_to_console(); +} +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag) { @@ -1565,6 +1616,7 @@ void esp_ble_controller_log_dump_all(bool output) portEXIT_CRITICAL_SAFE(&spinlock); #endif } +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED) From 954e370bc0817e11ad24110d705164322fd65667 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Mon, 15 Sep 2025 11:56:12 +0800 Subject: [PATCH 3/8] feat(ble): supported ble log v2 for ESP32-H2 --- components/bt/controller/esp32h2/Kconfig.in | 143 +++++++++++--------- components/bt/controller/esp32h2/bt.c | 54 +++++++- 2 files changed, 129 insertions(+), 68 deletions(-) diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index ff299e7187..6d6e38af5a 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -332,84 +332,93 @@ menu "Controller debug features" help Enable controller log - config BT_LE_CONTROLLER_LOG_CTRL_ENABLED - bool "enable controller log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED + config BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + bool "Utilize BLE Log v2 for controller log" + depends on BLE_LOG_ENABLED default y help - Enable controller log module + Utilize BLE Log v2 for controller log - config BT_LE_CONTROLLER_LOG_HCI_ENABLED - bool "enable HCI log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help - Enable hci log module + if !BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + config BT_LE_CONTROLLER_LOG_CTRL_ENABLED + bool "enable controller log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Enable controller log module - config BT_LE_CONTROLLER_LOG_DUMP_ONLY - bool "Controller log dump mode only" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help - Only operate in dump mode + config BT_LE_CONTROLLER_LOG_HCI_ENABLED + bool "enable HCI log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Enable hci log module - config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - bool "Output ble controller logs to SPI bus (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - select BT_BLE_LOG_SPI_OUT_ENABLED - default n - help - Output ble controller logs to SPI bus + config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Only operate in dump mode - config BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED - bool "Output ble controller logs via UART DMA (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on !BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - select BT_BLE_LOG_UHCI_OUT_ENABLED - default y - help - Output ble controller logs via UART DMA + config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + bool "Output ble controller logs to SPI bus (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + select BT_BLE_LOG_SPI_OUT_ENABLED + default n + help + Output ble controller logs to SPI bus - config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - bool "Store ble controller logs to flash(Experimental)" - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Store ble controller logs to flash memory. + config BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED + bool "Output ble controller logs via UART DMA (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on !BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + select BT_BLE_LOG_UHCI_OUT_ENABLED + default y + help + Output ble controller logs via UART DMA - config BT_LE_CONTROLLER_LOG_PARTITION_SIZE - int "size of ble controller log partition(Multiples of 4K)" - depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - default 65536 - help - The size of ble controller log partition shall be a multiples of 4K. - The name of log partition shall be "bt_ctrl_log". - The partition type shall be ESP_PARTITION_TYPE_DATA. - The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. + config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + bool "Store ble controller logs to flash(Experimental)" + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Store ble controller logs to flash memory. - config BT_LE_LOG_CTRL_BUF1_SIZE - int "size of the first BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help - Configure the size of the first BLE controller LOG buffer. + config BT_LE_CONTROLLER_LOG_PARTITION_SIZE + int "size of ble controller log partition(Multiples of 4K)" + depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + default 65536 + help + The size of ble controller log partition shall be a multiples of 4K. + The name of log partition shall be "bt_ctrl_log". + The partition type shall be ESP_PARTITION_TYPE_DATA. + The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. - config BT_LE_LOG_CTRL_BUF2_SIZE - int "size of the second BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 1024 - help - Configure the size of the second BLE controller LOG buffer. + config BT_LE_LOG_CTRL_BUF1_SIZE + int "size of the first BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help + Configure the size of the first BLE controller LOG buffer. - config BT_LE_LOG_HCI_BUF_SIZE - int "size of the BLE HCI LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help - Configure the size of the BLE HCI LOG buffer. + config BT_LE_LOG_CTRL_BUF2_SIZE + int "size of the second BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 1024 + help + Configure the size of the second BLE controller LOG buffer. + + config BT_LE_LOG_HCI_BUF_SIZE + int "size of the BLE HCI LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help + Configure the size of the BLE HCI LOG buffer. + endif config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE bool "Enable wrap panic handler" diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 65435cf80a..c5d60c50d2 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -55,6 +55,9 @@ #include "esp_sleep.h" #include "soc/rtc.h" +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +#include "ble_log.h" +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #include "ble_log/ble_log_spi_out.h" #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED @@ -62,6 +65,7 @@ #if CONFIG_BT_BLE_LOG_UHCI_OUT_ENABLED #include "ble_log/ble_log_uhci_out.h" #endif // CONFIG_BT_BLE_LOG_UHCI_OUT_ENABLED +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ /* Macro definition ************************************************************************ @@ -194,12 +198,14 @@ static int esp_ecc_gen_key_pair(uint8_t *pub, uint8_t *priv); static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y, const uint8_t *our_priv_key, uint8_t *out_dhkey); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +#if !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag); #endif // !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE +#endif /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* Local variable definition *************************************************************************** @@ -208,9 +214,47 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED -const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; static bool log_is_inited = false; +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +/* TODO: Remove event handler dependency in lib */ +static void void_handler(void) {} + +/* TODO: Declare public interfaces in a public header */ +void esp_bt_controller_log_deinit(void) +{ + log_is_inited = false; + r_ble_log_deinit_simple(); + ble_log_deinit(); +} + +esp_err_t esp_bt_controller_log_init(void) +{ + if (log_is_inited) { + return ESP_OK; + } + + if (!ble_log_init()) { + goto exit; + } + + if (r_ble_log_init_simple(ble_log_write_hex_ll, void_handler) != 0) { + goto exit; + } + + if (r_ble_log_ctrl_level_and_mod(CONFIG_BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL, + CONFIG_BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH) != ESP_OK) { + goto exit; + } + log_is_inited = true; + return ESP_OK; + +exit: + esp_bt_controller_log_deinit(); + return ESP_FAIL; +} +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ +const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; esp_err_t esp_bt_controller_log_init(void) { if (log_is_inited) { @@ -304,6 +348,7 @@ void esp_bt_controller_log_deinit(void) log_is_inited = false; } +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE #include "esp_partition.h" @@ -1442,6 +1487,12 @@ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t po } #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +void esp_ble_controller_log_dump_all(bool output) +{ + ble_log_dump_to_console(); +} +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag) { @@ -1488,6 +1539,7 @@ void esp_ble_controller_log_dump_all(bool output) portEXIT_CRITICAL_SAFE(&spinlock); #endif } +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED) From 49bcc44e769bb73cbc471562ca845110ddee1ccb Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Mon, 15 Sep 2025 13:40:47 +0800 Subject: [PATCH 4/8] feat(ble): supported ble log v2 for ESP32-C2 --- components/bt/controller/esp32c2/Kconfig.in | 125 +++++++++++--------- components/bt/controller/esp32c2/bt.c | 50 +++++++- 2 files changed, 116 insertions(+), 59 deletions(-) diff --git a/components/bt/controller/esp32c2/Kconfig.in b/components/bt/controller/esp32c2/Kconfig.in index 4d406f2c71..c0bf39a7fe 100644 --- a/components/bt/controller/esp32c2/Kconfig.in +++ b/components/bt/controller/esp32c2/Kconfig.in @@ -288,74 +288,83 @@ menu "Controller debug features" help Enable controller log - config BT_LE_CONTROLLER_LOG_CTRL_ENABLED - bool "enable controller log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED + config BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + bool "Utilize BLE Log v2 for controller log" + depends on BLE_LOG_ENABLED default y help - Enable controller log module + Utilize BLE Log v2 for controller log - config BT_LE_CONTROLLER_LOG_HCI_ENABLED - bool "enable HCI log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help - Enable hci log module + if !BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + config BT_LE_CONTROLLER_LOG_CTRL_ENABLED + bool "enable controller log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Enable controller log module - config BT_LE_CONTROLLER_LOG_DUMP_ONLY - bool "Controller log dump mode only" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help - Only operate in dump mode + config BT_LE_CONTROLLER_LOG_HCI_ENABLED + bool "enable HCI log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Enable hci log module - config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - bool "Output ble controller logs to SPI bus (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - select BT_BLE_LOG_SPI_OUT_ENABLED - default n - help - Output ble controller logs to SPI bus + config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Only operate in dump mode - config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - bool "Store ble controller logs to flash(Experimental)" - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Store ble controller logs to flash memory. + config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + bool "Output ble controller logs to SPI bus (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + select BT_BLE_LOG_SPI_OUT_ENABLED + default n + help + Output ble controller logs to SPI bus - config BT_LE_CONTROLLER_LOG_PARTITION_SIZE - int "size of ble controller log partition(Multiples of 4K)" - depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - default 65536 - help - The size of ble controller log partition shall be a multiples of 4K. - The name of log partition shall be "bt_ctrl_log". - The partition type shall be ESP_PARTITION_TYPE_DATA. - The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. + config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + bool "Store ble controller logs to flash(Experimental)" + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Store ble controller logs to flash memory. - config BT_LE_LOG_CTRL_BUF1_SIZE - int "size of the first BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help - Configure the size of the first BLE controller LOG buffer. + config BT_LE_CONTROLLER_LOG_PARTITION_SIZE + int "size of ble controller log partition(Multiples of 4K)" + depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + default 65536 + help + The size of ble controller log partition shall be a multiples of 4K. + The name of log partition shall be "bt_ctrl_log". + The partition type shall be ESP_PARTITION_TYPE_DATA. + The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. - config BT_LE_LOG_CTRL_BUF2_SIZE - int "size of the second BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 1024 - help - Configure the size of the second BLE controller LOG buffer. + config BT_LE_LOG_CTRL_BUF1_SIZE + int "size of the first BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help + Configure the size of the first BLE controller LOG buffer. - config BT_LE_LOG_HCI_BUF_SIZE - int "size of the BLE HCI LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help - Configure the size of the BLE HCI LOG buffer. + config BT_LE_LOG_CTRL_BUF2_SIZE + int "size of the second BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 1024 + help + Configure the size of the second BLE controller LOG buffer. + + config BT_LE_LOG_HCI_BUF_SIZE + int "size of the BLE HCI LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help + Configure the size of the BLE HCI LOG buffer. + endif config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE bool "Enable wrap panic handler" diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index ffa15d3c9a..e5eb940d34 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -66,9 +66,13 @@ #include "hal/efuse_ll.h" #include "soc/rtc.h" +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +#include "ble_log.h" +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #include "ble_log/ble_log_spi_out.h" #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ /* Macro definition ************************************************************************ @@ -207,12 +211,14 @@ static int esp_ecc_gen_key_pair(uint8_t *pub, uint8_t *priv); static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y, const uint8_t *our_priv_key, uint8_t *out_dhkey); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +#if !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag); #endif // !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE +#endif /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* Local variable definition *************************************************************************** @@ -224,9 +230,43 @@ void *g_ble_lll_rfmgmt_env_p; static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED -const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; static bool log_is_inited = false; +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +/* TODO: Remove event handler dependency in lib */ +static void void_handler(void) {} + +/* TODO: Declare public interfaces in a public header */ +void esp_bt_controller_log_deinit(void) +{ + log_is_inited = false; + ble_log_deinit_simple(); + ble_log_deinit(); +} + +esp_err_t esp_bt_controller_log_init(void) +{ + if (log_is_inited) { + return ESP_OK; + } + + if (!ble_log_init()) { + goto exit; + } + + if (ble_log_init_simple(ble_log_write_hex_ll, void_handler) != 0) { + goto exit; + } + + log_is_inited = true; + return ESP_OK; + +exit: + esp_bt_controller_log_deinit(); + return ESP_FAIL; +} +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ +const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; esp_err_t esp_bt_controller_log_init(void) { if (log_is_inited) { @@ -289,6 +329,7 @@ void esp_bt_controller_log_deinit(void) log_is_inited = false; } +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE #include "esp_partition.h" @@ -413,6 +454,12 @@ void esp_bt_read_ctrl_log_from_flash(bool output) } #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +void esp_ble_controller_log_dump_all(bool output) +{ + ble_log_dump_to_console(); +} +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag) { @@ -455,6 +502,7 @@ void esp_ble_controller_log_dump_all(bool output) portEXIT_CRITICAL_SAFE(&spinlock); #endif } +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE void esp_task_wdt_isr_user_handler(void) From 8e1b0c23a78571e3cc649cc536411806eec5d723 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Mon, 15 Sep 2025 13:46:23 +0800 Subject: [PATCH 5/8] feat(ble): supported ble log v2 for ESP32-C5 --- components/bt/controller/esp32c5/Kconfig.in | 143 +++++++++++--------- components/bt/controller/esp32c5/bt.c | 54 +++++++- 2 files changed, 129 insertions(+), 68 deletions(-) diff --git a/components/bt/controller/esp32c5/Kconfig.in b/components/bt/controller/esp32c5/Kconfig.in index 8d6daf7247..e634fba4a9 100644 --- a/components/bt/controller/esp32c5/Kconfig.in +++ b/components/bt/controller/esp32c5/Kconfig.in @@ -297,84 +297,93 @@ menu "Controller debug features" help Enable controller log - config BT_LE_CONTROLLER_LOG_CTRL_ENABLED - bool "enable controller log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED + config BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + bool "Utilize BLE Log v2 for controller log" + depends on BLE_LOG_ENABLED default y help - Enable controller log module + Utilize BLE Log v2 for controller log - config BT_LE_CONTROLLER_LOG_HCI_ENABLED - bool "enable HCI log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help - Enable hci log module + if !BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 + config BT_LE_CONTROLLER_LOG_CTRL_ENABLED + bool "enable controller log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Enable controller log module - config BT_LE_CONTROLLER_LOG_DUMP_ONLY - bool "Controller log dump mode only" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help - Only operate in dump mode + config BT_LE_CONTROLLER_LOG_HCI_ENABLED + bool "enable HCI log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Enable hci log module - config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - bool "Output ble controller logs to SPI bus (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - select BT_BLE_LOG_SPI_OUT_ENABLED - default n - help - Output ble controller logs to SPI bus + config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help + Only operate in dump mode - config BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED - bool "Output ble controller logs via UART DMA (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on !BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - select BT_BLE_LOG_UHCI_OUT_ENABLED - default y - help - Output ble controller logs via UART DMA + config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + bool "Output ble controller logs to SPI bus (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + select BT_BLE_LOG_SPI_OUT_ENABLED + default n + help + Output ble controller logs to SPI bus - config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - bool "Store ble controller logs to flash(Experimental)" - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Store ble controller logs to flash memory. + config BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED + bool "Output ble controller logs via UART DMA (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on !BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + select BT_BLE_LOG_UHCI_OUT_ENABLED + default y + help + Output ble controller logs via UART DMA - config BT_LE_CONTROLLER_LOG_PARTITION_SIZE - int "size of ble controller log partition(Multiples of 4K)" - depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - default 65536 - help - The size of ble controller log partition shall be a multiples of 4K. - The name of log partition shall be "bt_ctrl_log". - The partition type shall be ESP_PARTITION_TYPE_DATA. - The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. + config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + bool "Store ble controller logs to flash(Experimental)" + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Store ble controller logs to flash memory. - config BT_LE_LOG_CTRL_BUF1_SIZE - int "size of the first BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help - Configure the size of the first BLE controller LOG buffer. + config BT_LE_CONTROLLER_LOG_PARTITION_SIZE + int "size of ble controller log partition(Multiples of 4K)" + depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + default 65536 + help + The size of ble controller log partition shall be a multiples of 4K. + The name of log partition shall be "bt_ctrl_log". + The partition type shall be ESP_PARTITION_TYPE_DATA. + The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. - config BT_LE_LOG_CTRL_BUF2_SIZE - int "size of the second BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 1024 - help - Configure the size of the second BLE controller LOG buffer. + config BT_LE_LOG_CTRL_BUF1_SIZE + int "size of the first BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help + Configure the size of the first BLE controller LOG buffer. - config BT_LE_LOG_HCI_BUF_SIZE - int "size of the BLE HCI LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help - Configure the size of the BLE HCI LOG buffer. + config BT_LE_LOG_CTRL_BUF2_SIZE + int "size of the second BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 1024 + help + Configure the size of the second BLE controller LOG buffer. + + config BT_LE_LOG_HCI_BUF_SIZE + int "size of the BLE HCI LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help + Configure the size of the BLE HCI LOG buffer. + endif config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE bool "Enable wrap panic handler" diff --git a/components/bt/controller/esp32c5/bt.c b/components/bt/controller/esp32c5/bt.c index a7363cbfd7..7673594f52 100644 --- a/components/bt/controller/esp32c5/bt.c +++ b/components/bt/controller/esp32c5/bt.c @@ -56,6 +56,9 @@ #include "hal/efuse_hal.h" #include "soc/rtc.h" +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +#include "ble_log.h" +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #include "ble_log/ble_log_spi_out.h" #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED @@ -63,6 +66,7 @@ #if CONFIG_BT_BLE_LOG_UHCI_OUT_ENABLED #include "ble_log/ble_log_uhci_out.h" #endif // CONFIG_BT_BLE_LOG_UHCI_OUT_ENABLED +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ /* Macro definition ************************************************************************ @@ -192,12 +196,14 @@ static int esp_ecc_gen_key_pair(uint8_t *pub, uint8_t *priv); static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y, const uint8_t *our_priv_key, uint8_t *out_dhkey); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +#if !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag); #endif // !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE +#endif /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* Local variable definition *************************************************************************** @@ -206,9 +212,47 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED -const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; static bool log_is_inited = false; +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +/* TODO: Remove event handler dependency in lib */ +static void void_handler(void) {} + +/* TODO: Declare public interfaces in a public header */ +void esp_bt_controller_log_deinit(void) +{ + log_is_inited = false; + r_ble_log_deinit_simple(); + ble_log_deinit(); +} + +esp_err_t esp_bt_controller_log_init(void) +{ + if (log_is_inited) { + return ESP_OK; + } + + if (!ble_log_init()) { + goto exit; + } + + if (r_ble_log_init_simple(ble_log_write_hex_ll, void_handler) != 0) { + goto exit; + } + + if (r_ble_log_ctrl_level_and_mod(CONFIG_BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL, + CONFIG_BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH) != ESP_OK) { + goto exit; + } + log_is_inited = true; + return ESP_OK; + +exit: + esp_bt_controller_log_deinit(); + return ESP_FAIL; +} +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ +const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; esp_err_t esp_bt_controller_log_init(void) { if (log_is_inited) { @@ -302,6 +346,7 @@ void esp_bt_controller_log_deinit(void) log_is_inited = false; } +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE #include "esp_partition.h" @@ -1448,6 +1493,12 @@ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t po } #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED +#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 +void esp_ble_controller_log_dump_all(bool output) +{ + ble_log_dump_to_console(); +} +#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED && !CONFIG_BT_LE_CONTROLLER_LOG_UHCI_OUT_ENABLED static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag) { @@ -1494,6 +1545,7 @@ void esp_ble_controller_log_dump_all(bool output) portEXIT_CRITICAL_SAFE(&spinlock); #endif } +#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */ #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED) From 85d2c81f70eaeec8f353a56ab7302524621c6c00 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Mon, 15 Sep 2025 14:22:52 +0800 Subject: [PATCH 6/8] feat(ble): supported ble log v2 for ESP32-C3/ESP32-S3 --- components/bt/controller/esp32c3/Kconfig.in | 69 ++++++++++++--------- components/bt/controller/esp32c3/bt.c | 69 ++++++++++++++++++++- 2 files changed, 105 insertions(+), 33 deletions(-) diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index f3fc5778b1..b29a4fd8ee 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -569,41 +569,50 @@ menu "Controller debug log Options (Experimental)" bool "Enable BLE debug log" default n + config BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 + bool "Utilize BLE Log v2 for controller log" + depends on BT_CTRL_LE_LOG_EN + default y + help + Utilize BLE Log v2 for controller log + + if !BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 + config BT_CTRL_LE_LOG_DUMP_ONLY + depends on BT_CTRL_LE_LOG_EN + bool "Enable BLE log dump only" + default n + + config BT_CTRL_LE_LOG_STORAGE_EN + depends on BT_CTRL_LE_LOG_EN + bool "Enable BLE log storage to flash" + default n + + config BT_CTRL_LE_LOG_PARTITION_SIZE + int "The size of ble controller log partition(Multiples of 4K)" + depends on BT_CTRL_LE_LOG_STORAGE_EN + default 65536 + help + The size of ble controller log partition shall be a multiples of 4K. + The name of log partition shall be "bt_ctrl_log". + The partition type shall be ESP_PARTITION_TYPE_DATA. + The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. + + config BT_CTRL_LE_LOG_SPI_OUT_EN + bool "Output ble controller logs to SPI bus" + depends on BT_CTRL_LE_LOG_EN + depends on !BT_CTRL_LE_LOG_DUMP_ONLY + select BT_BLE_LOG_SPI_OUT_ENABLED + select BT_BLE_LOG_SPI_OUT_LL_ENABLED + default n + help + Output ble controller logs to SPI bus + endif + config BT_CTRL_LE_HCI_LOG_EN depends on BT_CTRL_LE_LOG_EN bool "Enable BLE HCI log" default n - config BT_CTRL_LE_LOG_DUMP_ONLY - depends on BT_CTRL_LE_LOG_EN - bool "Enable BLE log dump only" - default n - - config BT_CTRL_LE_LOG_STORAGE_EN - depends on BT_CTRL_LE_LOG_EN - bool "Enable BLE log storage to flash" - default n - - config BT_CTRL_LE_LOG_PARTITION_SIZE - int "The size of ble controller log partition(Multiples of 4K)" - depends on BT_CTRL_LE_LOG_STORAGE_EN - default 65536 - help - The size of ble controller log partition shall be a multiples of 4K. - The name of log partition shall be "bt_ctrl_log". - The partition type shall be ESP_PARTITION_TYPE_DATA. - The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. - - config BT_CTRL_LE_LOG_SPI_OUT_EN - bool "Output ble controller logs to SPI bus" - depends on BT_CTRL_LE_LOG_EN - depends on !BT_CTRL_LE_LOG_DUMP_ONLY - select BT_BLE_LOG_SPI_OUT_ENABLED - select BT_BLE_LOG_SPI_OUT_LL_ENABLED - default n - help - Output ble controller logs to SPI bus - config BT_CTRL_LE_LOG_MODE_EN depends on BT_CTRL_LE_LOG_EN int "Enable log for specified BLE mode" diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index fc5abee358..29b6a49fe0 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -49,9 +49,13 @@ #else //CONFIG_IDF_TARGET_ESP32S3 #include "esp32s3/rom/rom_layout.h" #endif +#if CONFIG_BLE_LOG_ENABLED +#include "ble_log.h" +#else /* !CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #include "ble_log/ble_log_spi_out.h" #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_CTRL_LE_LOG_STORAGE_EN #include "esp_partition.h" #include "hal/wdt_hal.h" @@ -503,10 +507,14 @@ enum log_out_mode { LOG_ASYNC_OUT, LOG_STORAGE_TO_FLASH, LOG_SPI_OUT, + LOG_BLE_LOG_V2, }; const static uint32_t log_bufs_size[] = {CONFIG_BT_CTRL_LE_LOG_BUF1_SIZE, CONFIG_BT_CTRL_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_CTRL_LE_LOG_BUF2_SIZE}; bool log_is_inited = false; +#if CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 +uint8_t log_output_mode = LOG_BLE_LOG_V2; +#else /* !CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_CTRL_LE_LOG_DUMP_ONLY uint8_t log_output_mode = LOG_DUMP_MEMORY; #else @@ -518,6 +526,7 @@ uint8_t log_output_mode = LOG_SPI_OUT; uint8_t log_output_mode = LOG_ASYNC_OUT; #endif // CONFIG_BT_CTRL_LE_LOG_STORAGE_EN #endif // CONFIG_BT_CTRL_LE_LOG_DUMP_ONLY +#endif /* CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 */ #if CONFIG_BT_CTRL_LE_LOG_STORAGE_EN static const esp_partition_t *log_partition; static uint32_t write_index = 0; @@ -527,6 +536,17 @@ static bool stop_write = false; static bool is_filled = false; #endif // CONFIG_BT_CTRL_LE_LOG_STORAGE_EN +#if CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 +static IRAM_ATTR void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end) +{ + ble_log_write_hex_ll(len, addr, 0, NULL, 0); +} + +void esp_ble_controller_log_dump_all(bool output) +{ + ble_log_dump_to_console(); +} +#else /* !CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 */ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end) { if (log_output_mode == LOG_STORAGE_TO_FLASH) { @@ -571,6 +591,7 @@ void esp_ble_controller_log_dump_all(bool output) portEXIT_CRITICAL_SAFE(&spinlock); } } +#endif /* CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 */ void esp_bt_log_output_mode_set(uint8_t output_mode) { @@ -582,6 +603,31 @@ uint8_t esp_bt_log_output_mode_get(void) return log_output_mode; } +#if CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 +esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) +{ + if (log_is_inited) { + return ESP_OK; + } + + esp_err_t ret = ESP_OK; + uint8_t buffers = 0; + +#if CONFIG_BT_CTRL_LE_LOG_EN + buffers |= ESP_BLE_LOG_BUF_CONTROLLER; +#endif // CONFIG_BT_CTRL_LE_LOG_EN +#if CONFIG_BT_CTRL_LE_HCI_LOG_EN + buffers |= ESP_BLE_LOG_BUF_HCI; +#endif // CONFIG_BT_CTRL_LE_HCI_LOG_EN + + ret = r_ble_log_init_async(esp_bt_controller_log_interface, true, buffers, (uint32_t *)log_bufs_size); + if (ret == ESP_OK) { + log_is_inited = true; + } + + return ret; +} +#else /* !CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 */ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) { esp_err_t ret = ESP_OK; @@ -631,8 +677,9 @@ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode) return ret; } +#endif /* CONFIG_BT_CTRL_LE_LOG_MODE_BLE_LOG_V2*/ -void esp_bt_ontroller_log_deinit(void) +void esp_bt_controller_log_deinit(void) { r_ble_log_deinit_async(); log_is_inited = false; @@ -713,7 +760,7 @@ void esp_bt_read_ctrl_log_from_flash(bool output) portENTER_CRITICAL_SAFE(&spinlock); esp_panic_handler_feed_wdts(); r_ble_log_async_output_dump_all(true); - esp_bt_ontroller_log_deinit(); + esp_bt_controller_log_deinit(); stop_write = true; buffer = (const uint8_t *)mapped_ptr; @@ -1806,6 +1853,13 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) coex_init(); #endif +#if CONFIG_BLE_LOG_ENABLED + if (!ble_log_init()) { + ESP_LOGE(BT_LOG_TAG, "BLE Log v2 init failed"); + err = ESP_ERR_NO_MEM; + goto error; + } +#else /* !CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED if (ble_log_spi_out_init() != 0) { ESP_LOGE(BT_LOG_TAG, "BLE Log SPI output init failed"); @@ -1813,6 +1867,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto error; } #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BLE_LOG_ENABLED */ periph_module_enable(PERIPH_BT_MODULE); periph_module_reset(PERIPH_BT_MODULE); @@ -1846,9 +1901,13 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) error: +#if CONFIG_BLE_LOG_ENABLED + ble_log_deinit(); +#else /* !CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED ble_log_spi_out_deinit(); #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BLE_LOG_ENABLED */ bt_controller_deinit_internal(); @@ -1861,9 +1920,13 @@ esp_err_t esp_bt_controller_deinit(void) return ESP_ERR_INVALID_STATE; } +#if CONFIG_BLE_LOG_ENABLED + ble_log_deinit(); +#else /* !CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED ble_log_spi_out_deinit(); #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BLE_LOG_ENABLED */ #if (CONFIG_BT_BLUEDROID_ENABLED || CONFIG_BT_NIMBLE_ENABLED) scan_stack_enableAdvFlowCtrlVsCmd(false); @@ -1951,7 +2014,7 @@ static void bt_controller_deinit_internal(void) esp_phy_modem_deinit(); #if CONFIG_BT_CTRL_LE_LOG_EN - esp_bt_ontroller_log_deinit(); + esp_bt_controller_log_deinit(); #endif // CONFIG_BT_CTRL_LE_LOG_EN if (osi_funcs_p != NULL) { From 2d83b8f4221728ab4e3b6577d61f48ab02e6c263 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Mon, 15 Sep 2025 15:57:15 +0800 Subject: [PATCH 7/8] feat(ble): supported ble log v2 for ESP32 --- components/bt/controller/esp32/bt.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/bt/controller/esp32/bt.c b/components/bt/controller/esp32/bt.c index a88fca9c72..9243426b97 100644 --- a/components/bt/controller/esp32/bt.c +++ b/components/bt/controller/esp32/bt.c @@ -48,9 +48,13 @@ #include "esp_rom_sys.h" #include "hli_api.h" +#if CONFIG_BLE_LOG_ENABLED +#include "ble_log.h" +#else /* !CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #include "ble_log/ble_log_spi_out.h" #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_ENABLED @@ -1702,6 +1706,13 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) coex_init(); #endif +#if CONFIG_BLE_LOG_ENABLED + if (!ble_log_init()) { + ESP_LOGE(BTDM_LOG_TAG, "BLE Log v2 init failed"); + err = ESP_ERR_NO_MEM; + goto error; + } +#else /* !CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED if (ble_log_spi_out_init() != 0) { ESP_LOGE(BTDM_LOG_TAG, "BLE Log SPI output init failed"); @@ -1709,6 +1720,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto error; } #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BLE_LOG_ENABLED */ btdm_cfg_mask = btdm_config_mask_load(); @@ -1737,9 +1749,13 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) error: +#if CONFIG_BLE_LOG_ENABLED + ble_log_deinit(); +#else /* !CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED ble_log_spi_out_deinit(); #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BLE_LOG_ENABLED */ bt_controller_deinit_internal(); @@ -1752,9 +1768,13 @@ esp_err_t esp_bt_controller_deinit(void) return ESP_ERR_INVALID_STATE; } +#if CONFIG_BLE_LOG_ENABLED + ble_log_deinit(); +#else /* !CONFIG_BLE_LOG_ENABLED */ #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED ble_log_spi_out_deinit(); #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED +#endif /* CONFIG_BLE_LOG_ENABLED */ btdm_controller_deinit(); From 727224920ce1594986d6300e32c4e9b2edb776b7 Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Tue, 16 Sep 2025 19:43:03 +0800 Subject: [PATCH 8/8] fix(ble): fixed ble log config for ESP32-C3/ESP32-S3 --- components/bt/controller/esp32c3/Kconfig.in | 1 + 1 file changed, 1 insertion(+) diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index b29a4fd8ee..d9f1bcc05d 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -572,6 +572,7 @@ menu "Controller debug log Options (Experimental)" config BT_CTRL_LE_LOG_MODE_BLE_LOG_V2 bool "Utilize BLE Log v2 for controller log" depends on BT_CTRL_LE_LOG_EN + depends on BLE_LOG_ENABLED default y help Utilize BLE Log v2 for controller log