Chat freely about anything...

User avatar
By eriksl
#82847 It's quite an easy way, although not terribly accurate:

- the SDK code already allocates quite a bit of space on the stack, before it starts running your code (or Aduino, for that matter), > 300 bytes
- this method does not give a historic insight in stack usage. If at any point a huge amount of data is allocated on the stack, maybe such an amount that the memory below the stack gets overwritten, and the stack pointer is restored after that function returned, you will never know it happened
- it does not tell how big the area is the stack pointer can grow in; so you may know how much stack is used, but you don't know how mucht is left.
- the same information can be retrieved from the compiler, calculating stack frame sizes

So what you needs is a stack painting mechanism and information from Espressif how large the stack area actually is.

The first I already implemented long ago, the second I am still waiting on, but did an estimate using memory painting. From there it looks like, on NON-SDK, we have 5324 bytes available, which is quite a bit, if you don't do stupid things like allocating complete arrays on the stack or having complex C++ classes.

From my code:

Code: Select all> stack:
>   bottom: 0x3ffffffc
>   top: 0x3fffeb30
>   initial stack pointer: 0x3ffffab0 (339 bytes)
>   current stack pointer: 0x3ffffedc (72 bytes)
>   painted: 3968 bytes
>   not painted: 1356 bytes
>   size: 5324 bytes
>   used: 2748 bytes
>   free: 2576 bytes

So the only information I still would like to have the actual area size, from a source directly involved, i.e. Espressif themselves.