gicking / stm8gal

PC tool for uplading hexfiles to the STM8 microcontroller via UART or SPI , using the built-in ROM bootloader. Works under Windows and Posix operating systems
Apache License 2.0
80 stars 21 forks source link

drawing

Overview

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


License / Disclaimer


Building the Software

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:

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.


Linux

Use one of the following options to build stm8gal:

Note: Under Linux access to serial ports may be prohibited. To grant access rights see here


Raspberry Pi

Same as Linux above, but with additional option:


Windows

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


MacOSX

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!


Using the Software

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:


Supported File Formats

Supported 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.


Examples

Program custom muBoard via USB with manual reset

  1. supply the muBoard via USB from the PC, here a RasPi. This also establishes the USB<->UART connection via an on-board FT232 adapter

  2. note name of serial port, e.g. COM10 (Win) or /dev/ttyUSB0 (Linux). Hint: launching stm8gal without argument lists the available ports

  1. software usage:

    -stm8gal -p /dev/ttyUSB0 -w main.ihx (Linux)

    -stm8gal -p COM10 -w main.ihx (Windows)


Program STM8S Discovery Board via UART pins from Raspberry Pi with reset via GPIO

  1. connect the STM8S Discovery Board to the Raspberry Pi in the same sequence as shown below. Notes:

  1. 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)


Program STM8S Discovery Board via SPI pins from Raspberry Pi using spidev with reset via GPIO

  1. connect the STM8S Discovery Board to the Raspberry Pi in the same sequence as shown below. Notes:

  1. software usage:

    -stm8gal -i 2 -p /dev/spidev0.0 -w main.ihx -R 5


Program STM8S Discovery Board via Arduino SPI bridge and reset via GPIO

  1. 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.

  2. Supply the Arduino to the PC via USB. This also establishes an USB connection to the on-board microcontroller

  3. Program the Arduino to act an an USB<->SPI bridge.

  4. Note name of serial port, e.g. COM10 (Win) or /dev/ttyUSB0 (Linux). Hint: launching stm8gal without argument lists the available ports

  5. connect the STM8S Discovery Board to the Arduino in the same sequence as shown below.

  1. software usage:

    -stm8gal -i 1 -p /dev/ttyUSB0 -w main.ihx -R 4


Memory dump muBoard via USB with manual reset

  1. supply the muBoard via USB from the PC, here a RasPi. This also establishes the USB<->UART connection via an on-board FT232 adapter

  2. note name of serial port, e.g. COM10 (Win) or /dev/ttyUSB0 (Linux). Hint: launching stm8gal without argument lists the available ports

  1. 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)


Notes


Test Overview

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


Known Bugs

If you are aware of bugs, please drop me a note or start an issue on the project homepage.


Revision History

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):