9.11.9 Persistent Variable Attribute
persistent attribute specifies that the variable should not
be initialized or cleared at startup. Use a variable with the
persistent attribute to store state information
that will remain valid after a device Reset. For
example:int last_mode __attribute__((persistent));The persistent attribute typically causes the compiler to place
the variable in the .pbss section, which does not get
cleared by the default runtime startup code; however, that might not be the
case if the object is defined using other attributes. For example, use of
either the address or section attributes
in addition to persistent will place the object in sections
with different names. Because the section used for
persistent objects must be placed in data space,
this attribute is not compatible with the space attribute.
The persistent attribute implies the
coherent attribute. That is,
persistent attributed variables are accessed via
the uncached address. The const qualifier can be used with
the persistent attribute provided the object is not
initialized. Any attempt to initialize such an object will result in a
warning and the initial value ignored.
Note that on microcontrollers featuring an L1 cache, cache reinitialization may cause the runtime value of the variable to change. For devices with an L1 cache and a Memory Protection Unit (MPU), you may choose to use the Memory Protection Unit to create an uncached region of RAM and place the persistent variable into that region.
