Hello everybody!
I'm doing a little project with MSP430F149. My compiler is mspgcc.
Needing much space for other variables I'm not sure whether my space for stack is enough
or not.
Can anybody give me a hint how to determine the stack usage of each function (recursion
not necessary).
Thanks for Your help!
Bernhard
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Hello Matthias,
thanks for your answer. I tested your solution before but it is not that exact. It would
be very interesting to get this information for each function to do some improvements.
Greetings
Bernhard
--- In m...@yahoogroups.com, Matthias Weingart
wrote:
>
> "bernhard.glaser" :
>
> > Hello everybody!
> >
> > I'm doing a little project with MSP430F149. My compiler is mspgcc.
> > Needing much space for other variables I'm not sure whether my space for
> > stack is enough or not. Can anybody give me a hint how to determine the
> > stack usage of each function (recursion not necessary).
>
> Simplest way (but not accurate) is to fill your RAM with a pattern at startup
> and look into it with a debugger after a while (and usage of all functions).
>
> M.
>
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com ) You can also add a simple "guard" at the bottom of your stack. Use your map and
configuration file (.xcl) to determine your stack's size and location. Remember that on
the MSP430 the stack starts at the highest address and works down.
.map file contains:
SEGMENT SPACE START ADDRESS END ADDRESS SIZE TYPE ALIGN
======= ===== ============= =========== ==== ==== =====
CSTACK 0500 - 05FF 100 rel 1
Then in your code place a variable with a "magic number" just below the stack:
#pragma location=0x0500 - 0x0002
__no_init static volatile uint16_t stackGuard;
#define STACK_GUARD_MAGIC_NUMBER 0xABCD
...
stackGuard = STACK_GUARD_MAGIC_NUMBER;
Then, you can always test that location to see if the magic number is still valid. (Of
course there is some small probability that the guard variable will be written-over by the
magic number, but doubtful.)
To validate this, I wrote a "stack killer" function that just calls itself recursively
until the magic number mismatches. This means the stack overflowed.
static void stackKiller(uint8_t iteration)
{
if (stackGuard == STACK_GUARD_MAGIC_NUMBER)
{
iteration++;
stackKiller(iteration);
}
}
The details of this kind of method is dependent on what you're doing, but it's a useful
trick in general.
Stuart
--- In m...@yahoogroups.com, Matthias Weingart
wrote:
>
> "bernhard.glaser" :
>
> > Hello everybody!
> >
> > I'm doing a little project with MSP430F149. My compiler is mspgcc.
> > Needing much space for other variables I'm not sure whether my space for
> > stack is enough or not. Can anybody give me a hint how to determine the
> > stack usage of each function (recursion not necessary).
>
> Simplest way (but not accurate) is to fill your RAM with a pattern at startup
> and look into it with a debugger after a while (and usage of all functions).
>
> M.
>
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )