stm8gal is an application for programming or reading out STM8 memory using the built-in ROM bootloader (BSL) via UART or SPI interface. It is compatible with Windows, MacOS X and Linux, including Raspbian. For a list of tested configurations see section Test Overview.
Note: stm8gal replaces the _STM8_serialflasher. The latter was renamed after a proposal by Philipp Krause
Tools with similar functionality via the UART interface are:
For bug reports or feature requests please send me a note.
Have fun! Georg
stm8gal and it's source code is distributed under the Apache License Version 2.0 (see License)
required flash write/erase RAM routines by Basil Hussain is distributed under the Apache License Version 2.0. Sources are available from https://github.com/basilhussain/stm8-bootloader-erase-write
optimized CRC32 calculation by Basil Hussain is distributed under the MIT License. Sources are available from https://github.com/basilhussain/stm8-crc
The majority of stm8gal is written in ISO C 99 with some OS-specific routines required e.g. for serial communication. However the required serial libs are part of all standard compiler suites and shouldn't pose a compatibility issue. In case of portability issues please contact the author for support.
Non ANSI-C extensions:
wiringPi library, which is Raspberry Pi specific, and allows automatic reset of the STM8 via GPIO header pin. Is pre-installed for Raspbian Stretch and above. To activate remove comment in Makefile
spidev kernel library for interfacing to the SPI. To activate remove comment in Makefile. The Raspberry Pi and other "embedded PCs" provide direct SPI pin access, so no extra hardware is required. For "normal" PCs, an extra hardware and likely an adaptation of the SPI send/receive routines is required (volunteers?)
A code reference can be generated by running Doxygen with input file 'Doxyfile'. Then open file './doxygen/html/index.html' with a webbrowser. For other output formats, e.g. PDF, modify 'Doxyfile' accordingly.
Use one of the following options to build stm8gal:
make
chmod u+x *.sh
spidev
and user access to SPI hardwareCFLAGS += -DUSE\_SPIDEV
and SOURCES += spi\_spidev\_comm.c
in file "Makefile"Note: Under Linux access to serial ports may be prohibited. To grant access rights see here
Same as Linux above, but with additional option:
-DUSE\_WIRING
and -lwiringPi
in file "Makefile"gpio readall
in commandlineraspi-config
sudo usermod -a -G gpio $(whoami)
)raspi-config
sudo usermod -a -G dialout $(whoami)
)CFLAGS += -DUSE\_SPIDEV
and SOURCES += spi\_spidev\_comm.c
in file "Makefile"raspi-config
sudo usermod -a -G spi $(whoami)
)Use one of the following options to build stm8gal:
Note: Windows commandline (cmd.exe) requires a path on a mounted drive, i.e. path to the tool has to start with 'C:\', 'D:\' or similar. So either copy the tool to a mounted drive or use 'connect network drive' to assign a drive letter. This limitation does not apply to POSIX operating systems
Same as for Linux above. However, for double-click rename files ".sh" to ".command"
Note: Due to lack of a Macintosh, compatibility with MacOSX is no longer tested. Therefore, please provide feedback if you have experience with stm8gal on a Mac. Also a Mac binary for distribution is highly appreciated. Thanks!
stm8gal is a commandline tool without graphical interface (volunteers...?). The application is called from the command line or via shell script using the below syntax.
usage: stm8gal with following options/commands:
-h/-help print this help
-v/-verbose [level] set verbosity level 0..3 (default: 2)
-B/-background skip prompts and colors for background operation (default: foreground)
-q/-exit-prompt prompt for <return> prior to exit (default: no prompt)
-R/-reset [rst] reset for STM8: 0=skip, 1=manual, 2=DTR line (RS232), 3=send 'Re5eT!' @ 115.2kBaud, 4=Arduino pin pin 8, 5=Raspi pin 12, 6=RTS line (RS232) (default: manual)
-i/-interface [line] communication interface: 0=UART, 1=SPI via Arduino, 2=SPI via spidev (default: UART)
-u/-uart-mode [mode] UART mode: 0=duplex, 1=1-wire, 2=2-wire reply, other=auto-detect (default: auto-detect)
-p/-port [name] communication port (default: list available ports)
-b/-baudrate [speed] communication baudrate in Baud (default: 115200)
-V/-verify [method] verify flash content after upload: 0=skip, 1=CRC32 checksum, 2=read-back (default: read-back)
-j/-jump-addr [address] jump to address (as dec or hex) before exit of stm8gal, or -1 for skip (default: flash)
-w/-write-file [file [addr]] upload file from PC to uController. For binary file (*.bin) with address offset (as dec or hex)
-W/-write-byte [addr value] change value at given address (both as dec or hex)
-r/-read [start stop output] read memory range (as dec or hex) and save to file or print (output=console)
-e/-erase-sector [addr] erase flash sector containing given address (as dec or hex). Use carefully!
-E/-erase-full mass erase complete flash. Use carefully!
Notes:
-R 5
) is only available on a Raspberry Pi and if stm8gal was built with wiringPi support (see Building the Software)-i 2
) is only available if stm8gal was built with spidev support (see Building the Software)-i 1
) and reset via Arduino GPIO (-R 4
) requires an additional Arduino programmed as SPI bridgeSupported import formats (option '-w'):
Supported export formats (option '-r'):
Data is uploaded and exported in the specified order, i.e. later uploads may overwrite previous uploads. Also exports only contain the previous uploads, i.e. intermediate exports only contain the memory content up to that point in time.
supply the muBoard via USB from the PC, here a RasPi. This also establishes the USB<->UART connection via an on-board FT232 adapter
note name of serial port, e.g. COM10 (Win) or /dev/ttyUSB0 (Linux). Hint: launching stm8gal without argument lists the available ports
software usage:
-stm8gal -p /dev/ttyUSB0 -w main.ihx
(Linux)
-stm8gal -p COM10 -w main.ihx
(Windows)
software usage:
-stm8gal -p /dev/ttyAMA0 -w main.ihx -R 5
(RasPi 1+2)
-stm8gal -p /dev/serial0 -w main.ihx -R 5
(RasPi 3)
software usage:
-stm8gal -i 2 -p /dev/spidev0.0 -w main.ihx -R 5
Ensure voltage level compatibility between Arduino and STM8. Note that ATMega-based (8-bit) Arduinos generally have 5V GPIOs, while ARM-based (32-bit) boards only support 3.3V. Exposing a 3.3V device to 5V signals may damage the 3.3V device.
Supply the Arduino to the PC via USB. This also establishes an USB connection to the on-board microcontroller
Program the Arduino to act an an USB<->SPI bridge.
Note name of serial port, e.g. COM10 (Win) or /dev/ttyUSB0 (Linux). Hint: launching stm8gal without argument lists the available ports
connect the STM8S Discovery Board to the Arduino in the same sequence as shown below.
software usage:
-stm8gal -i 1 -p /dev/ttyUSB0 -w main.ihx -R 4
supply the muBoard via USB from the PC, here a RasPi. This also establishes the USB<->UART connection via an on-board FT232 adapter
note name of serial port, e.g. COM10 (Win) or /dev/ttyUSB0 (Linux). Hint: launching stm8gal without argument lists the available ports
software usage:
-stm8gal -p /dev/ttyUSB0 -r 0x8000 0x8FFF dump.s19
(Linux, Motorola S19 format)
-stm8gal -p /dev/ttyUSB0 -r 0x8000 0x8FFF dump.txt
(Linux, table format)
-stm8gal -p COM10 -r 0x8000 0x8FFF dump.s19
(Windows, Motorola S19 format)
To program via stm8gal, communication between PC and STM8 must be possible. On the STM8 side this is via UART or SPI, on the PC side this is generally via USB or RS232.
On some boards, e.g. the muBoard, an USB<->UART bridge is already present. In this case, no additional hardware is required
However, e.g. the popular STM8S Discovery and STM8L Discovery boards connect to a standard PC via SWIM (=debug) interface. In this case a separate adapter is required to connect to the respective STM8 UART or SPI pins, e.g. UM232R. When connecting, make sure that the voltage levels of STM8 and the adapter are compatible. Exposing a 3.3V device to 5V signals may damage the 3.3V device.
Exception is the Raspberry Pi or similar “embedded PCs“ with direct access to UART and SPI pins via the GPIO header. In this case make sure that the voltage levels of STM8 and embedded PC are compatible, e.g. for RasPi with 3.3V pins also supply the STM8 with Vdd=3.3V. As noted above, never expose a 3.3V device to 5V signals.
Alternatively an Arduino can be used to act as a USB<->SPI bridge using a dedicated "gateway software". For the Arduino project and a technical documentation see the Arduino SPI_bridge repository. Again, note compatible voltage levels of Arduino and STM8.
Prior to uploading code via stm8gal the STM8 ROM bootloader needs to be activated via option bytes. For details see the respective STM8 device datasheet. If required, change the option bytes via SWIM debug interface using
ST Visual Programmer application by STM (proprietary, Windows only)
stm8flash by Valentin Dudouyt to upload and run the STM8 program in subfolder './BSL_activate'
Notes
Virgin devices (i.e. flash completely erased) automatically have the bootloader enabled
The BSL can be entered only within 1s after reset or power-on. Exception are virgin devices, which remain in bootloader mode indefinitely.
The UART "reply" mode (see above) supports single-wire interfaces like LIN or ISO9141. It requires a "Rx echo" for each sent byte. Using the reply mode with dual wires therefore requires stm8gal to echo each received byte individually, which results in extremely low reading speed due to USB latency.
SPI communication via spidev or Arduino SPI bridge works reliably only up to 250kBaud in my test setup (see above)
The STM32 uses a very similar bootloader protocol, so adapting the flasher tool for STM32 should be straightforward. However, I have no board available, but please feel free to go ahead...
stm8gal has recently been tested only for the below STM8 devices and operating systems. Theoretically it should work for all STM8 devices with bootloader, especially since STM8AF, STLUX, STNRG and STM8SPLNB seem to be test variants of the STM8S, and STM8AL and STM8T seem to be test variants of the STM8L. However, this has not been tested, so if you use stm8gal in another setup, any feedback is highly appreciated!
green: test passed; yellow: not yet tested
If you are aware of bugs, please drop me a note or start an issue on the project homepage.
v1.6.0 (2023-08-08)
v1.5.0 (2021-01-23)
v1.4.3 (2021-01-09)
v1.4.2 (2020-12-26)
v1.4.1 (2020-12-13)
v1.4.0 (2020-04-09)
v1.3.0 (2019-01-02)
v1.2.0 (2018-12-02)
v1.1.8 (2018-10-07)
v1.1.7 (2018-01-04)
v1.1.6 (2017-12-22)
v1.1.5 (2017-12-20)
v1.1.4 (2017-12-14)
v1.1.3 (2017-08-29)
v1.1.2 (2016-05-25)
v1.1.1 (2016-02-03):
v1.1.0 (2015-06-22):
v1.0.0 (2014-12-21):