Page 1 of 1

Unable to use the whole memory in ESP32 with Arduino

Posted: Fri Sep 29, 2023 5:39 am
by gchini
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?

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

Posted: Sat Sep 30, 2023 6:26 am
by andpet
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.

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

Posted: Sat Sep 30, 2023 5:39 pm
by MicroController
"***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.