3.6.1.4 Const-data-in-config-mapped-progmem Option
The -mconst-data-in-config-mapped-progmem
option stores
objects qualified with const
to an area of program memory that the
compiler will ensure is mapped into the data memory space for some devices.
Certain devices, such as the AVR DA and AVR DB family, have an SFR (e.g.
FLMAP
) that specifies which 32 KB section of program memory will be
mapped into the data memory space. The
-mconst-data-in-config-mapped-progmem
option can be used to have
the linker place all const
-qualified data within one of these 32 KB
sections and automatically initialize the relevant SFR register to ensure that these
objects are mapped into data memory, where they will be accessed more efficiently in
terms of program size. The option must be used in conjunction with the
-mconst-data-in-progmem
option; however, this option is enabled by
default.
The -mconst-data-in-config-mapped-progmem
option is automatically
enabled for devices that can support this mapping feature. In that case, the feature can
be disabled by using the -mno-const-data-in-config-mapped-progmem
option, forcing const
-qualified objects to be accessed from program
memory.
As the -mconst-data-in-config-mapped-progmem
option affects both how
code is generated and the choice of library to link against, it (or its negated
no-
form) must be used with both compile and link steps of the
build process.
When this option is selected, the runtime startup code will set the
FLMAPLOCK
bit. Doing so prevents any modification of the
FLMAP
register. This is necessary since the code generated by the
compiler assumes the page mapped by the compiler at compile time will still be mapped at
runtime. If a program could change the mapping at runtime, any code that reads
const
data might fail.
-mconst-data-in-config-mapped-progmem
option as well as the
__at()
construct to place const
data in a page of
your choice, the linker will attempt to allocate all const
data in the
same page and ensure that page is mapped. For
example:const char __at(0xc000) arr[3] = {3, 1, 2}; // Force arr into page 1
const char arr2[3] = {3, 1, 2}; // arr2 will be placed in the same page
__at()
is used more than once to force objects into different pages,
the compiler will generate an error and suggest disabling the
-mconst-data-in-config-mapped-progmem
option. If you place some
const
data using __at()
but you also need other
const
data in an alternate page that is not mapped (will be
accessed using LPM instructions), then use the __memx
specifier with
the other data. For
example:const char __at(0xc000) arr[3] = {8, 1, 2}; // Force arr into mapped page 1
const char __at(0x300) __memx arr2[3] = {7, 1, 2}; // Force arr2 into page 0
If more than 32 KB of const
-qualified data is defined or the section
holding this data cannot otherwise be located in the mapped memory section, an error
from the linker will be issued.
The macro __AVR_CONST_DATA_IN_CONFIG_MAPPED_PROGMEM__
is defined if this
option is enabled and const
-qualified objects are located in a mapped
section of memory.