cancel
Showing results for 
Search instead for 
Did you mean: 

Put function in RAM

DGo.1
Associate II

Hi,

how can I tell to the compiler that I want a function to be executed in RAM ?

9 REPLIES 9

Should be able to use an attribute or pragma to indicate which section a particular function is placed in by the linker. Code in the startup or scatter loader should move the code from ROM into RAM.

It is more of a linker directive than a compiler one.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
DGo.1
Associate II

Something like this ? :

#define EXEC_FUNC_ON_RAM __attribute__ ((section(".data")))
 
EXEC_FUNC_ON_RAM  void myFunc(int data) {....}

Do I have to modify the linker?

/* Initialized data sections into "RAM" Ram type memory */
  .data :
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */
    *(.RamFunc)        /* .RamFunc sections */
    *(.RamFunc*)       /* .RamFunc* sections */
 
    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
 
  } >RAM AT> FLASH

Also, how do I check if the function in in RAM or FLASH ?

DGo.1
Associate II

Found this; it worked correctly:

just add it before the function declaration:

__attribute__ ((section(".RamFunc")));

But don't add a semicolon in the end! Shall be:

__attribute__ ((section(".RamFunc"))) void some_function() {}

WojtekP1
Associate III

Define section in RAM in linkerscript

use void procedureinram() __attribute__ ((section(".yoursectionname")) {procedure code}

of course it may not be void and may have any parameters.

Just tried that, same results

This is been tried, same results

Ignore this wrong post.

Ignore this wrong post.