Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32使用blufi配网,当调用esp_blufi_controller_deinit后再次调用esp_blufi_controller_init会发生coredump (IDFGH-14085) #14898

Closed
3 tasks done
lipan465 opened this issue Nov 16, 2024 · 3 comments
Assignees
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@lipan465
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.2.2

Espressif SoC revision.

ESP32

Operating System used.

Windows

How did you build your project?

Command line with Make

If you are using Windows, please specify command line type.

None

Development Kit.

esp-idf-v5.2.2

Power Supply used.

USB

What is the expected behavior?

ESP32使用blufi配网,当调用esp_blufi_controller_deinit后再次调用esp_blufi_controller_init会发生coredump

What is the actual behavior?

ESP32使用blufi配网,当调用esp_blufi_controller_deinit后再次调用esp_blufi_controller_init会发生coredump

Steps to reproduce.

ESP32使用blufi配网,当调用esp_blufi_controller_deinit后再次调用esp_blufi_controller_init会发生coredump;
出问题的代码如下

`static esp_err_t esp_bt_controller_rom_mem_release(esp_bt_mode_t mode)
{
bool update = true;
intptr_t mem_start=(intptr_t) NULL, mem_end=(intptr_t) NULL;

if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
    return ESP_ERR_INVALID_STATE;
}

//already released
if (!(mode & btdm_dram_available_region[0].mode)) {
    return ESP_ERR_INVALID_STATE;
}`

当已经调用过released就会返回失败,然后
esp_err_t esp_blufi_controller_init() {
esp_err_t ret = ESP_OK;
#if CONFIG_IDF_TARGET_ESP32
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
#endif
这里就会coredump;请优化;

反观esp32C3的实现就没有问题
`esp_err_t esp_bt_controller_rom_mem_release(esp_bt_mode_t mode)
{
esp_err_t ret = ESP_OK;

if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
    return ESP_ERR_INVALID_STATE;
}

bt_area_t rom_btdm_data = {
    .start = (intptr_t) ets_rom_layout_p->data_start_btdm,
    .end   = (intptr_t) ets_rom_layout_p->data_end_btdm,
    .name  = "ROM btdm data",
};
bt_area_t rom_btdm_bss = {
    .start = (intptr_t)ets_rom_layout_p->bss_start_btdm,
    .end   = (intptr_t)ets_rom_layout_p->bss_end_btdm,
    .name  = "ROM btdm BSS",
};
bt_area_t rom_btdm_inter_data = {
    .start = (intptr_t) ets_rom_layout_p->data_start_interface_btdm,
    .end   = (intptr_t) ets_rom_layout_p->data_end_interface_btdm,
    .name  = "ROM interface btdm data",
};
bt_area_t rom_btdm_inter_bss = {
    .start = (intptr_t)ets_rom_layout_p->bss_start_interface_btdm,
    .end   = (intptr_t)ets_rom_layout_p->bss_end_interface_btdm,
    .name  = "ROM interface btdm BSS",
};

if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
    ret = ESP_ERR_INVALID_STATE;
}

if (mode & ESP_BT_MODE_BLE) {
    /* Free BTDM memory used by the ROM */
    if (ret == ESP_OK) {
        ret = esp_bt_mem_release_areas(&rom_btdm_data, &rom_btdm_bss);
    }

    if (ret == ESP_OK) {
        ret = esp_bt_mem_release_areas(&rom_btdm_inter_data, &rom_btdm_inter_bss);
    }
}

return ret;

}` 他这个如果if (mode & ESP_BT_MODE_BLE) 为false的时候直接返回OK

Debug Logs.

1

More Information.

1

@lipan465 lipan465 added the Type: Bug bugs in IDF label Nov 16, 2024
@github-actions github-actions bot changed the title ESP32使用blufi配网,当调用esp_blufi_controller_deinit后再次调用esp_blufi_controller_init会发生coredump ESP32使用blufi配网,当调用esp_blufi_controller_deinit后再次调用esp_blufi_controller_init会发生coredump (IDFGH-14085) Nov 16, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Nov 16, 2024
@esp-zhp
Copy link
Collaborator

esp-zhp commented Nov 19, 2024

1-问题出现原因
实际上 esp_bt_controller_mem_release 调用一次就好了,后面再调用该 API 的时候会返回错误,
返回错误的原因是该 API 已经被调用过了,相关的内存已经被释放。

2-解决办法
保证下面 API 只会被调用一次

#if CONFIG_IDF_TARGET_ESP32
    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
#endif

你可以将该 API 从 esp_blufi_controller_init 函数移出来。

@espressif-bot espressif-bot added Status: In Progress Work is in progress Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Opened Issue is new Status: In Progress Work is in progress labels Nov 19, 2024
@esp-zhp
Copy link
Collaborator

esp-zhp commented Nov 22, 2024

fixed in master 7addb57,will sync to GitHub
image

@Alvin1Zhang
Copy link
Collaborator

Thanks for sharing, fix on release/5.2 is available at aabe255, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

4 participants