Run arduino sketch from an sd card

Viewed 7189

Is it possible to put a sketch (.HEX file) to an SD card and run it from there? My objective is to utilize SD storage instead of flash memory for a program.

If yes, are there any libraries doing exactly this?

All i found was "flashing arduino from sd card", which is not what i need.

UPDATE:

the sketch's loop calling is implemented in the bootloader. so i assume there is something like this in the bootloader:

while(true)
{
    call_sketch_loop();
}

can it be changed to this? :

//signature changed from void loop() to int loop()
while(true)
{
    int retval = call_sketch_loop(); //get loop call's return value

    if( 0 == retval )
        continue; // if 0, iterate the loop as usual
    else
    {
        //copy 1.HEX from sd to flash and reboot
        copy_hex_from_sd_to_flash( retval + ".HEX" );
        reboot();
    }
}
  1. change loop singature to int loop()
  2. put {int}.HEX files to an SD card - 1.HEX , 2.HEX , 3.HEX
  3. the loop() call returns 0
  4. continue with next iteration as usual
  5. the loop() call returns 2
  6. copy file 2.HEX from SD card into program flash memory
  7. reboot device

with this approach, we can run flash-capacity-exceeding programs if we split them up to smaller subprograms.

1 Answers
Related