feat(ble): supported ble log v2 for ESP32-C3/ESP32-S3

This commit is contained in:
Zhou Xiao
2025-09-15 14:22:52 +08:00
parent b65ba9a601
commit 32cb69706b
2 changed files with 105 additions and 33 deletions

View File

@@ -567,41 +567,50 @@ menu "Controller debug log Options (Experimental)"
bool "Enable BLE debug log" bool "Enable BLE debug log"
default n 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 config BT_CTRL_LE_HCI_LOG_EN
depends on BT_CTRL_LE_LOG_EN depends on BT_CTRL_LE_LOG_EN
bool "Enable BLE HCI log" bool "Enable BLE HCI log"
default n 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 config BT_CTRL_LE_LOG_MODE_EN
depends on BT_CTRL_LE_LOG_EN depends on BT_CTRL_LE_LOG_EN
int "Enable log for specified BLE mode" int "Enable log for specified BLE mode"

View File

@@ -49,9 +49,13 @@
#else //CONFIG_IDF_TARGET_ESP32S3 #else //CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/rom/rom_layout.h" #include "esp32s3/rom/rom_layout.h"
#endif #endif
#if CONFIG_BLE_LOG_ENABLED
#include "ble_log.h"
#else /* !CONFIG_BLE_LOG_ENABLED */
#if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#include "ble_log/ble_log_spi_out.h" #include "ble_log/ble_log_spi_out.h"
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#endif /* CONFIG_BLE_LOG_ENABLED */
#if CONFIG_BT_CTRL_LE_LOG_STORAGE_EN #if CONFIG_BT_CTRL_LE_LOG_STORAGE_EN
#include "esp_partition.h" #include "esp_partition.h"
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
@@ -504,10 +508,14 @@ enum log_out_mode {
LOG_ASYNC_OUT, LOG_ASYNC_OUT,
LOG_STORAGE_TO_FLASH, LOG_STORAGE_TO_FLASH,
LOG_SPI_OUT, 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}; 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; 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 #if CONFIG_BT_CTRL_LE_LOG_DUMP_ONLY
uint8_t log_output_mode = LOG_DUMP_MEMORY; uint8_t log_output_mode = LOG_DUMP_MEMORY;
#else #else
@@ -519,6 +527,7 @@ uint8_t log_output_mode = LOG_SPI_OUT;
uint8_t log_output_mode = LOG_ASYNC_OUT; uint8_t log_output_mode = LOG_ASYNC_OUT;
#endif // CONFIG_BT_CTRL_LE_LOG_STORAGE_EN #endif // CONFIG_BT_CTRL_LE_LOG_STORAGE_EN
#endif // CONFIG_BT_CTRL_LE_LOG_DUMP_ONLY #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 #if CONFIG_BT_CTRL_LE_LOG_STORAGE_EN
static const esp_partition_t *log_partition; static const esp_partition_t *log_partition;
static uint32_t write_index = 0; static uint32_t write_index = 0;
@@ -528,6 +537,17 @@ static bool stop_write = false;
static bool is_filled = false; static bool is_filled = false;
#endif // CONFIG_BT_CTRL_LE_LOG_STORAGE_EN #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) static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end)
{ {
if (log_output_mode == LOG_STORAGE_TO_FLASH) { if (log_output_mode == LOG_STORAGE_TO_FLASH) {
@@ -572,6 +592,7 @@ void esp_ble_controller_log_dump_all(bool output)
portEXIT_CRITICAL_SAFE(&spinlock); 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) void esp_bt_log_output_mode_set(uint8_t output_mode)
{ {
@@ -583,6 +604,31 @@ uint8_t esp_bt_log_output_mode_get(void)
return log_output_mode; 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 esp_bt_controller_log_init(uint8_t log_output_mode)
{ {
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
@@ -632,8 +678,9 @@ esp_err_t esp_bt_controller_log_init(uint8_t log_output_mode)
return ret; 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(); r_ble_log_deinit_async();
log_is_inited = false; log_is_inited = false;
@@ -714,7 +761,7 @@ void esp_bt_read_ctrl_log_from_flash(bool output)
portENTER_CRITICAL_SAFE(&spinlock); portENTER_CRITICAL_SAFE(&spinlock);
esp_panic_handler_feed_wdts(); esp_panic_handler_feed_wdts();
r_ble_log_async_output_dump_all(true); r_ble_log_async_output_dump_all(true);
esp_bt_ontroller_log_deinit(); esp_bt_controller_log_deinit();
stop_write = true; stop_write = true;
buffer = (const uint8_t *)mapped_ptr; buffer = (const uint8_t *)mapped_ptr;
@@ -1807,6 +1854,13 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
coex_init(); coex_init();
#endif #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 CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
if (ble_log_spi_out_init() != 0) { if (ble_log_spi_out_init() != 0) {
ESP_LOGE(BT_LOG_TAG, "BLE Log SPI output init failed"); ESP_LOGE(BT_LOG_TAG, "BLE Log SPI output init failed");
@@ -1814,6 +1868,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
goto error; goto error;
} }
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#endif /* CONFIG_BLE_LOG_ENABLED */
periph_module_enable(PERIPH_BT_MODULE); periph_module_enable(PERIPH_BT_MODULE);
periph_module_reset(PERIPH_BT_MODULE); periph_module_reset(PERIPH_BT_MODULE);
@@ -1847,9 +1902,13 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
error: error:
#if CONFIG_BLE_LOG_ENABLED
ble_log_deinit();
#else /* !CONFIG_BLE_LOG_ENABLED */
#if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
ble_log_spi_out_deinit(); ble_log_spi_out_deinit();
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#endif /* CONFIG_BLE_LOG_ENABLED */
bt_controller_deinit_internal(); bt_controller_deinit_internal();
@@ -1862,9 +1921,13 @@ esp_err_t esp_bt_controller_deinit(void)
return ESP_ERR_INVALID_STATE; 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 #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
ble_log_spi_out_deinit(); ble_log_spi_out_deinit();
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#endif /* CONFIG_BLE_LOG_ENABLED */
#if (CONFIG_BT_BLUEDROID_ENABLED || CONFIG_BT_NIMBLE_ENABLED) #if (CONFIG_BT_BLUEDROID_ENABLED || CONFIG_BT_NIMBLE_ENABLED)
scan_stack_enableAdvFlowCtrlVsCmd(false); scan_stack_enableAdvFlowCtrlVsCmd(false);
@@ -1952,7 +2015,7 @@ static void bt_controller_deinit_internal(void)
esp_phy_modem_deinit(); esp_phy_modem_deinit();
#if CONFIG_BT_CTRL_LE_LOG_EN #if CONFIG_BT_CTRL_LE_LOG_EN
esp_bt_ontroller_log_deinit(); esp_bt_controller_log_deinit();
#endif // CONFIG_BT_CTRL_LE_LOG_EN #endif // CONFIG_BT_CTRL_LE_LOG_EN
if (osi_funcs_p != NULL) { if (osi_funcs_p != NULL) {