16.3 Allocation of Function Code

Code associated with C/C++ functions is normally always placed in the program Flash memory of the target device.

Functions may be located in and executed from RAM rather than Flash by using the __ramfunc__ and __longramfunc__ macros.

Functions specified as a RAM function will be copied to RAM by the start-up code and all calls to those functions will reference the RAM location. Functions located in RAM will be in a different 512MB memory segment than functions located in program memory, so the longcall attribute should be applied to any RAM function, which will be called from a function not in RAM. The __longramfunc__ macro will apply the longcall attribute as well as place the function in RAM.

#include <sys/attribs.h>
/* function ‘foo’ will be placed in RAM */
void __ramfunc__ foo (void)
{
}

/* function ‘bar’ will be placed in RAM and will be invoked
   using the full 32 bit address */
void __longramfunc__ bar (void)
{
}
Note: Specifying __longramfunc__ is functionally equivalent to specifying both __ramfunc__ and __longcall__.