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 Overflow

Other Parts Discussed in Thread: MSP430F5419

Hi,

I'm using CCS v4.1.2 to write code for the MSP430F5419.

In order to protect agaisnt stack overflow  i've been placing a variable in the first posisiton that would get overwritten if the stack was to overflow into normal RAM variables, setting this to a particular value and then checking that it doesn't change. If it does then I know there has been a stack overflow and can perform a controlled re-start of the code. 

At the moment to place the variable I've been compiling the code looking in the MAP file to find the variable with the highest address and then declaring another variable after this one that can perform the above task, then re-compiling. Is there an easier way to locate this variable in the correct place? (i.e. making sure it is the variable in RAM with the highest address).

Regards,

Ben

  • CCS allows you to set a breakpoint on stack overflow, so you can catch such overflows during debugging. There is an option under View->Breakpoints, to set a Break on Stack overflow, which will cause program execution to stop on the instruction that caused the stack overflow. Please take a look at the CCS v4.1 Users Guide for MSP430, http://www.ti.com/slau157 as well as the application note "Advanced Debugging using the Enhanced Emulation Module", http://www.ti.com/slaa393

    Hope this helps.

     

  • Thanks Aarti that is a useful feature,

    My orignal thinking behind catching the stack overflow was as a safeguard agaisnt it unexpectadely happening in the field, such that if it did we would perform a controlled restart of the code. Is my original method of doing this the best way?

  • Your method sounds like a reasonable way to do it. The link map file also contains a global symbol _stack which will give you the address beyond which the stack will overflow. You could place your variable at the next address and check for whether its value changes. In fact, the "Break on Stack overflow" feature in the debugger I mentioned earlier works in a similar fashion by setting a breakpoint at address of _stack.