Please note as of Wednesday, August 15th, 2018 this wiki has been set to read only. If you are a TI Employee and require Edit ability please contact x0211426 from the company directory.

Placing functions in RAM

From Texas Instruments Wiki
(Redirected from Ramfunc Attribute)
Jump to: navigation, search


For embedded software which is mainly stored in and executed out of ROM, developers may wish to place certain functions in RAM instead for performance-sensitive code on devices where executing from RAM is faster than ROM. The TI compiler provides an easy mechanism to do this automatically.

"ramfunc" attribute and option

The ramfunc attribute is a TI compiler feature which allows code to easily specify that a function will be placed in and executed out of RAM. This allows the compiler to optimize functions for RAM execution, as well as to automatically copy functions to RAM on flash-based devices.

The attribute is applied to a function with GCC attribute syntax, as follows:

 void f(void) { ... }

The --ramfunc=on option is equivalent to specifying the attribute on all functions in translations units compiled with the option, with no source modification required.

This feature is available in ARM, C2000, and MSP430 compiler versions 15.6 and above, and will be available in future releases for all other TI compilers.

Linker command file

Most new TI linker command files support the ramfunc attribute by default. If your project uses an older linker command file that does not include a section specification for .TI.ramfunc, the linker will emit an error if your code uses the attribute. In this case, you can update your project's linker command file with a SECTIONS specifier as shown below.

Note that in the following examples, FLASH and RAM are the names of the MEMORY regions for flash and RAM and may be different depending on the particular names in your linker command file.

Flash-based devices

On flash-based devices, the BINIT functionality may be used to automatically copy the code to RAM for execution at boot:

 .TI.ramfunc : {} load=FLASH, run=RAM, table(BINIT)

Using table(BINIT) creates a copy table entry. This copy table is placed in an output section named .binit. Thus an entry is needed to place .binit:

 .binit : {} > FLASH

RAM-based devices

On RAM-based devices where no copying is needed (or the loader places the program directly in RAM), the section may be placed directly in RAM:

 .TI.ramfunc : {} > RAM

Target-specific effects

The ramfunc attribute is supported on and has the same meaning on all TI compilers, but will affect some targets differently depending on the device characteristics.


Fast branch instructions will be generated for ramfunc functions. Regular branch instructions will be generated for all other functions (which are assumed to be running from flash). The --no_fast_branch option is deprecated and no longer has any effect.


The attribute is ignored on CLA because this is a RAM-only device and to allow source compatibility with C28x.

Older compilers

For older compilers that do not support this feature, the CODE_SECTION pragma may be used in combination with linker command file modifications.

C syntax:

 #pragma CODE_SECTION(f, ".TI.ramfunc")
 void f(void) { ... }

C++ syntax:

 #pragma CODE_SECTION(".TI.ramfunc")
 void f() { ... }

On C6x and ARM, the same BINIT mechanism as described in the Linker command file section above may be used. On other targets with older compilers, BINIT is not supported and instead a different copy table must be specified and then copied explicitly by the user with copy_in() as described by the corresponding compiler user's guide.