I'm going to deploy a few MKR GSM1400s at remote sites and would like to be able to remotely update the sketch. I'd like to discuss my approach:
I would compile the new sketch and make it accessible over the internet by some protocol the Arduino supports, be it HTTP, FTP, MQTT (payload size dependant) or something else. The existing sketch would use the modem to download the new sketch and write it to an external memory chip. Once it had downloaded, the existing sketch would trigger a reset using the watchdog timer. On reset, the bootloader would then check the external memory chip for new firmware, and on detecting it flash the microcontroller with the new firmware. The new firmware must also have the ability to download new sketches.
I need a bootloader that can flash the SAM D21 processor from an external memory chip. After some searching I came across this:
This is a bootloader that can flash an Arduino Zero from a FAT16 or FAT32 formatted SD card. Should it be compatible with all of the boards that use the SAM D21 processor? I noticed that the official bootloaders are different for various MKR boards.
I need to install the bootloader on my Arduino. According to the SAM D21 datasheet (page 1), the SAM D21 can be flashed over SWD (Serial Wire Debug). The pin assignment is given in 7.2.2. According to the EAGLE files for the Arduino, the SWD interface is connected to the six large pads on the underside of the Arduino. So, I think I need to put some pogo pins in a breadboard to connect to the pads and buy an ATMEL ICE to install the new bootloader.
The nice thing about the bootloader is that you can put two firmware files on the SD card, selectable with pins on the Arduino. This could help mitigate the risk of remotely installing faulty firmware that can't update itself. I'd have a main firmware file that ran my application and could download new firmware, and a backup firmware file that only downloaded new main firmware. A button held down on reset would install the backup firmware.
In the event I installed bad main firmware, I could ask someone on site to use the button to install the backup firmware. The Arduino would then download and install new (hopefully good) main firmware.
- Am I on the right track?
- Has anyone done this already?