7.5 Tightly-Coupled Memories
The compiler supports attributes and options that allow the placement of code and objects into Tightly Coupled Memory (TCM). Accessing code and data in this memory avoids the intricacies of a system bus matrix and provides fixed latency and hence deterministic program execution.
Some Cortex-M7 devices implement TCM in SRAM, as separate instruction TCM (or ITCM), used to hold code, and data TCM (DTCM), used to hold data. These memories can be enabled and configured through independent device registers. The internal organization and size of the TCM areas vary greatly across devices, and this will be discussed in the data sheet for your selected device.
The tcm
attribute places objects or functions into the appropriate TCM,
for example uint32_t __attribute__((tcm)) var;
, which will place the
object var
into DTCM.
In device families where separate ITCM and DTCM are present, independent
driver options allow you to set the size of these memory areas, those being
-mitcm=size
and
-mdtcm=size
, which set the size (in bytes) of the
instruction and data TCM respectively. The size
specified
must be one permitted by the device and can be specified as a decimal number or as a
hexadecimal number with a leading 0x
. When an invalid size has been
specified, check the error message to see the sizes acceptable by that device. Use of these
options will ensure that the device-specific runtime startup code and linker script enable
and initialize TCM before your main()
function is called. Once enabled,
the preprocessor macros __XC32_ITCM_LENGTH
and/or
__XC32_DTCM_LENGTH
will be defined and equated to the size of the
respective TCM area.
By default, the vector table is allocated to TCM if possible. The option
-mno-vectors-in-tcm
keeps the vector table out of TCM, which might be
desirable if the selected device has limited memory available.
The data stack can be moved to TCM by ensuring that the -mstack-in-tcm
driver option is issued at both compile and link time. The linker will allocate a stack to
DTCM and the startup code will transfer the stack from System SRAM to DTCM before calling
your main()
function.