QE128 how to determine stack/heap/ram size?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

QE128 how to determine stack/heap/ram size?

2,067 Views
Toe
Contributor IV
I'm using a MCF51QE128 and I'm starting to see some strange problems that I can massage away, but I'm concerned I'm running out of space.  I'm not sure how to tell if I'm overflowing my stack or RAM space.  Is there a good way to see this using the tools?  I'm using CW6.1.  Is there a document that I've missed describing how stack, heap, and ram are managed in the 8k space?

Also, is there some type of limitation for how stack and heap sizes must be created?  The default lcf uses 1k for stack and 1k for heap, but adding to only the stack or heap prevents the solution from running.
Labels (1)
0 Kudos
Reply
1 Reply

351 Views
RichTestardi
Senior Contributor II
The way I figure out how much stack I am using is as follows...
 
1. start your project, up to the point where you initialize your stack pointer (a7); the a7 value is the top (highest memory address) of your stack.
2. determine your stack size from your .lcf or .xmap file.
3. the bottom of your stack (lowest memory address) is at a7 minus the stack size.
4. use Debug -> ColdFire -> Fill Memory to fill your entire stack, from the bottom address for the whole stack size, to 0xaa.
5. run your application, with a representative workload.
6. break into the debugger.
7. use Data -> View Memory to view the bottom address of your stack.
 
Now look for the *first* non-0xaa byte in your stack and that was your last unused stack location (ignore any 0xaa's after the first non-0xaa byte, as they are just holes in your stack).  If you don't see any 0xaa's at the bottom address, you've overflowed your stack.  If you only see a few, you're close to overflowing your stack.  If you see a whole bunch, you're OK.  (And if you see tons, you might be able to get by with a smaller stack.)
 
This assumes you never change stack pointers -- if you're using threading libraries, they might well do that, and you have to initialize *all* stacks and check them all that way.  (We actually do this at runtime during thread creation/cleanup at work, and it gives you a nice overview as long as you're not overflowing -- when you overflow, you never make it to cleanup code...)
 
You can get an idea of your static RAM usage from your .xmap file -- sorry, I can't help you for determining heap usage, if you're doing dynamic memory allocations.
 
-- Rich
0 Kudos
Reply