Is RAM value equal to 0x00 when power up?

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

Is RAM value equal to 0x00 when power up?

2,100 Views
patacCooper
Contributor I
MC9S12D32 question...
I want a reset counter in my program for reading the reset counts. But I'm not sure whether the RAM is 0-init when power up. Certainly, I know the start.c file will clear RAM for global variables, but it will not clear the NO-INIT RAM. I can't find any information about this in freescale's documents. Anybody can help?
Labels (1)
0 Kudos
3 Replies

498 Views
Lundin
Senior Contributor IV
ISO C states that variables with static storage duration (that is, global and static variables) must be set to zero before the program is started, unless they are explicitly initialized by the programmer. It also states that variables with automatic storage duration (local variables) will have a random value at startup.

So this isn't something that the Freescale docs need to mention, the C programming standard is clear. Assuming of course that the compiler follows ISO C, which Codewarrior does as long as the startup file is executed.

---

Codewarrior does not clear NO_INIT segments, so it is possible to preserve variables in RAM after a reset, assuming that the reset wasn't a power-on reset. With the S12 you can check if the reset was caused by the COP, clock failure or power-on. If the cause was the COP, one can assume that the RAM is still intact.

The best solution is indeed to do as already mentioned: store the variable in non-volatile memory.
0 Kudos

498 Views
patacCooper
Contributor I
JeffS, thanks for your helpful suggestion.
And Lundin, you are very kind. I guess it takes not a short time to present the background information. Thank you very much.
0 Kudos

498 Views
JeffS_
Contributor I
From the mcu's point of view, reset does not affect ram.

Of course from a power down, ram is random data.
If you truly need a persistent reset counter, you need to write it EEPROM or flash, otherwise it will be lost of power is lost.




0 Kudos