• C 83.8%
  • Python 10.7%
  • Makefile 3.7%
  • Assembly 1.3%
  • Shell 0.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-12-09 20:05:52 +01:00
app uart definitions in config.h; example update 2018-10-11 23:02:30 +03:00
isp-programmer Updated isp-programmer, gitignore and README 2025-03-24 11:03:29 +01:00
util added support for large block size 2017-07-29 03:02:18 +03:00
.gitignore added map file to gitignore 2025-03-24 11:21:49 +01:00
config.h Added more functionality to the bootloader; added checksum to every step; Added possibility to read memory via UART ISP programmer; Added command to set the read-out protection (WIP) 2025-02-28 16:24:39 +01:00
init.s stm8l port 2018-10-09 10:12:00 +03:00
LICENSE added LICENSE 2019-04-04 01:54:06 +03:00
main.c Added more functionality to the bootloader; added checksum to every step; Added possibility to read memory via UART ISP programmer; Added command to set the read-out protection (WIP) 2025-02-28 16:24:39 +01:00
Makefile Added more functionality to the bootloader; added checksum to every step; Added possibility to read memory via UART ISP programmer; Added command to set the read-out protection (WIP) 2025-02-28 16:24:39 +01:00
program.sh added program shell script 2025-12-09 20:05:25 +01:00
ram.c Added more functionality to the bootloader; added checksum to every step; Added possibility to read memory via UART ISP programmer; Added command to set the read-out protection (WIP) 2025-02-28 16:24:39 +01:00
ram.h Added more functionality to the bootloader; added checksum to every step; Added possibility to read memory via UART ISP programmer; Added command to set the read-out protection (WIP) 2025-02-28 16:24:39 +01:00
README.md Updated isp-programmer, gitignore and README 2025-03-24 11:03:29 +01:00
stm8.h uart definitions in config.h; example update 2018-10-11 23:02:30 +03:00
stm8l.h uart definitions in config.h; example update 2018-10-11 23:02:30 +03:00
stm8s.h uart definitions in config.h; example update 2018-10-11 23:02:30 +03:00

stm8-bootloader

Serial bootloader for STM8S and STM8L microcontrollers. A detailed write-up on this bootloader is posted here.

Features

  • small - fits in 547 bytes (SDCC v3.6.8 #9951)
  • fast - uploads 4k binary in 1 second @115200bps
  • configurable - can be adjusted for parts with different flash block size

Configuration

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.

  • BLOCK_SIZE - flash block size according to device datasheet. This should be set to 64 for low-density devices or 128 for devices with >8k flash.
  • BOOT_ADDR - application boot address.
  • BOOT_PIN - entry jumper. This is set to PD3 by default.
  • RELOCATE_IVT - when set to 1 (default) the interrupt vectors are relocated. When set to 0 the bootloader will overwrite it's own interrupt vector table with the application's IVT, thus eliminating additional CPU overhead during interrupts. Write-protection cannot be used in this case and resulting binary is slightly larger.

Changing boot address

Boot address must be a multiple of BLOCK_SIZE. Address is set in 2 places:

  • config.h
  • init.s

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 instructions

Build and flash the bootloader:

$ make && make flash

Enable write-protection (UBC) on pages 0-9 (TODO: must be adjusted for STML):

$ make enable-wpr

Enable read-out protection (ROP):

$ make enable-rop

Uploading the firmware

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