Typically running functions from RAM is much faster on most MCUs however I created a quick benchmark project which proves that running the same function from RAM is about 25% slower.
see code below:
"
/******************************************************************************/
/* MISC_NOPs
*
* The function does a certain number of NOPs.
* */
/******************************************************************************/
void MISC_NOPs(unsigned int nops)
{
unsigned int i;
for(i=0;i<nops;i++)
{
NOP();
}
}
#pragma CODE_SECTION(MISC_NOPs_RAM,".TI.ramfunc");
/******************************************************************************/
/* MISC_NOPs_RAM
*
* The function does a certain number of NOPs.
* */
/******************************************************************************/
void MISC_NOPs_RAM(unsigned int nops)
{
unsigned int i;
for(i=0;i<nops;i++)
{
NOP();
}
}
"
The one from ram takes ~13uS while the one from Flash takes ~10uS.
Linker:
"
MEMORY
{
/* Application stored in and executes from internal flash */
FLASH (RX) : origin = APP_BASE, length = 0x00100000
/* Application uses internal RAM for data */
SRAM (RWX) : origin = 0x20000000, length = 0x00030000
SRAM_RAMFUNC (RWX) : origin = 0x20030000, length = 0x00010000
}
/* Section allocation in memory */
SECTIONS
{
.intvecs: > APP_BASE
.text : > FLASH
.const : > FLASH
.cinit : > FLASH
.pinit : > FLASH
.init_array : > FLASH
.vtable : > RAM_BASE
.data : > SRAM
.bss : > SRAM
.sysmem : > SRAM
.stack : > SRAM, fill 0xAAAA5555
.TI.ramfunc : {} LOAD = FLASH,
RUN = SRAM_RAMFUNC,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
PAGE = 0, ALIGN(4)
}
"