Skip to content

Commit f598976

Browse files
feat(ble): support enhanced controller log capabilities on ESP32-C6 and ESP32-H2
1 parent 6cb6176 commit f598976

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed

components/bt/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ if(CONFIG_BT_ENABLED)
904904
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
905905
endif()
906906
elseif(CONFIG_BT_CONTROLLER_ENABLED)
907+
if(CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE)
908+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=esp_panic_handler")
909+
endif()
907910
if(CONFIG_IDF_TARGET_ESP32C6)
908911
add_prebuilt_library(libble_app
909912
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c6/esp32c6-bt-lib/esp32c6/libble_app.a")

components/bt/controller/esp32c6/Kconfig.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,36 @@ config BT_LE_LOG_HCI_BUF_SIZE
424424
help
425425
Configure the size of the BLE HCI LOG buffer.
426426

427+
config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
428+
bool "Enable wrap panic handler"
429+
depends on BT_LE_CONTROLLER_LOG_ENABLED
430+
default n
431+
help
432+
Wrap esp_panic_handler to get controller logs when PC pointer exception crashes.
433+
434+
config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
435+
bool "Enable esp_task_wdt_isr_user_handler implementation"
436+
depends on BT_LE_CONTROLLER_LOG_ENABLED
437+
default n
438+
help
439+
Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered.
440+
441+
config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL
442+
int "The output level of controller log"
443+
depends on BT_LE_CONTROLLER_LOG_ENABLED
444+
range 0 5
445+
default 1
446+
help
447+
The output level of controller log.
448+
449+
config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH
450+
hex "The switch of module log output"
451+
depends on BT_LE_CONTROLLER_LOG_ENABLED
452+
range 0 0xFFFFFFFF
453+
default 0xFFFFFFFF
454+
help
455+
The switch of module log output, this is an unsigned 32-bit hexadecimal value.
456+
427457
config BT_LE_LL_RESOLV_LIST_SIZE
428458
int "BLE LL Resolving list size"
429459
range 1 5

components/bt/controller/esp32c6/bt.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ extern int r_ble_log_deinit_async(void);
120120
extern void r_ble_log_async_select_dump_buffers(uint8_t buffers);
121121
extern void r_ble_log_async_output_dump_all(bool output);
122122
extern void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms);
123+
extern int r_ble_log_ctrl_level_and_mod(uint8_t log_level, uint32_t mod_switch);
124+
extern int r_ble_ctrl_mod_type(uint16_t mod, uint32_t mod_type_switch);
123125
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
124126
extern int r_ble_controller_deinit(void);
125127
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)
269271
}
270272

271273
ret = r_ble_log_init_async(bt_controller_log_interface, task_create, buffers, (uint32_t *)log_bufs_size);
274+
if (ret != ESP_OK) {
275+
return ret;
276+
}
277+
278+
ret = r_ble_log_ctrl_level_and_mod(CONFIG_BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL, CONFIG_BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH);
272279
if (ret == ESP_OK) {
273280
log_is_inited = true;
274281
}
275-
276282
return ret;
277283
}
278284

@@ -406,6 +412,22 @@ void esp_bt_read_ctrl_log_from_flash(bool output)
406412
assert(err == ESP_OK);
407413
}
408414
#endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
415+
416+
#if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
417+
void esp_task_wdt_isr_user_handler(void)
418+
{
419+
esp_ble_controller_log_dump_all(true);
420+
}
421+
#endif // CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
422+
423+
#if CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
424+
void __real_esp_panic_handler(void *info);
425+
void __wrap_esp_panic_handler (void *info)
426+
{
427+
esp_ble_controller_log_dump_all(true);
428+
__real_esp_panic_handler(info);
429+
}
430+
#endif // CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
409431
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
410432

411433
/* This variable tells if BLE is running */

components/bt/controller/esp32h2/Kconfig.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,36 @@ config BT_LE_LOG_HCI_BUF_SIZE
415415
help
416416
Configure the size of the BLE HCI LOG buffer.
417417

418+
config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
419+
bool "Enable wrap panic handler"
420+
depends on BT_LE_CONTROLLER_LOG_ENABLED
421+
default n
422+
help
423+
Wrap esp_panic_handler to get controller logs when PC pointer exception crashes.
424+
425+
config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
426+
bool "Enable esp_task_wdt_isr_user_handler implementation"
427+
depends on BT_LE_CONTROLLER_LOG_ENABLED
428+
default n
429+
help
430+
Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered.
431+
432+
config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL
433+
int "The output level of controller log"
434+
depends on BT_LE_CONTROLLER_LOG_ENABLED
435+
range 0 5
436+
default 1
437+
help
438+
The output level of controller log.
439+
440+
config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH
441+
hex "The switch of module log output"
442+
depends on BT_LE_CONTROLLER_LOG_ENABLED
443+
range 0 0xFFFFFFFF
444+
default 0xFFFFFFFF
445+
help
446+
The switch of module log output, this is an unsigned 32-bit hexadecimal value.
447+
418448
config BT_LE_LL_RESOLV_LIST_SIZE
419449
int "BLE LL Resolving list size"
420450
range 1 5

components/bt/controller/esp32h2/bt.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ extern int r_ble_log_deinit_async(void);
115115
extern void r_ble_log_async_select_dump_buffers(uint8_t buffers);
116116
extern void r_ble_log_async_output_dump_all(bool output);
117117
extern void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms);
118+
extern int r_ble_log_ctrl_level_and_mod(uint8_t log_level, uint32_t mod_switch);
119+
extern int r_ble_ctrl_mod_type(uint16_t mod, uint32_t mod_type_switch);
118120
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
119121
extern int r_ble_controller_deinit(void);
120122
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)
267269
}
268270

269271
ret = r_ble_log_init_async(bt_controller_log_interface, task_create, buffers, (uint32_t *)log_bufs_size);
272+
if (ret != ESP_OK) {
273+
return ret;
274+
}
275+
276+
ret = r_ble_log_ctrl_level_and_mod(CONFIG_BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL, CONFIG_BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH);
270277
if (ret == ESP_OK) {
271278
log_is_inited = true;
272279
}
@@ -403,6 +410,22 @@ void esp_bt_read_ctrl_log_from_flash(bool output)
403410
assert(err == ESP_OK);
404411
}
405412
#endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
413+
414+
#if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
415+
void esp_task_wdt_isr_user_handler(void)
416+
{
417+
esp_ble_controller_log_dump_all(true);
418+
}
419+
#endif // CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
420+
421+
#if CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
422+
void __real_esp_panic_handler(void *info);
423+
void __wrap_esp_panic_handler (void *info)
424+
{
425+
esp_ble_controller_log_dump_all(true);
426+
__real_esp_panic_handler(info);
427+
}
428+
#endif // CONFIG_BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
406429
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
407430

408431
/* This variable tells if BLE is running */
@@ -937,6 +960,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
937960
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "controller_sleep_init failed %d", ret);
938961
goto free_controller;
939962
}
963+
940964
ESP_ERROR_CHECK(esp_read_mac((uint8_t *)mac, ESP_MAC_BT));
941965
ESP_LOGI(NIMBLE_PORT_LOG_TAG, "Bluetooth MAC: %02x:%02x:%02x:%02x:%02x:%02x",
942966
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)
10471071
#if CONFIG_SW_COEXIST_ENABLE
10481072
coex_enable();
10491073
#endif // CONFIG_SW_COEXIST_ENABLE
1074+
10501075
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
10511076
r_ble_ll_scan_start_time_init_compensation(500);
10521077
r_priv_sdk_config_insert_proc_time_set(500);

0 commit comments

Comments
 (0)