Flashing compiled .bin from SD card to Due?

First of all, keep in mind that I wrote a CANbus based firmware flasher so you will need to do quite a bit of modification to make it work for loading from an SDCard.

But, the general concept is the same. Yes, there are two examples for the FirmwareReceiver project. One of them is not exactly an example sketch per-se. It is an example bootloader. You see, the general idea is that your main sketch runs and monitors for a request to upload firmware. When this happens the main sketch reboots to the bootloader. What I'd do is put the bootloader sketch in FLASH1 and the user sketch in FLASH0. So, you reboot the board into FLASH1 and you're in the bootloader now. The bootloader can now freely write anything it wants to FLASH0 as they're separate and one can write to the other without any problems. So, the bootloader rewrites FLASH0 then it reboots to FLASH0 and you're in the new sketch. That's the basic idea. It's reasonably simple and it works pretty well. You can replace my CAN bootloader with an SDCard bootloader. Just put it into FLASH1. Then you reference the other example for how it calls the FirmwareReceiver where code sets up for a reboot. That's the only part you need - the set up for a reboot to FLASH1.

So, general overview:

  1. Grab the reboot routine from FirmwareReceiver.cpp. This routine you shouldn't need to change. Be sure you keep the ramfunc part.

  2. Modify the bootloader so it grabs firmware from an sdcard instead of over CAN. Note that the bootloader sketch has a routine very similar to the one above. It's subtly different and reboots to FLASH0 so make sure you keep them straight.

  3. Flash that bootloader to FLASH1

  4. Now your sketches can compile as normal and go to FLASH0. But, they need to call the reboot routine when it is time to update firmware.

That's it. Basically that project on Github is a template you can use to do what you want. It is complete as-is if you wanted to flash over CAN but can be modified to flash from any source. And, I've already banged my head into the desk trying to make it all work so you don't have to. :wink: