[Solved] How to place a function RAM?
How to place a function RAM?
Good evening
I have tried a few ways of placing functions in RAM. I am trying to do this so i can write data into my user data flash on the RX630 from the user boot area.
Initially i placed the functions in the .data section and this placed the functions in RAM but the return from the function would fail as if the stack was damaged.
I then created a new section in the middle of the RAM called .rtdata and added my functions to that section. This works 100% when using the E1 debugger. When i remove power the functions disappear and the code does not run.
How can i safely add my functions to RAM so they do not cause trouble with the variables placed after the .data area and be available after power up?
Info:
e2studio v5.4.0.018 & GCC for Renesas 4.8.4.201701-GNURX Windows
.data -> 0x0000
.gcc_exc -> after .data
.bss -> after .gcc_exc
.rtdata -> 0x4000
ustack -> 0x17000
istack -> 0x17FFF
function desc:
unsigned int __attribute__((section(“.rtdata”),noinline))program_flash_block (volatile unsigned short *rom)
or
unsigned int __attribute__((section(“.data”),noinline))program_flash_block (volatile unsigned short *rom)
Regards
Richard
Best answer
Hello Richard,
Thank you for reaching out to us.
Every loadable or allocatable output section has two addresses:
- VMA (virtual memory address) which is the address the section will have when the code is executed.
- LMA (load memory address), the address at which the section will be loaded.
The documentation for these is in your toolchain installation folder > Documentation > Using ld > 3.1 Basic Linker Script Concepts and the full description of an output section is at 3.6.1 Output Section Description.
You can load a particular section in the ROM section, in order to have the functions available even after the power was removed, by specifying the LMA address in the linker script, e.g:.
rdata 0x4000 : AT (_mdata + _edata)
This line will load the .rdata section at the address _mdata + _edata, and from there you can copy the function code into RAM, at runtime when you need it. Please check if that address does not already contains any instruction.
e2 Studio provides an example in the reset_program.asm file on how to copy data from ROM to RAM:
reset_program.asm: /* src ROM address of data section in R2 */ mov #_mdata,r2 /* dest start RAM address of data section in R1 */ mov #_data,r1 /* end RAM address of data section in R3 */ mov #_edata,r3 /* size of data section in R3 (R3=R3-R1) */ sub r1,r3 /* block copy R3 bytes from R2 to R1 */ smovf
The same code can be written in C, using memcpy for example, but you must remove the underscore before the labels. An example for a label declaration is:
extern char *mdata;
Please let us know if we can be of further assistance.
—
Best regards,
The GNU Tools Team