Unable to use the whole memory in ESP32 with Arduino

gchini
Posts: 18
Joined: Wed Jun 08, 2022 1:41 pm

Unable to use the whole memory in ESP32 with Arduino

Postby gchini » Fri Sep 29, 2023 5:39 am

Hi,

I have a problem in the amout of memory allocated in my esp32

Basically i want use the Whole potentiality of my esp32 in particular the whole memory about 400k. I chosed ESP32 for this reason. I've tried it on the Raspberry PI Pico W and it works well but i want change platform because esp is cheaper.

The problem is that when I'm calling a function that calls other functions it gives me the error "***ERROR*** A stack overflow in task newloop has been detected."

I've investigated the reason and i putted in my program the follow code:

Code: Select all

void newloop(void* param) {
  //MY CODE
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  xTaskCreateUniversal(newloop,"newloop", 32*1024, NULL, 1, NULL, ARDUINO_RUNNING_CORE);
  vTaskDelete(NULL);
}

void loop() {}
But unsucessfully, the error stil appear.

I qant higllight that my code soes not user dynamic allocation and all variables and structures are allocated directly in the stack statically,

What i can do?

andpet
Posts: 2
Joined: Thu Sep 28, 2023 6:07 pm

Re: Unable to use the whole memory in ESP32 with Arduino

Postby andpet » Sat Sep 30, 2023 6:26 am

Increase the 32*1024 argument or change your large allocations from the stack to static allocations.
You can also switch to xTaskCreateStatic() to allocate the task stack at compile-time. It doesn't change how much memory is available but it does show already at compile-time how much RAM is used instead of waiting until the program crashes.

MicroController
Posts: 1699
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Unable to use the whole memory in ESP32 with Arduino

Postby MicroController » Sat Sep 30, 2023 5:39 pm

"***ERROR*** A stack overflow in task newloop has been detected."
all variables and structures are allocated directly in the stack statically,

What i can do?
viewtopic.php?f=13&t=35960#p121185
Don't use the stack/local variables for all your memory needs. Use globals or heap memory.

Who is online

Users browsing this forum: taherrera and 99 guests