This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Tracking Stack Size (Program currently faulting)



Hello,

Due to the amount of codes I have and not knowing the specific area that this problem is occurring in, it didn't seem logical to post all of my codes on here. I will do my best to explain the problem.

Currently the program is faulting whenever I perform too many HTTP request to the Wi-Fi module that I am using. To verify this, I've commented out the Wi-FI section and the program works as expected without crashing. The last time when I've seen a fault occurring due to the Wi-Fi was when I was allocating too much memory for the stack to handle (default stack size gotten from "Project Properties -> Linker -> Basic Options" is 512), which was a char array of around 250 bytes. To try to circumvent this, as I do not know what changing the stack size and heap size will do, nor how to do so correctly, I've changed the structure of my code so that it is not passing in so many parameters anymore, as I've recently learned that that increased the stack size.

However, the program now crashes at random number of HTTP request that I make to the Wi-Fi module, which leads me to think that somehow either the stack size or the heap size is exceeding the limits. I am not sure however, and thus would like to know how I can track the current stack/heap size of a program.

Thank you 

  • If you can't rely on toolchain support, stack checking/tracking will be troublesome. IAR has such an option, don't know about CCS (you didn't explicitly mention your toolchain). This will add some runtime and memory load, though.

    However, the program now crashes at random number of HTTP request ...

    Interrupts use the stack as well, and can cause "random" crash triggers. But they are more of a symptom (of insufficient stack size) than a cause.

    Are you using any clib functions, especially of the printf family ? This functions use to have a severe impact on stack usage.

    ... (default stack size gotten from "Project Properties -> Linker -> Basic Options" is 512) ...

    I guess that is bytes. Anyway, toolchain defaults for stack sizes are often ridiculous. I know one that honestly suggests 128 bytes ...

    In your case, I would rather go with 2 ... 5kByte. And I would consult the documentation of your TCP/IP stack (lwip ?) for stack size requirements and suggestions.

    Using a RTOS might make things more difficult, but you did not mention such an environment.

  • Hi f. m.,

    Sorry for still leaving out so many details.

    I am using CCS, and I also was using printf function. That really explained why it was faulting before when I try to printf.

    For now, I'm just looking to learn how much stack my program currently use and try to change my code structure to decrease the stack being used.

    Thomas
  • Hi,

    It is useful to generate listings and map file. Listings for each file shows  stack usage for each function.

    Also, CCS linker add to your program a hidden variable called _stack. You can insert that variable into watch window and see how much stack is used.