On Fri, 2011-08-26 at 13:26 +0200, N. Coesel wrote:
> I've been reading this thread for a while and it 
> makes me wonder if there is some kind of tool 
> which can analyze the code and determine the 
> stack usage? I think this may be a safer route 
> than to depend on a real-time stack check. The 
> big question is: what do you do when the stack 
> overflows? Just resetting the MCU is probably not 
> an option so you'll have to add extra code to 
> handle such an 'exception'. That does not seem very trivial to me.

Worst-case scenario: you have a recursive function and the recursion
depth depends on the value of a (peripheral) register. It's true that
writing such code means asking for trouble, but it's just an example of
stack usage that is impossible to determine at compile time (or before
the code is actually running).

In my case at least, the purpose of the handling code depends on the
environment where it's used:

* for development, it should signal the user (for instance by blinking
an LED) and stop execution (disable interrupts, enter and endless loop),
allowing the user to go into the debugger, examine the stack trace and
see what caused the overflow

* for production, it should simply restart the MCU; the idea behind it
is that if stack overflow occurs, some "sensitive" data may be
corrupted, causing the device to malfunction. Therefore it's better to
do a soft reset (and cause it to stop working at all for a very little
time) and then have it function properly.

Radu Rendec



------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to