This library allows to access (load, read, set and store) the persistent settings of the bootloader and user defined values. The bootloader for dice devices is based on the CAN bus, hence it needs certain settings to operate (e.g. baud rate, CAN-IDs etc.) at start-up. These settings are stored in a protected area of the processors flash memory. This part will be left untouched during an application update while the remaining flash memory will be erased during this process. Now the user has two ways to read and write these settings. Firstly by using the diceConfig PC tool which puts the target into bootloader mode to communicate to the bootloader. Or secondly by making use of the following methods within the target application.

To use this library

There is no need to manually include the library since it is part of the core code. Also a global object is already created by the library and the current bootloader values are loaded so the object can be used by the sketches straight away. The handle of the provided object is:

BOOTLOADER_SETTING

This object provides all methods to load, read, change and store the settings in the protected area of the memory. In fact the current bootloader values are already loaded before the sketch is started so that the sketch can work with them. If any settings have been changed, the function u8_store_bootloader_settings() must be called afterwards to save the settings in the flash memory.

In addition to the bootloader settings, the developer can create his own variable-structs and store them in a protected memory area. These settings survive the flash process and can thus also be used after a system update. Examples would be WIFI settings or device specific ones like IDs or cloud credentials. The total size of the user defined values is 3kB.

Examples

Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE -> BOOTLOADER -> ...

1) This example reads the device serial number from the bootloader settings and prints it.

void setup()
{  
  Serial.begin();
  // wait for PC CAN2SER-monitor to open
  while (!Serial) { yield(); }
  Serial.print(" - serial number:  ");
  Serial.println( BOOTLOADER_SETTING.s_get_sernNo() );
}

void loop () 
{ }

2) This example works with a user variable that persists in the protected area of the memory.

typedef struct {
  uint32_t u32_Value_A;
} t_userValues;
t_userValues t_myValues;

void setup()
{
  Serial.begin();
  while (!Serial) { yield(); }
  
  BOOTLOADER_SETTING.u8_load_user_values(&t_myValues, sizeof(t_myValues));
  Serial.print("Value A:");
  Serial.println(String(t_myValues.u32_Value_A));
  if(t_myValues.u32_Value_A > 10)
    t_myValues.u32_Value_A = 0;
  t_myValues.u32_Value_A++;
  BOOTLOADER_SETTING.u8_store_user_values(&t_myValues, sizeof(t_myValues));
  Serial.println("Now re-flash the target and see");
}

void loop () 
{ }

Bootloader_settings library compatibility

Further reads

Find more details about the ‘bootloader settings’ and the memory areas in the users manual.