Skip to main content
DGo.1
Associate II
September 15, 2021
Question

Put function in RAM

  • September 15, 2021
  • 9 replies
  • 5932 views

Hi,

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

This topic has been closed for replies.

9 replies

Tesla DeLorean
Guru
September 15, 2021

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
DGo.1
DGo.1Author
Associate II
September 16, 2021

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
DGo.1Author
Associate II
September 20, 2021

Found this; it worked correctly:

just add it before the function declaration:

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

Graduate
March 7, 2023

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

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

CLeo.1
Senior II
March 8, 2023

This is been tried, same results

WojtekP1
Associate II
March 7, 2023

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.

CLeo.1
Senior II
March 8, 2023

Just tried that, same results

CLeo.1
Senior II
March 8, 2023

Ignore this wrong post.