1.1 Entering Bootloader Mode
The EFM8 device will entry bootloader mode under these three conditions.
• On any reset, the bootloader will start if flash address 0x0000 is 0xFF (i.e. first byte of the reset vector is not programmed). This ensures new or erased parts start the bootloader for production programming. For robustness, the bootloader erases flash page 0 first and writes flash address 0x0000 last. This ensures that any interrupted bootload operations will restart when the interrupting event clears.
• To start the bootloader on demand, the application firmware can set the signature value 0xA5 in R0 in Bank 0 (data address 0x00) and then initiate a software reset of the device. If the bootloader sees a software reset with the signature value in R0, it will start bootloader execution instead of jumping to the application.
• To provide fail-safe operation in case the application is corrupted, the bootloader starts on either power-on reset (POR) or pin resets if a pin is held low for longer than 50 µs. A full list of entry pins for each device and package is available in Table 3.1 Summary of Pins for Bootloader Mode Entry on page 7 of AN945. The pin for this bootloader entry method can also be found by looking at the efm8_device.h file in the bootloader source code. There is no option to disable this entry method.
1.2 The detailed implementation of bootloader source code as below.
After system reset or power on, the MCU will execute the boot_startup.asm in bootloader FW firstly.
• If the flash address 0x0000 is 0xFF, MCU will jump to boot_start to start the bootloader, otherwise execute the next command.
• When the bootloader sees a software reset and the signature value in R0 is 0xA5, it will jump to boot_start, otherwise will jump to pin_test for boot pin checking.
• If the boot pin held low for longer than 50us, the MCU will also execute boot_start, otherwise jump to app_start to execute the application code.
; Start bootloader if reset vector is not programmed MOV DPTR,#00H CLR A MOVC A,@A+DPTR CPL A JZ boot_start ; Start bootloader if software reset and R0 == signature MOV A,RSTSRC CJNE A,#010H,pin_test MOV A,R0 XRL A,#BL_SIGNATURE JZ boot_start ; Start the application by jumping to the reset vector app_start: LJMP 00H ; Start bootloader if POR|Pin reset and boot pin held low pin_test: ANL A,#03H ; A = RSTSRC JZ app_start ; POR or PINR only MOV R0,#(BL_PIN_LOW_CYCLES / 7) ?C0001: ; deglitch loop JB BL_START_PIN,app_start ; +3 DJNZ R0,?C0001 ; +4 = 7 cycles per loop ; Setup the stack and jump to the bootloader boot_start: MOV SP, #?BL_STACK-1 LJMP ?C_START