Static variable not cleared at reset

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

Static variable not cleared at reset

349 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by celephicus on Wed May 30 19:49:22 MST 2012
Greetings,

We all know that variables declared static with no explicit initialization are implicitly set to zero by the start up code. Now, how do I declare a static variable that is NOT so initialized? I need this to keep state during a watchdog reset so that I can ascertain which thread blocked and caused the reset.

Hopefully this can be done without linker trickery.
0 Kudos
3 Replies

322 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Thu May 31 00:59:36 MST 2012
Looking at a map file I noticed the section [I].uninit_RESERVED[/I] which brought me to this help page.

I think you could use this section attribute for what you want. All the linker script trickery was done for you.
0 Kudos

322 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by celephicus on Wed May 30 20:44:47 MST 2012

Quote: fastmapper
I presume the static variable you are declaring is in RAM.  If that is the case, what would the value of an uninitialized variable be on the first reset after each power up?

Maybe you should consider something in non-volatile memory (e.g. flash) that you can initialize before the first reset and update as necessary for all subsequent resets.



The variable is cleared on a power on reset (which can be ascertained by reading SYSRSTSTAT). On other resets, the variable contains useful information which is read and stored elsewhere.
0 Kudos

322 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fastmapper on Wed May 30 20:36:55 MST 2012
I presume the static variable you are declaring is in RAM.  If that is the case, what would the value of an uninitialized variable be on the first reset after each power up?

Maybe you should consider something in non-volatile memory (e.g. flash) that you can initialize before the first reset and update as necessary for all subsequent resets.
0 Kudos