Unable to flash code on to ESP32 - Memory allocation failed error

karunt
Posts: 93
Joined: Sat Apr 03, 2021 7:58 am

Unable to flash code on to ESP32 - Memory allocation failed error

Postby karunt » Thu Apr 28, 2022 7:15 pm

Trying to flash my program on ESP32 and get the following error:

Code: Select all

I (800) spiffs: Initializing SPIFFS
I (890) spiffs: Partition size: total: 896321, used: 0
I (1370) wifi:wifi driver task: 3ffd2a90, prio:23, stack:6656, core=0
I (1370) system_api: Base MAC address is not set
I (1370) system_api: read default base MAC address from EFUSE
I (1420) wifi:wifi firmware version: 1865b55
I (1420) wifi:wifi certification version: v7.0
I (1420) wifi:config NVS flash: enabled
I (1420) wifi:config nano formating: disabled
I (1430) wifi:Init data frame dynamic rx buffer num: 32
I (1430) wifi:Init management frame dynamic rx buffer num: 32
I (1440) wifi:Init management short buffer num: 32
I (1440) wifi:Init dynamic tx buffer num: 32
I (1450) wifi:Init static rx buffer size: 1600
I (1450) wifi:Init static rx buffer num: 10
I (1450) wifi:Init dynamic rx buffer num: 32
I (1460) wifi_init: rx ba win: 6
I (1460) wifi_init: tcpip mbox: 32
I (1470) wifi_init: udp mbox: 6
I (1470) wifi_init: tcp mbox: 6
I (1470) wifi_init: tcp tx win: 5744
I (1480) wifi_init: tcp rx win: 5744
I (1480) wifi_init: tcp mss: 1440
I (1490) wifi_init: WiFi IRAM OP enabled
I (1490) wifi_init: WiFi RX IRAM OP enabled
I (1500) wifi_prov_mgr: execute_event_cb : 0
I (1500) wifi_prov_scheme_ble: BT memory released
I (1510) wifi_prov_mgr: scheme cb: 0
I (1510) wifi_provision: Starting provisioning
I (1510) wifi_provision: service name is: EZZLE_01234
I (1520) wifi_provision: Starting wifi_prov_scheme_ble_set_service_uuid from app.c and set_config_service from scheme_ble.c
W (1540) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (1680) phy: phy_version: 4500, 0cd6843, Sep 17 2020, 15:37:07, 0, 2
I (1700) wifi:mode : sta (8c:aa:b5:b5:72:04)
I (1700) wifi_prov_scheme_ble: Starting set_config_service from scheme_ble.c
I (1700) wifi_prov_mgr: Starting provisioning service from manager.c
I (1710) wifi_prov_scheme_ble: Starting provisioning service from scheme_ble.c
I (1720) protocomm_ble: Starting protocomm_ble_start service from protocomm_ble.c
I (1730) BTDM_INIT: BT controller compile version [3723d5b]

Memory allocation failed

Backtrace:0x4008eff3:0x3ffd9530 0x4008f515:0x3ffd9550 0x400d38bb:0x3ffd9570 0x40081356:0x3ffd9590 0x40081371:0x3ffd95b0 0x40096118:0x3ffd95d0 0x4009613c:0x3ffd95f0 0x40105178:0x3ffd9610 0x4010544c:0x3ffd9670 0x400e1fac:0x3ffd96b0 0x400e24d7:0x3ffd96d0 0x400e2580:0x3ffd96f0 0x40104515:0x3ffd9720 0x401065f1:0x3ffd9740 0x4008f51d:0x3ffd9760

0x4008eff3: panic_abort at C:/Users/Prog/ESP/esp-idf/components/esp_system/panic.c:330
0x4008f515: esp_system_abort at C:/Users/Prog/ESP/esp-idf/components/esp_system/system_api.c:106
0x400d38bb: heap_caps_alloc_failed at C:/Users/Prog/ESP/esp-idf/components/heap/heap_caps.c:67
0x40081356: heap_caps_malloc at C:/Users/Prog/ESP/esp-idf/components/heap/heap_caps.c:155
0x40081371: heap_caps_malloc_default at C:/Users/Prog/ESP/esp-idf/components/heap/heap_caps.c:177
0x40096118: _calloc_r at C:/Users/Prog/ESP/esp-idf/components/newlib/heap.c:73
0x4009613c: calloc at C:/Users/Prog/ESP/esp-idf/components/newlib/heap.c:37
0x40105178: config_parse at C:/Users/Prog/ESP/esp-idf/components/bt/common/osi/config.c:553
0x4010544c: config_new at C:/Users/Prog/ESP/esp-idf/components/bt/common/osi/config.c:105
0x400e1fac: btc_config_init at C:/Users/Prog/ESP/esp-idf/components/bt/host/bluedroid/btc/core/btc_config.c:74
0x400e24d7: btc_init_bluetooth at C:/Users/Prog/ESP/esp-idf/components/bt/host/bluedroid/btc/core/btc_main.c:66
0x400e2580: btc_main_call_handler at C:/Users/Prog/ESP/esp-idf/components/bt/host/bluedroid/btc/core/btc_main.c:114
0x40104515: btc_thread_handler at C:/Users/Prog/ESP/esp-idf/components/bt/common/btc/core/btc_task.c:155
0x401065f1: osi_thread_run at C:/Users/Prog/ESP/esp-idf/components/bt/common/osi/thread.c:68
0x4008f51d: vPortTaskWrapper at C:/Users/Prog/ESP/esp-idf/components/freertos/xtensa/port.c:143
ELF file SHA256: 34316b95d76b8a00
CPU halted.
Here's my partitions.cv file:

Code: Select all

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1300000,
storage,  data, spiffs,  ,        0xF0000,
Here's my code in main.c

Code: Select all

void app_main(void)
{
    spiffs_start();
    wifi_provision();
    http_start();
}
spiffs_start code:

Code: Select all

void spiffs_start(void)
{
    ESP_LOGI(TAG, "Initializing SPIFFS");
    
    esp_vfs_spiffs_conf_t conf = {
      .base_path = "/spiffs",
      .partition_label = NULL,
      .max_files = 5,
      .format_if_mount_failed = true
    };
    
    // Use settings defined above to initialize and mount SPIFFS filesystem.
    // Note: esp_vfs_spiffs_register is an all-in-one convenience function.
    esp_err_t ret = esp_vfs_spiffs_register(&conf);

    if (ret != ESP_OK) {
        if (ret == ESP_FAIL) {
            ESP_LOGE(TAG, "Failed to mount or format filesystem");
        } else if (ret == ESP_ERR_NOT_FOUND) {
            ESP_LOGE(TAG, "Failed to find SPIFFS partition");
        } else {
            ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
        }
        return;
    }
    
    size_t total = 0, used = 0;
    ret = esp_spiffs_info(conf.partition_label, &total, &used);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
    } else {
        ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
    }
}
wifi_provision code is taken straight from the wifi_provisioning manager code in esp/esp-idf/examples/provisioning/wifi_prov_mgr. I think this is where my code is failing - where it attempts to start protocomm_ble from protocomm_ble.c. Any suggestions on how to debug what the problem might be? When I run the wifi_provisioning example stand alone, it works perfectly fine. But importing the code into a new program which combines spiffs creates this issue. I have to admit, I don't understand a whole lot about how to create partitions in partitions.csv.

hustenhabas
Posts: 18
Joined: Tue Sep 14, 2021 2:18 pm

Re: Unable to flash code on to ESP32 - Memory allocation failed error

Postby hustenhabas » Thu Apr 28, 2022 7:57 pm

im not familiar with spiffs but should'n the partition_label struct field be the name of the partition you created? and are you sure you changed your sdkconfig partition table option to Custom partition table?

karunt
Posts: 93
Joined: Sat Apr 03, 2021 7:58 am

Re: Unable to flash code on to ESP32 - Memory allocation failed error

Postby karunt » Thu Apr 28, 2022 9:15 pm

Yes, sdkconfig partition table option (CONFIG_PARTITION_TABLE_CUSTOM) is set to "y".

Don't understand your comment "shouldn't the partition_label struct field be the name of the partition you created" Can you please elaborate or point out where in my code you see a potential issue related to this? Thanks.

hustenhabas
Posts: 18
Joined: Tue Sep 14, 2021 2:18 pm

Re: Unable to flash code on to ESP32 - Memory allocation failed error

Postby hustenhabas » Fri Apr 29, 2022 4:50 pm

karunt wrote:
Thu Apr 28, 2022 9:15 pm
Yes, sdkconfig partition table option (CONFIG_PARTITION_TABLE_CUSTOM) is set to "y".

Don't understand your comment "shouldn't the partition_label struct field be the name of the partition you created" Can you please elaborate or point out where in my code you see a potential issue related to this? Thanks.
Ignore what i said earlier, i think your problem is on bluetooth. Can you post the code you're using to initialize Bluetooth?

karunt
Posts: 93
Joined: Sat Apr 03, 2021 7:58 am

Re: Unable to flash code on to ESP32 - Memory allocation failed error

Postby karunt » Fri Apr 29, 2022 7:58 pm

Figured my issue out. It was a Bluetooth Nimble setting in menuconfig. Enabling BT Nimble solved my problem. At least the code compiles and am able to flash it to the ESP32 chip. But now I'm running into a separate issue. Upon flashing my code, I get the following error message:

Code: Select all

SPIFFS: failed to erase addr xxxxxxxx; size 00001000, err 258
where xxxxxxxx ranges from 00000000 to 000ef000
THis is followed by

Code: Select all

SPIFFS: mount failed, -10025
I have a feeling this might have something to do with the way my partitions.csv file is structured, but not sure. Here's how my partitions.csv file is structured:

Code: Select all

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1300000,
storage,  data, spiffs,  ,        0xF0000, 
How do I make sure my factory partition is the appropriate size?

If this error is not related to the partitions.csv structure/partition allocations, then what could be causing it?

karunt
Posts: 93
Joined: Sat Apr 03, 2021 7:58 am

Re: Unable to flash code on to ESP32 - Memory allocation failed error

Postby karunt » Sun May 01, 2022 3:29 pm

Figured the final issue out too. Problem was with my partitions.csv file. Storage partition needs an explicit offset value. When set at 1300000 (the size value of the factory partition right before), error disappears.

Who is online

Users browsing this forum: Michaelboeding and 50 guests