Serial bootloader for STM8 microcontrollers
Serial bootloader for STM8S and STM8L microcontrollers. A detailed write-up on this bootloader is posted here.
The default configuration targets low-density devices (STM8S003). To compile for a different target MCU
and FAMILY
makefile variables are adjusted accordingly.
Bootloader configuration is located in config.h
.
Boot address must be a multiple of BLOCK_SIZE. Address is set in 2 places:
Main application is compiled with --code-loc <address>
option. When RELOCATE_IVT is set to 0, 0x80 must be subtracted from application address and isr29 must be implemented: void dummy_isr() __interrupt(29) __naked { ; }
.
Build and flash the bootloader:
$ make && make flash
Enable write-protection (UBC) on pages 0-9 (TODO: must be adjusted for STML):
$ make opt-set
There is a demo application inside app
directory which toggles PD4 via interrupts. To upload the application short PD3 to ground, power-cycle the MCU and run the uploader utility. DTR pin on UART-USB converter can be connected to RESET pin on STM8 for automatic reset.
$ cd app && make
$ python ../uploader/boot.py -p /dev/ttyUSB0 firmware.bin