fix(ble): Fixed BLE assert in "emi.c" when low memory

(cherry picked from commit e3aac6f703)

Co-authored-by: zhanghaipeng <zhanghaipeng@espressif.com>
This commit is contained in:
Zhang Hai Peng
2026-03-23 17:53:17 +08:00
parent a7d6fb261d
commit 2ff071aef3
2 changed files with 27 additions and 17 deletions
+15 -11
View File
@@ -1692,32 +1692,31 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
ESP_LOGI(BTDM_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version()); ESP_LOGI(BTDM_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version());
s_wakeup_req_sem = semphr_create_wrapper(1, 0);
if (s_wakeup_req_sem == NULL) {
err = ESP_ERR_NO_MEM;
goto error;
}
esp_phy_modem_init(); esp_phy_modem_init();
esp_bt_power_domain_on(); esp_bt_power_domain_on();
btdm_controller_mem_init(); btdm_controller_mem_init();
/* Must call periph_module_enable(BT) before any step that may goto error,
* otherwise bt_controller_deinit_internal() will call periph_module_disable(BT)
* when ref is still 0, causing ref underflow (0-1=255) and subsequent
* init/enable failures (EM BASE MISMATCH, BLE assert, etc.) */
periph_module_enable(PERIPH_BT_MODULE); periph_module_enable(PERIPH_BT_MODULE);
periph_module_reset(PERIPH_BT_MODULE); periph_module_reset(PERIPH_BT_MODULE);
s_wakeup_req_sem = semphr_create_wrapper(1, 0);
if (s_wakeup_req_sem == NULL) {
err = ESP_ERR_NO_MEM;
goto error;
}
#if CONFIG_BTDM_CTRL_HCI_UART_FLOW_CTRL_EN #if CONFIG_BTDM_CTRL_HCI_UART_FLOW_CTRL_EN
sdk_config_set_uart_flow_ctrl_enable(true); sdk_config_set_uart_flow_ctrl_enable(true);
#else #else
sdk_config_set_uart_flow_ctrl_enable(false); sdk_config_set_uart_flow_ctrl_enable(false);
#endif #endif
if ((err = btdm_low_power_mode_init()) != ESP_OK) {
ESP_LOGE(BTDM_LOG_TAG, "Low power module initialization failed");
goto error;
}
#if CONFIG_SW_COEXIST_ENABLE #if CONFIG_SW_COEXIST_ENABLE
coex_init(); coex_init();
#endif #endif
@@ -1738,6 +1737,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#endif /* CONFIG_BLE_LOG_ENABLED */ #endif /* CONFIG_BLE_LOG_ENABLED */
if ((err = btdm_low_power_mode_init()) != ESP_OK) {
ESP_LOGE(BTDM_LOG_TAG, "Low power module initialization failed");
goto error;
}
btdm_cfg_mask = btdm_config_mask_load(); btdm_cfg_mask = btdm_config_mask_load();
err = btdm_controller_init(btdm_cfg_mask, cfg); err = btdm_controller_init(btdm_cfg_mask, cfg);
+12 -6
View File
@@ -1868,15 +1868,18 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
ESP_LOGI(BT_LOG_TAG,"Put all controller code in flash"); ESP_LOGI(BT_LOG_TAG,"Put all controller code in flash");
#endif #endif
if ((err = btdm_low_power_mode_init(cfg)) != ESP_OK) {
ESP_LOGE(BT_LOG_TAG, "Low power module initialization failed");
goto error;
}
#if CONFIG_SW_COEXIST_ENABLE #if CONFIG_SW_COEXIST_ENABLE
coex_init(); coex_init();
#endif #endif
/* Must call periph_module_enable(BT) before any step that may goto error,
* otherwise bt_controller_deinit_internal() will call periph_module_disable(BT)
* when ref is still 0, causing ref underflow (0-1=255) and subsequent
* init/enable failures (EM BASE MISMATCH, BLE assert, etc.) */
periph_module_enable(PERIPH_BT_MODULE);
periph_module_reset(PERIPH_BT_MODULE);
#if CONFIG_BLE_LOG_ENABLED #if CONFIG_BLE_LOG_ENABLED
if (!ble_log_init()) { if (!ble_log_init()) {
ESP_LOGE(BT_LOG_TAG, "BLE Log v2 init failed"); ESP_LOGE(BT_LOG_TAG, "BLE Log v2 init failed");
@@ -1893,8 +1896,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#endif /* CONFIG_BLE_LOG_ENABLED */ #endif /* CONFIG_BLE_LOG_ENABLED */
periph_module_enable(PERIPH_BT_MODULE); if ((err = btdm_low_power_mode_init(cfg)) != ESP_OK) {
periph_module_reset(PERIPH_BT_MODULE); ESP_LOGE(BT_LOG_TAG, "Low power module initialization failed");
goto error;
}
#if CONFIG_BT_CTRL_LE_LOG_EN #if CONFIG_BT_CTRL_LE_LOG_EN
err = esp_bt_controller_log_init(log_output_mode); err = esp_bt_controller_log_init(log_output_mode);