11.3.1.2 Const-qualified Variables in Secure Flash
const
-qualified variables with initializers can be
supported in secure Flash segments using PSV constant sections managed by the compiler.
For example:
const int __attribute__((boot)) time_delay = 55;
If the const
qualifier was omitted from the definition
of time_delay
, this statement would be rejected with an error message.
(Initialized variables in secure RAM are not supported).
Since the const
qualifier has been specified, variable
time_delay
can be allocated in a PSV constant section that is owned
by the boot segment. It is also possible to specify the PSV constant section explicitly
with the space(auto_psv)
attribute:
int __attribute__((boot,space(auto_psv))) bebop =
20;
Pointer variables initialized with string literals require special processing. For example:
char * const foo __attribute__((boot)) = "eek";
The compiler will recognize that string literal "eek"
must be allocated in the same PSV constant section as pointer variable
foo
.
Regardless of whether you have selected the constants-in-code or constants-in-data memory model, the compiler will create and manage PSV constant sections as needed for secure segments. Support for user-managed PSV sections is maintained through an object compatibility model explained below.
Upon entrance to a boot or secure function, PSVPAG
will
be set to the correct value. This value will be restored after any external function
call.