0

I want to write a program in which I can select a HEX file recorded on a SD card (via a LED screen, etc.) and run it, i.e. transfer control to it, like launching programs on a PC. Is this possible and if so, how? I only found ways to directly run a sketch from an SD card without that "program"

asked Oct 24, 2020 at 20:17
4
  • this may work ... arduino-forth.com Commented Oct 24, 2020 at 20:46
  • 2
    Bootloaders like Optiboot accept a program via UART and burn it into the flash of the MCU. That code is openly available: github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/…. With lots of effort, you too can write a bootloader which loads a compiled (or intel hex format) sketch from an SD card via SPI. The nearest project to that that aI could find is github.com/zevero/avr_boot which looks for a FIRMWARE.BIN on the SD card, programs the internal flash and runs it. You might want to modify that.. or, do it on another MCU with less restrictions Commented Oct 24, 2020 at 23:19
  • @MaximilianGerhardt, burn SD bootloader and then you use SD library to copy the selected file to firmware.bin and reset. the new firmware should have the same capability of selecting a firmware Commented Oct 25, 2020 at 5:28
  • @MaximilianGerhardt If you wish to answer the question, please post an answer. Commented Oct 25, 2020 at 8:31

2 Answers 2

0

The HEX files on SD card would have to be linked for a specific address in flash. Normal program is linked for address zero on ATmega, but the bootloaders are an example on how to link for specific address in flash.

Then you could use the do_sdm() function provided by Optiboot 8 (see the example) to write the bytes from the HEX file to the right location in flash memory. Next step would be to call the start address as function same way as do_spm() is made accessible with optiboot.h in the example.

typedef void (*loaded_function_t)();
const loaded_function_t loaded_function = (loaded_function_t)(ADDRESS_OF_LOADED_FUNCTION);

then you can use

 Serial.prinln("Execute the loaded code...);
 loaded_function();
 Serial.prinln("Loaded code finished.");
answered Oct 25, 2020 at 5:23
2
  • 1) Sorry, but I don't understand how to link HEX files from SD card for a specific address in flash. How to do it? 2) I've not found do_sdm() function in Optiboot. What did you mean? Commented Oct 28, 2020 at 20:52
  • 2) there is a link in the answer 1) see how bootloaders are compiled and linked for specific address Commented Oct 29, 2020 at 6:40
0

Not with an Uno, no, it's not possible. Or it's very very hard and the results would be less than desirable. You need a proper MCU with lots of RAM and the ability to run code from it, which you can't with an Uno.

It would be less work to write your own scripting language to control things from a text file.

answered Oct 24, 2020 at 20:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.