In a recent project I noticed my board resets after 18 touch events/processes.
Basically I use Makerfabs-ESP32-S3-SPI-TFT-with-Touch board and a mixed bag of example code to produce a Macro Keyboard.
It works perfectly for about 18 button(touch) presses but then resets (I run out of Stack). Chances are it's my code but...
I found example code to show how much stack was used/remained. I put the code before and after suspect function call to print Stack used for that process. For example, the first call to load and display a menu/bmp uses over 1k, each call thereafter uses about an additional 200 bytes... nothing appeared to pop the data off the stack...
Does the compiler pop after a function call or does the code need to do the house keeping?
How would I examine the stack to see what was pushed to it? (knowing this might point me in the right direction)...
Any help appreciated....
Mike
Stack issue
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Stack issue
Are you sure that code doesn't simply show the stack high point (that is, the maximum of stack ever used?)MichaelOToole wrote: ↑Mon Sep 11, 2023 12:53 pmI found example code to show how much stack was used/remained.
-
- Posts: 4
- Joined: Mon Sep 11, 2023 11:57 am
Re: Stack issue
I have changed it a little, here's the code...
I didn't check what the code actually reports, I just assumed as if uses StackPtrEnd = StackPtrAtStart - watermarkStart...
I best take a closer look...
The full code can be seen here: https://github.com/phpbbireland/3x5_tou ... stCode.ino
Code: Select all
void printStack(char *mytxt)
{
char *SpStart = NULL;
char *StackPtrAtStart = (char *)&SpStart;
UBaseType_t watermarkStart = uxTaskGetStackHighWaterMark(NULL);
char *StackPtrEnd = StackPtrAtStart - watermarkStart;
if(stacktot == 0) { stackori = stacktot = (uint32_t)StackPtrAtStart - (uint32_t)StackPtrEnd; }
stackrun += (uint32_t)stacktot - ((uint32_t)StackPtrAtStart - (uint32_t)StackPtrEnd);
Serial.printf("Free Stack near previous: %d, now: %d,", stackori, (uint32_t)StackPtrAtStart - (uint32_t)StackPtrEnd);
Serial.printf(" this loop [%d] used: %4d, total stack used:%4d (%s)\r\n", loopcount++, (uint32_t)stacktot - ((uint32_t)StackPtrAtStart - (uint32_t)StackPtrEnd), stackrun, mytxt);
stacktot = (uint32_t)StackPtrAtStart - (uint32_t)StackPtrEnd;
}
I best take a closer look...
The full code can be seen here: https://github.com/phpbbireland/3x5_tou ... stCode.ino
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Stack issue
uxTaskGetStackHighWaterMark indeed returns the largest amount of stack the task ever used, at this moment or anywhere in the past. So you would not expect the number that this returns ever to go down.
-
- Posts: 1707
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Stack issue
The problem is that you have an infinite recursion in your code:each call thereafter uses about an additional 200 bytes... nothing appeared to pop the data off the stack...
setFileNames -> processMenu -> processMenuLine -> setFileNames -> ...
-
- Posts: 4
- Joined: Mon Sep 11, 2023 11:57 am
Re: Stack issue
To be honest, I did suspect something on those lines, it makes perfect sense but, I haven't coded in years and had convinced myself is was something to do with string manipulation, or my lack of knowledge of modern coding techniques, or the Cat...
Many thanks, I will fix it...
Mike
Many thanks, I will fix it...
Mike
-
- Posts: 4
- Joined: Mon Sep 11, 2023 11:57 am
Re: Stack issue
All fixed, many thanks MicroController...
Now to make it useful...
Now to make it useful...
-
- Posts: 1707
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Stack issue
Good luck with your project
Who is online
Users browsing this forum: username and 130 guests