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.

Stack Error. Any suggestions on why it might be occurring?

Other Parts Discussed in Thread: MSP430F2274

Hello Everyone,

I am working on a MSP430F2274 device project. I am getting this warning when I download and debug my project. The code does not download to the device and I get this:

The stack pointer for stack 'Stack' (currently Memory:0x52C) is outside the stack range (Memory:0x5B0 to Memory:0x600)


I am using IAR . Is it stack overflow? How do I start solving this issue. I would really appreciate any response. In case, I need to paste any code snippets for your reference let me know.

Thanks and regards

Ravi



  • Ravi Mandliya said:
    I am using IAR . Is it stack overflow?

    Yes, it is.

    Ravi Mandliya said:
    How do I start solving this issue.

    Check where you allocate huge amount of local variables like temporary array/buffer, fix it. Other option: increase stack size.

  • Thank you so much for the response.  I just had a one more query. Does the size of the stack is decided by compiler. I mean to ask does the stack size is dependent on which compiler I use? I have a constrain of using mspgcc for this project. I will soon port the code. My query is if I fix this issue on IAR, would things be solved just in IAR?

  • Ravi Mandliya said:
    Does the size of the stack is decided by compiler.

    Compilers have default stack size defined, but developer shall be one deciding stack size if default is not good enough.

  • Ravi Mandliya said:
    The code does not download to the device and I get this:

    If you got a stack poitner error, then the code did download and is running. The debugger jsu tdetected that whiel running, the stack pointer has changed to a position where it shouldn't be according to the configured stack size (or rather: declared size, as there is no way to configure or limit the size of the stack - if it grows, it grows)

    Apparently, the project tells the debugger that you expect the stack to never be larger than 80 bytes (0x5B0 to 0x600), which is the default setting.
    However, during execution of you rprogrma to the point where the debugger stops it, the stack has grown to 216 bytes. Possible reasons are recursions or local variables.
    Since local variables are dynamically created on and removed form stack when a funciton is called, even multiple times in case of recursions (except for static local variabels, whcih exist only once per function and are allocated globally on the heap), neither compiler nor linekr cna possibly know ho wmuch space might be required for them during program execution. It's your job to figure this out and adjust the project settings accordingly,

    Hint: local variables in main should be instead declared ouside main and marked static. Except for loop variables which might be put into a register by the compiler anyway)
    You surely won't recurse into main, and this way, these variables can be considered when the linker calculates the definitely used memory.

**Attention** This is a public forum