How to run code from RAM on ARM architecture

On GCC: Just put the function in the .data section:

__attribute__( ( section(".data") ) )

It will be copied over with the rest of your initialzed variables by the startup code (no need to mess with the linker scipt). You may also need a “long_call” option as well if the function ends up “far away” from the rest of the code after being placed into RAM.

__attribute__( ( long_call, section(".data") ) )

Example:

__attribute__( ( long_call, section(".data") ) ) void ram_foobar (void) { ... }

You may get an compiler warning that can be safely ignored:

Warning: ignoring changed section attributes for .data

Leave a Comment