-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Esp.getFreeSysStack #5148
Comments
There are two stacks in play: the OS one (sys) and the Arduino core one (cont). Callbacks from the OS will be on the OS stack, so "getStackFree()' is not valid and will report nonsense values when called from a callback. Since this is a CB, I think you're getting an invalid result and it's not indicative of any problem here. |
Didn't know there are two stacks. So probably most of my code is executing in OS stack since it's implemented in callbacks. What is the size limit for OS stack? I know Arduino core stack is 4kb. Also any way to get current free space of OS stack? |
The way stacks are done now, the Arduino one is actually allocated from the OS stack, so I'm not sure there's one fool-proof way of getting the free stack if you don't know if you're in the OS or in the app. @d-a-v may have a better way, but if you know you're in the OS then there I believe the stack limit is going to be 0x3FFFC000, and you can subtract |
@toomasz I currently have no better way. The API now includes Remember we are not in a multitasking environment, so our sketches should be state-machines and callbacks should be minimal - at best only used for setting some global variables that the main loop examines. |
Created PR with
In my case its problematic, my library is using async-mqtt-client which is based on ESPAsyncTCP which is using lwip. So probably all callback from mqtt library are fired on OS sys if I'm not wrong. |
Why would those queues be allocated on the stack? I am really interested in this, since I am convinced the random reboots seen at our project (ESPeasy) may be related to stack usage. |
@TD-er There are 2 stacks: the sys and cont. The sys is used by the sdk, and is als the one in use in certain callbacks, like Ticker. The cont is the one used in our Arduino setup() and loop(), as well as all functions called from them. If you're using other sdk functionality similar to wps, it's possible that you're running into the same problem as that case, and the optimization needs to be disabled for your project. @d-a-v is there a way to manually disable the stack optimization for testing? |
|
As suggested [here](letscontrolit#1858 (comment)) the previous used flag may also enable WPS. So I used [this suggestion](esp8266/Arduino#5148 (comment)) to only re-allocate the stack at link time.
This issue was originally named Stack usage in WiFi.onStationModeGotIP too high, probably overflow
Below original report showing my wrong understanding of ESP internals
Basic Infos
Platform
Settings in IDE
Problem Description
I was experiencing random crashes in my project which is using ESPAsyncTCP and async-mqtt-library so i decided to check stack usage in event handlers on mqtt library, especially in publish received. Found out that free stack size is below zero. I was getting results like current free stack = -4000
I also checked stack usage in onStationModeGotIP event handler and saw free stack is below zero.
Im not sure if this method of measuring free stack is good enough. In setup method is shows areound 4Kb of free stack which seems to be correct.
Is it a bug? Does 'negative' free stack means that stack overlaps with heap region?
MCVE Sketch
Debug Messages
The text was updated successfully, but these errors were encountered: