EEPROM mark is used to guarantee fail-safe user mode application update. Bootloader sets mark in EEPROM memory at receiving of the first command from host and removes it during reset command (after the programming is completed). At the moment of user application programming the mark is always set. If any errors occur (e.g., power drop or off), EEPROM mark remains. At the next switch-on bootloader sees the EEPROM mark and enters the programming mode automatically. User application can be reprogrammed. Only in case host completes application upload and sends BOOT_RESET command, bootloader will clear EEPROM mark and run user application.
EEPROM mark can also be used for soft entry into the programming mode. All user-mode application has to do is to jump to 0x0016 address:
Bootloader will set EEPROM mark and reset the microcontroller to enter the programming mode.
EEPROM mark use is configured in boot.inc file with USE_EEPROM_MARK macro.
To use EEPROM mark macros value must be set to 1.
#define USE_EEPROM_MARK 1
If EEPROM mark is not used macros value must be set to 0.
#define USE_EEPROM_MARK 0
By default mark is located at address 0x00 of EEPROM memory. Bootloader enters the programming mode, if it reads 0x5A or 0xF0 at this address. 0xF0 value is used for fail-safe user mode application update. Bootloader doesn’t change this value unless it receives BOOT_RESET command from host. 0x5A value is used for soft reset. Bootloader resets this value (writes 0xFF instead of it) when it enters the programming mode.
If necessary to change mark address or values, override the following macros:
- in EEPROM_MARK_ADDR macro specify EEPROM memory address to place the mark;
- in EEPROM_MARK macro specify the value for fail-safe update mark;
- in EEPROM_MARK_SOFT_RESET macro specify the value for soft-reset mark;
These macros are defined in boot.inc file as shown below:
After EEPROM erase all bytes values are equal to 0xFF, therefore, it is better to use other values for marks. If you use bootloader to program the microcontroller EEPROM memory, put the EEPROM mark into the image file. Otherwise if any errors occur bootloader will enter the user mode and launch the corrupted application.