Watching the use of RAM during development....

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

Watching the use of RAM during development....

2,547 Views
awilliams
Contributor I
I'm new to uC programming.

Question: Is there a way to monitor RAM usage during software development?

Background: I am developing on the MC9S08QG8 Demo Board using CodeWarrior 5.7.0. The plan will be to use the MC9S08QG4. I want to be able to monitor the overall RAM usage so that I know that the code will run on the MC9S08QG4. I ran across the Project.map file but I'm not sure if I can totally rely on it for monitoring the overall RAM usage. I'm pretty sure there is a general method for doing this, I just haven't found it. Any documentation on the subject would be great.

Question: Does the size value for "READ_WRITE (R/W):" under the "Summary of section sizes per section type:" in the Project.map file provide the actual RAM usage? Or is it found in another part of the file?

My other thought would be to just swap out the MC9S08QG8 and install a MC9S08QG4 on my Demo Board.

Question: Will the Demo board support both uC versions?

Thanks for your help.


Labels (1)
0 Kudos
Reply
4 Replies

1,066 Views
awilliams
Contributor I
Quick followup. I applied the suggestions that you guys recommended and am able to watch my stack usage.
The suggestion to put static variables at the bottom of memory and the stack at the top of memory....NICE!

Thanks bigmac, mke_et, and PeterHouse.
0 Kudos
Reply

1,066 Views
mke_et
Contributor IV
Simple answer? Use simple tricks!

I always put my 'fixed' variables at the bottom and fill up. I always put my stack at the top and fill down. If I have variable variables, like variable size buffers, I always put them just on top of my fixed variables.

And one of the first things I do when I init in my code, is fill all the RAM with an easily recognizable pattern. They just stop and look to see where you pattern still exists. Hopefully it will still be there! At least somewhere.

No matter how much you calculate, there's always some kind of gotcha that can step in and take up ram, usually from nested interrupts or something you were sure wouldn't happen. It's nice to be able to just look as see if your microworld is what you expect!

Mike
0 Kudos
Reply

1,066 Views
PeterHouse
Contributor I
I recommend the same approach of filling the RAM with a known value and go one step further.  I have a routine which is called periodically from the main loop which begins after the last used heap memory and counts upward to find the beginning of stack usage and can send this count out a convenient communications channel if there is one or maybe just set an LED to flash if it gets within ten bytes of RAM left.

All of my projects have this routine.

Good Luck,

Peter House
0 Kudos
Reply

1,066 Views
bigmac
Specialist III
Hello, and welcome to the forum.
 
The project map file will detail the use of RAM for global and static variables only, that are assigned to a specific address.  For C programming in particular, the total stack usage will not be known, and is difficult to estimate.  It could be a significant portion of the total RAM available.
 
For the QG4, with only 256 bytes of RAM, make sure that the global variables commence at the lowest RAM address (within zero page), and that the stack pointer is initialised to top of RAM.  This will keep the stack and the globals as far separated as possible, to lessen the chance of the stack usage over-writing the variables.  This may require optimisation of the PRM file, and the use of #pragmas within the code.  It is possible for the stack size allocated within the PRM file to be exceeded during operation of the code.
 
During testing and debug of your code, it is a good idea to check for the amout of stack used at various times.  Initialise all RAM available to the stack to a known value (perhaps 0x00 or 0xFF).  Then periodically enter a break point so that the contents of RAM can be examined.  The lowest address that does not contain the pre-determined value will indicate the current extent of the stack.
 
You can use a QG4 on the demo board.  Another possibility is to leave the QG8 device in situ, and simply assign the QG4 device to your project.  The QG8 will be directly compatible with any code written for the QG4, but not vice versa.
 
Regards,
Mac
 
0 Kudos
Reply