The dice-bootloader has the ability to flash a new application from the SerialFlash into the processor’s program memory. This library provides simple functions to control the update process.

To use this library

#include "Update.h"

Simple update

  • place the new application bin file into the SPI flash memory (e.g. via FileTransfer or http download)
  • call i_update( s_newAppFile ) to prepare the bootloader to copy the s_newAppFile binary file into the processors prog. memory at the next system start
  • call v_update_reset() or do a power cycle. This starts the bootloader that will now flash the new application and start it.
  • done

Advanced update using fall back

  • place the new application bin file into the SPI flash memory (e.g. via FileTransfer or http download)
  • call i_update_recover( s_newAppFile ) this:
    • creates an image file of the current application (called recover.bin) in the SerialFlash.
    • prepares the bootloader so that it updates to s_newAppFile at the next system start
  • a power cycle or v_update_reset() restarts the system, which starts the bootloader. The bootloader flashes the new application and prepares for a possible fallback to the recover.bin.
  • The new application:
  • confirms the successful update process by calling i_update_confirm(). This cancels any further fallback activities of the bootloader.
  • or
  • if the new application does not confirm the process then the bootloader will flash the previously application (recover.bin) back into the processor memory at the following system start.

Example

This example expects an application binary named ‘Blink.ino.bin’ in the SerialFlash, which can be created using the Blink.ino example code, compile, export and transfer it onto the device. The example shows the update process and fallback function.

#include "Update.h"
void setup() 
{
  SerialFlash.begin();
  while(!Serial);
  Serial.print("This is the application:");
  Serial.println(BOOTLOADER_SETTING.s_get_app_name());
  Serial.print("Version:");
  Serial.println(" V" +
    String(BOOTLOADER_SETTING.u32_get_app_version()));
  Serial.println("Prepare update to app: Blink.ino.bin");
  if(!i_update_recover("Blink.ino.bin"))
  {
      Serial.println("Error. Make sure the update file exists and is compiled for the right HW variant");
      while(1){ yield(); };
  }
  Serial.println("OK! Update prepared and recovery image created");
  Serial.println("Now manually restart the system");
}
void loop() 
{}

Now restart the system and see the LED blink. The blink.ino application does not call i_update_confirm().
Restart the the device again.
You should now see the output of the application above again since the bootloader re-flashed the recover.bin application. It fell back on the original application.

Find another example here and in the Examples menu of the Arduino IDE.

Update library notes:

The library / bootloader not only updates the application but also makes sure that the app. name and app. version is kept correct.
Don’t forget to SerialFlash.begin() before using the Update library functions.
Use (and study) the ‘Console_Dev” example project (see Arduino IDE) that allows to test all options of this library. Find the source code here:
C:\Users\your_name\AppData\Local\Arduino15\packages\dice\hardware\samc\1.x.x\libraries\Console -> consoleUpdate.cpp

Further information

SerialFlash – Library
Users manual – chapter Memory
writeFromClient() – download a file via httpGET into a file
i_FileTrans_ReceiveFile()
SerialFlash – see getVersion()
BOOTLOADER SETTINGS – Library – see u32_get_app_version()