NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

Placing functions in RAM

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

Overview[edit]

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[edit]

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:

 __attribute__((ramfunc))
 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[edit]

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[edit]

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[edit]

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[edit]

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.

C2000[edit]

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.

CLA[edit]

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

Older compilers[edit]

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.

E2e.jpg {{
  1. switchcategory:MultiCore=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Ramfunc Attribute here.

Keystone=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Ramfunc Attribute here.

C2000=For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article Ramfunc Attribute here. DaVinci=For technical support on DaVincoplease post your questions on The DaVinci Forum. Please post only comments about the article Ramfunc Attribute here. MSP430=For technical support on MSP430 please post your questions on The MSP430 Forum. Please post only comments about the article Ramfunc Attribute here. OMAP35x=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Ramfunc Attribute here. OMAPL1=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Ramfunc Attribute here. MAVRK=For technical support on MAVRK please post your questions on The MAVRK Toolbox Forum. Please post only comments about the article Ramfunc Attribute here. For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article Ramfunc Attribute here.

}}

Hyperlink blue.png Links

Amplifiers & Linear
Audio
Broadband RF/IF & Digital Radio
Clocks & Timers
Data Converters

DLP & MEMS
High-Reliability
Interface
Logic
Power Management

Processors

Switches & Multiplexers
Temperature Sensors & Control ICs
Wireless Connectivity