one of the biggest drawbacks of arduino (and microcontrollers in general) is the small program storage. if you include a few libraries like TFT, FAT, Ethernet, you easily exhaust most of your program flash memory (70%). this really hurts.
but there is an SD card. lots of space. gigabytes instead of kilobytes. unfortunately, you cannot run the program from there.
so, the objective is to utilize SD card as a storage for programs, with these information taken into account:
- programs can be run only from flash memory
- copying program from SD to flash can be done in the bootloader (2boots and such)
- but 2boots is made for manually triggered in-the-field program replacement
- the loop() method actually gets called by the bootloader
is there a way to programatically trigger .hex file upload/replacement, while this .hex file's filename is received from inside the current program's loop() ? i believe there is.
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();
}
}
- change loop singature to
int loop() - put {int}.HEX files to an SD card -
1.HEX , 2.HEX , 3.HEX - the loop() call returns
0 - continue with next iteration as usual
- the loop() call returns
2 - copy file
2.HEXfrom SD card into program flash memory - reboot device
with this approach, you can run flash-capacity-exceeding programs if you split them into smaller subprograms. you are no longer limited by the program size.
can this be done or not?