You have two options.
- Copy them as you suggest, compile with
pc relative
.
- Use a linker file with a different load/run address.
A simple copy will only work if the routines do not use any absolute addresses. It maybe fine if they do use the absolute address as I guess you are going to leave a copy in standard RAM. However, this may not get the full benefit of the TCM
.
With a linker script, you can specify a different LOAD
and RUN
locations.
sections {
.text { *(.text); } >FLASH
.tcm {
*(.tcm);
} >TCM_MEM AT>FLASH
.data { *(.data); } > RAM
.bss : NOLOAD { *(.bss); } > RAM
}
Note especially AT>FLASH
.
See also: gnu linker map file... and many more on stackoverflow. The Gnu Ld manual has information on LMA
sections (LOAD address). Your LMA
would be flash, but the VMA
(RUN address) would be TCM. The manual link above also shows how to copy. The RAM
, FLASH
, and TCM_MEM
are defined with ld MEMORY information, depending on the addresses are for your board. All of this will be documented in a MAP
file. Be sure to generate a MAP
file and examine the addresses to double check your ld
script.
The 2nd case also requires a copy (at start-up or at least before the first TCM
function use). However, the compiler can use absolute addresses and they will be in the TCM
memory. Also any function within the main DRAM
can call the TCM
function directly. With the first case, you must use function pointers to call the TCM
code. If you wish global variables to be placed in this memory, you can use attributes to put them in different sections and use gnu ld to place them appropriately. I think there is ITCM
and DTCM
? So maybe this doesn't apply for you, or you need two sections.
The linker script is more generic and will work best if you put complicated functionality in the TCM
. Just using -fpic
, etc and copying may get things working quickly, especially if you only have a single pure
function.