freertos fails to allocate memory and crashes at boot

calint
Posts: 3
Joined: Fri Dec 08, 2023 7:06 pm

freertos fails to allocate memory and crashes at boot

Postby calint » Fri Dec 08, 2023 7:27 pm

chip model: ESP32-D0WD-V3
free heap mem: 228008 B
largest free block: 110580 B

visual code (1.84.2) and platformio (6.1.11)
device: ESP32-2432S028R

when i allocate more than a certain amount of global variables and although the code compiles, builds and gets uploaded it crashes with:

Code: Select all

rst:0xc (SW_CPU_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:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4

assert failed: vApplicationGetIdleTaskMemory port_common.c:194 (pxTCBBufferTemp != NULL)


Backtrace: 0x40083709:0x3ffe3a30 0x400884b1:0x3ffe3a50 0x4008dc21:0x3ffe3a70 0x4008b47f:0x3ffe3ba0 0x4008ad86:0x3ffe3bc0 0x400fbd38:0x3ffe3c00 0x400e1f17:0x3ffe3c20 0x40082e1d:0x3ffe3c50 0x40079306:0x3ffe3c90 |<-CORRUPTED

  #0  0x40083709:0x3ffe3a30 in panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:408
  #1  0x400884b1:0x3ffe3a50 in esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c:137
  #2  0x4008dc21:0x3ffe3a70 in __assert_func at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/assert.c:85
  #3  0x4008b47f:0x3ffe3ba0 in vApplicationGetIdleTaskMemory at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/port_common.c:195 (discriminator 1)
  #4  0x4008ad86:0x3ffe3bc0 in vTaskStartScheduler at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/tasks.c:2279
  #5  0x400fbd38:0x3ffe3c00 in esp_startup_start_app at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/port.c:512
  #6  0x400e1f17:0x3ffe3c20 in start_cpu0_default at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/startup.c:462
  #7  0x40082e1d:0x3ffe3c50 in call_start_cpu0 at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/port/cpu_start.c:630
  #8  0x40079306:0x3ffe3c90 in ?? ??:0
indication is that it fails to allocate memory

should freertos be sure to have that memory reserved and not cause a crash?

could it be the build tool that i use that does not take into account ram reserved for freertos?

right now i am using "malloc" at "setup" to get around the problem

king regards!

RandomInternetGuy
Posts: 52
Joined: Fri Aug 11, 2023 4:56 am

Re: freertos fails to allocate memory and crashes at boot

Postby RandomInternetGuy » Tue Jan 02, 2024 4:39 am

There's not really enough detail there for anyone to give you a definitive answer. malloc() allocates memory at runtime. There's no static tool that can tell how much memory malloc will use.

Code: Select all

allocate_foos(int nfoos) {
  return calloc(sizeof(foo), nfoos);
}
That might be called with a million and it may never be called at all. No tool is going to come along behind your back and tell you to be responsible for ensuring that it's all going to fit. It's up to every caller to decide what to do if malloc() fails. It seems pretty clear that vApplicationGetIdleTaskMemory() is asking for some memory and has decided that if it can't get it, the only sane way to continue is to end it all as no recovery is possible.

If you allocate almost all the memory and the system doesn't have enough left to continue, yes, it's quite reasonable for the system to die.

It's also worth remembering that ESP32s have several different kinds of memory in different places. Some is available to malloc by default and some is available only after you add it. You may have no memory in one pocket - that malloc is looking in - and have a ton of unused memory in another pocket - like PSRAM - that malloc just doesn't know about yet.

https://docs.espressif.com/projects/esp ... 2C%20DROM).

calint
Posts: 3
Joined: Fri Dec 08, 2023 7:06 pm

Re: freertos fails to allocate memory and crashes at boot

Postby calint » Mon May 13, 2024 4:39 pm

I was hoping FreeRTOS would allocate what it needs to always be able to run upfront in the static memory. It probably can be compiled with that option.

Kind regards

Who is online

Users browsing this forum: Bing [Bot] and 83 guests