How to Execute code from RAM

hi,
how to simple form execute code from RAM Arduino DUE?

example compiling code to area, set adress RAM ( 0x2001000 ~0x2002000).

loader code( PC Usb ) and call to start_ram_code.

ARM easy loader and execute.

thanks,

Carlos.

Create a function that is prefixed with this line:

__attribute__ ((long_call, section (".ramfunc")))

That will cause the function to reside in RAM. The SAM3X can call RAM functions just the same as FLASH functions so you don't need to do anything else to make the call. It can literally long jump into a RAM function. But, you have to be careful what you do within a RAM function. You generally don't want to be calling external code - just do what you need to do to the hardware and get out.

Hi Collin,

I understand, I will test your code. but how to set the address of the ram to build?. ex Start_program_ram = 0x2001000.

thanks
Carlos.

. but how to set the address of the ram to build?. ex Start_program_ram = 0x2001000.

You don't need to want to do that. The linker will find a spot for it and change all the calls as needed.

Hi, I tested code see:

//-----------------code Flash

void setup() {
}
void loop() {
main_ram( ); call Ram
}
//-------------------------code RAM
#include <Arduino.h>
#include <inttypes.h>
#ifdef __cplusplus
extern “C” {
#endif
uint32_t value;
int a;
byte i;
RAMFUNC
void main_ram( void )
{
value = 0xAA55BBCC;
pinMode(L1,1);
while(!SerialUSB){
LED_ON
delay(50);
LED_OFF
delay(200);
}
for(;;){
usb_serial_print( a++, "Runnig in RAM… " );
delay(1000);
LED_ON
delay(50);
LED_OFF
}
}
//---------------------------
RAMFUNC
void usb_serial_print( uint32_t d, String str )
{
SerialUSB.print( str);
SerialUSB.println( d, HEX);
}

#ifdef __cplusplus
}
#endif
//-------------------------------------------------
1- programmer ok
2- running ok
3- reset or power down…
question ?

if, code in RAM how to the charging code to RAM ?

show file.ino.map

0x20070000 _srelocate = .
(.ramfunc .ramfunc.)

how to creat code to loader in to RAM ?

ex: flash program loader code ( USB ) write in RAM, call ram_program.

thanks.
Carlos.

If I understand your question... The RAMFUNC code will get a copy in flash that the C startup code copies into RAM for you, just like it does initialized variables. (in fact, code in RAM and initialized variables in RAM are exactly the same as far as the startup code is concerned, and is probably all copied in one big memcopy-like operation.)
You don't have to do anything.

Hi westfw,

"The RAMFUNC code will get a copy in flash "

modifier to: I get a copy in ( my computer ) write in RAM, will call funcRAM.

how to , whats parte in code flash ( file.hex ) it function loader code flash and write RAM.

I have 16 different functions for different partners.

thanks,
Carlos.

If I was to use the example above as a Template,

could I copy over the RAM portion of the Code - from the SdCard dynamically (over and over),
so I can load (precompiled) executable tools from the Sdcard (like Dos) -
??

-> Maybe the Template could be a Command prompt like program.

  • Sdcard> List
    PhotoViewer.due
    MusicPlayer.due
    Checkers.due
  • Sdcard> PhotoViewer
    ...
    quit
  • Sdcard> MusicPlayer
    ...
    quit
    ... etc