Page 1 of 1

Not enough heap memory during esp_wifi_init()

Posted: Fri Mar 03, 2023 2:31 pm
by LucAppelman
I am using a ESP32 project with LVGL. The starting point was the https://github.com/espressif/esp-dev-ki ... ello_world project. I want to add WiFi access point functionality but it appears there is not enough memory available. Decreasing the buffer size of LVGL, or moving it to PSRAM resolves the problem. But this makes the display extremely slow. I printed the amount that is allocated by lvgl, the available memory and largest_free_block to find out if there should be enough memory available. "largest free" is printed right before calling esp_wifi_init().

I don't understand why there is not enough memory available...

Code: Select all

allocating =    48000 bytes
heap free =    2162366
largest free = 2064384
I (2245) wifi:wifi driver task: 3fffbabc, prio:23, stack:6656, core=0
I (2245) system_api: Base MAC address is not set
I (2245) system_api: read default base MAC address from EFUSE
I (2248) wifi:wifi firmware version: 6567a16
I (2248) wifi:wifi certification version: v7.0
I (2249) wifi:config NVS flash: enabled
I (2249) wifi:config nano formating: disabled
I (2249) wifi:Init data frame dynamic rx buffer num: 32
I (2249) wifi:Init management frame dynamic rx buffer num: 32
I (2249) wifi:Init management short buffer num: 32
I (2250) wifi:Init static tx buffer num: 16
I (2251) wifi:Init tx cache buffer num: 32
I (2251) wifi:Init static rx buffer size: 1600
W (2251) wifi:malloc buffer fail
I (2251) wifi:Init static rx buffer num: 6
I (2251) wifi:Init dynamic rx buffer num: 32
E (2252) wifi:Expected to init 10 rx buffer, actual is 6
I (2252) wifi:Deinit lldesc rx mblock:0
I (2252) wifi:Deinit lldesc rx mblock:0
I (2253) wifi:Deinit lldesc rx mblock:0
I (2253) wifi:Deinit lldesc rx mblock:0
I (2254) wifi_init: rx ba win: 6
I (2254) wifi_init: tcpip mbox: 32
I (2254) wifi_init: udp mbox: 6
I (2254) wifi_init: tcp mbox: 6
I (2254) wifi_init: tcp tx win: 5744
I (2254) wifi_init: tcp rx win: 5744
I (2255) wifi_init: tcp mss: 1440
I (2255) wifi_init: WiFi/LWIP prefer SPIRAM
I (2255) wifi_init: WiFi IRAM OP enabled
I (2255) wifi_init: WiFi RX IRAM OP enabled
ESP_ERROR_CHECK failed: esp_err_t 0x101 (ESP_ERR_NO_MEM) at 0x4002e4fc
0x4002e4fc: _esp_error_check_failed at C:/Espressif/frameworks/esp-idf-v4.4.4/components/esp_system/esp_err.c:42

file: "./components/levelz-ap/levelz-ap.cpp" line 43
func: CLevelzAp::CLevelzAp(const char*, const char*)
expression: esp_wifi_init(&cfg)

abort() was called at PC 0x4002e4ff on core 0
0x4002e4ff: _esp_error_check_failed at C:/Espressif/frameworks/esp-idf-v4.4.4/components/esp_system/esp_err.c:43



Backtrace: 0x40025b32:0x3ffd5700 0x4002e509:0x3ffd5720 0x40035ede:0x3ffd5740 0x4002e4ff:0x3ffd57b0 0x40087dbd:0x3ffd57d0 0x4008794e:0x3ffd5960 0x4011c4db:0x3ffd5980 0x40031045:0x3ffd59a0
0x40025b32: panic_abort at C:/Espressif/frameworks/esp-idf-v4.4.4/components/esp_system/panic.c:408

0x4002e509: esp_system_abort at C:/Espressif/frameworks/esp-idf-v4.4.4/components/esp_system/esp_system.c:137

0x40035ede: abort at C:/Espressif/frameworks/esp-idf-v4.4.4/components/newlib/abort.c:46

0x4002e4ff: _esp_error_check_failed at C:/Espressif/frameworks/esp-idf-v4.4.4/components/esp_system/esp_err.c:43

0x40087dbd: CLevelzAp::CLevelzAp(char const*, char const*) at C:/Users/Luc/websites/harmonic-design/levelz-touch/components/levelz-ap/levelz-ap.cpp:43 (discriminator 1)

0x4008794e: app_main at C:/Users/Luc/websites/harmonic-design/levelz-touch/main/main.cpp:44

0x4011c4db: main_task at C:/Espressif/frameworks/esp-idf-v4.4.4/components/freertos/port/port_common.c:141 (discriminator 2)

0x40031045: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v4.4.4/components/freertos/port/xtensa/port.c:142





ELF file SHA256: 03268c16eaf653df

CPU halted.

Re: Not enough heap memory during esp_wifi_init()

Posted: Sat Mar 04, 2023 11:45 am
by MicroController
Some allocations are required to be in internal RAM, possibly also DMA-capable. Check the available heap memory by "capability" (see https://docs.espressif.com/projects/esp ... nformation).
You may want to decide what other data, instead of the LVGL buffer, you want relocate to external RAM to have enough internal RAM available.

Re: Not enough heap memory during esp_wifi_init()

Posted: Tue Mar 07, 2023 7:55 am
by LucAppelman
I solved it by disabling IRAM optimization using the menu config. This should save about 27kb. The specific options disabled are CONFIG_ESP32_WIFI_IRAM_OPT and CONFIG_ESP32_WIFI_RX_IRAM_OPT.