I'm programming with arduino but i need more stack space
I'm programming with arduino but i need more stack space
Hi at all... I'm new
I'm writing a program with the ARDUINO IDE but i have a problem of stack overflow due to large structures in a library that i use. I don't want change the library because i don't want introduce errors in the code (in particular i need to free() for each malloc()).
I have some questions
1. How can i increase the stack size for my arduino process?
I'm writing a program with the ARDUINO IDE but i have a problem of stack overflow due to large structures in a library that i use. I don't want change the library because i don't want introduce errors in the code (in particular i need to free() for each malloc()).
I have some questions
1. How can i increase the stack size for my arduino process?
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: I'm programming with arduino but i need more stack space
Moving to Arduino subforum.
Re: I'm programming with arduino but i need more stack space
2 options:
- to create a new task and delete default one
- add this in your code
- to create a new task and delete default one
- add this in your code
Code: Select all
#define ARDUINO_LOOP_STACK_SIZE (x * 1024)
Re: I'm programming with arduino but i need more stack space
I've allredy used
but it did not worked.
I'll try even
But there is a manual or a list of API to understand these variables? I mean where are defined these definitions?
==============================================================
But i'm intrested to understand how i can create a (new task with the stack size) because i'll use in the future.
Do you have any suggestion/link/starting point?
===============================================================
Many thanks
Code: Select all
size_t getArduinoLoopTaskStackSize() {
return 32 * 1024; // bytes
}
I'll try even
Code: Select all
#define ARDUINO_LOOP_STACK_SIZE (x * 1024)
==============================================================
But i'm intrested to understand how i can create a (new task with the stack size) because i'll use in the future.
Do you have any suggestion/link/starting point?
===============================================================
Many thanks
-
- Posts: 828
- Joined: Mon Jul 22, 2019 3:20 pm
Re: I'm programming with arduino but i need more stack space
Arduino IDE provides no way to modify defines before Arduino.h is included. It is intended for use by people that don't want any of that complexity, so it hides it. In platform.io or Arduino CLI, you can use the defines to change the stack size.
Code: Select all
void newloop(void* param) {
while(1) {
delay(10000);
Serial.printf("memtask: %d\n", uxTaskGetStackHighWaterMark(NULL));
}
}
void setup() {
Serial.begin(115200);
xTaskCreateUniversal(newloop,"newloop", 32*1024, NULL, 1, NULL, ARDUINO_RUNNING_CORE);
vTaskDelete(NULL);
}
void loop() {}
Re: I'm programming with arduino but i need more stack space
Hi, I’ve tried the function that you have told me. In particular i’ve tried this code:
The output is 64200, that is correct. But i need MORE than 64k of stack. I need around 350k,
Do you know why when i use the xTaskCreateUniversal(newloop,“newloop”, x*1024, NULL, 1, NULL, ARDUINO_RUNNING_CORE); with x>64 the output is <64k?
Many thanks
Code: Select all
void newloop(void* param) {
while(1) {
delay(10000);
Serial.printf("memtask: %d\n", uxTaskGetStackHighWaterMark(NULL));
}
}
void setup() {
Serial.begin(115200);
xTaskCreateUniversal(newloop,"newloop", 64*1024, NULL, 1, NULL, ARDUINO_RUNNING_CORE);
vTaskDelete(NULL);
}
void loop() {}
Do you know why when i use the xTaskCreateUniversal(newloop,“newloop”, x*1024, NULL, 1, NULL, ARDUINO_RUNNING_CORE); with x>64 the output is <64k?
Many thanks
-
- Posts: 828
- Joined: Mon Jul 22, 2019 3:20 pm
Re: I'm programming with arduino but i need more stack space
Raspberry Pi 3 costs about $30. I don't think you are looking for a MCU.
Re: I'm programming with arduino but i need more stack space
Not sure if this works for other MCUs, but it works for ESP32-S3. Put this at the beginning of your sketch (increase size if needed)
SET_LOOP_TASK_STACK_SIZE(16 * 1024); // 16KB
SET_LOOP_TASK_STACK_SIZE(16 * 1024); // 16KB
-
- Posts: 94
- Joined: Tue Sep 07, 2021 12:07 pm
Re: I'm programming with arduino but i need more stack space
the parameter is a 16 bit int. I'm not sure you'll find 350K of contiguous memory for a stack.Do you know why when i use the xTaskCreateUniversal(newloop,“newloop”, x*1024, NULL, 1, NULL, ARDUINO_RUNNING_CORE); with x>64 the output is <64k?
Code: Select all
#ifndef configSTACK_DEPTH_TYPE
/* Defaults to uint16_t for backward compatibility, but can be overridden
in FreeRTOSConfig.h if uint16_t is too restrictive. */
#define configSTACK_DEPTH_TYPE uint16_t
#endif
Craige
Re: I'm programming with arduino but i need more stack space
The replies all address increasing stack size. I suggest a different approach: define the problem the code as a whole is to solve then consider the various solutions and their data structures.
And answer: what data structures besides a stack can be used.
Tom Meyers
And answer: what data structures besides a stack can be used.
Tom Meyers
IT Professional, Maker
Santiago, Dominican Republic
Santiago, Dominican Republic
Who is online
Users browsing this forum: No registered users and 152 guests