joint work of BLE and erasing operations of flash memory

Dimych
Posts: 13
Joined: Tue Feb 05, 2019 6:09 am

joint work of BLE and erasing operations of flash memory

Postby Dimych » Sat Jun 12, 2021 9:26 am

Hi,
please tell me how you can solve the problem:
after BLE initialization, the esp_partition_erase_range function stops working
the program just freezes and the WDT is triggered ((
if you do not turn on bluetooth, everything works fine...
Used ESP-IDF v4.2.1 and module ESP32-WROVER-B, PSRAM enabled

restart log after trying to erase a block

Code: Select all

ets Jun  8 2016 00:22:57

rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4
load:0x3fff0034,len:7368
load:0x40078000,len:14368
ho 0 tail 12 room 4
load:0x40080400,len:5360
0x40080400: _init at ??:?

entry 0x40080710
I (183) boot: ESP-IDF v4.2.1-dirty 2nd stage bootloader
I (183) boot: compile time 13:40:36
I (184) boot: chip revision: 1
I (188) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (195) qio_mode: Enabling default flash chip QIO
I (200) boot.esp32: SPI Speed      : 80MHz
I (205) boot.esp32: SPI Mode       : QIO
I (210) boot.esp32: SPI Flash Size : 4MB
W (214) boot.esp32: PRO CPU has been reset by WDT.
W (220) boot.esp32: WDT reset info: PRO CPU PC=0x400803c3
0x400803c3: _DoubleExceptionVector at C:/esp/esp-idf/components/freertos/xtensa/xtensa_vectors.S:457

W (226) boot.esp32: WDT reset info: APP CPU PC=0x40096209
0x40096209: panic_handler at C:/esp/esp-idf/components/esp_system/port/panic_handler.c:496 (discriminator 3)

init BLE

Code: Select all

esp_err_t ret;

    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));

    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    ret = esp_bt_controller_init(&bt_cfg);
    if (ret) {
        ESP_LOGE(ESP_NEDAP_TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret));
        return;
    }

    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
    if (ret) {
        ESP_LOGE(ESP_NEDAP_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    ret = esp_bluedroid_init();
    if (ret) {
        ESP_LOGE(ESP_NEDAP_TAG, "%s init bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    ret = esp_bluedroid_enable();
    if (ret) {
        ESP_LOGE(ESP_NEDAP_TAG, "%s enable bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    ret = esp_ble_gatts_register_callback(gatts_event_handler);
    if (ret){
        ESP_LOGE(ESP_NEDAP_TAG, "gatts register error, error code = %x", ret);
        return;
    }
    ret = esp_ble_gap_register_callback(gap_event_handler);
    if (ret){
        ESP_LOGE(ESP_NEDAP_TAG, "gap register error, error code = %x", ret);
        return;
    }
    ret = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
    if (ret){
        ESP_LOGE(ESP_NEDAP_TAG, "gatts app register error, error code = %x", ret);
        return;
    }
    esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
    if (local_mtu_ret){
        ESP_LOGE(ESP_NEDAP_TAG, "set local  MTU failed, error code = %x", local_mtu_ret);
    }
if you comment out line ret = esp_ble_gatts_app_register(PROFILE_A_APP_ID); - then erasing the flash works

erase function

Code: Select all

const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "keys");
assert(partition != NULL);
esp_partition_erase_range(partition, 0, SPI_FLASH_SEC_SIZE)

Dimych
Posts: 13
Joined: Tue Feb 05, 2019 6:09 am

Re: joint work of BLE and erasing operations of flash memory

Postby Dimych » Sat Jun 12, 2021 8:38 pm

I like this forum, I asked myself, - I answered myself :-)

Helps stop advertising with a pause before the erase operation...

Code: Select all

void enabled_ble_adv(void)
{
    esp_ble_gap_start_advertising(&adv_params);
}
//-----------------------------------------------------------------------------------

void disabled_ble_adv(void)
{
    esp_ble_gap_stop_advertising();
    vTaskDelay(1 / portTICK_PERIOD_MS);
}

Who is online

Users browsing this forum: No registered users and 107 guests