This post is also available in: cs

This post is part of a series of articles about STM8 development with OpenSource tools. You can find an overview of the whole toolchain in the post STM8 Development with OpenSource Tools.

Hint

If you have a Linux distribution based on Debian (Ubuntu, Mint, Devuan, …), you don’t need to do anything from this article. Just use our repository with precompiled packages. Another option is the pre-prepared installation for VirtualBox.

This article is for users of other distributions and other operating systems, and for those who want to compile the tools from source code. It is organised by operating system:

In each chapter the tools are in the same order as in the following table. The flashing script, which is common to all systems, is in the chapter OpenOCD flashing script.

Tool What it is for Debian package Procedure
make, git toolchain make, git Linux, macOS, Windows
SDCC compiler sdcc, sdcc-libraries Linux, macOS, Windows
OpenOCD flashing and debugging openocd Linux, macOS, Windows
stm8flash flashing stm8flash Linux, macOS, Windows: STVP instead
STVP flashing on Windows — Windows
stm8-binutils-gdb debugger stm8-gdb stm8-binutils-gdb Linux, macOS, Windows
cgdb frontend for GDB cgdb Linux, macOS, Windows
ccls LSP server for the editor ccls Linux, macOS, Windows
SDCC-gas, sdccrm historical solutions — Historical Solutions

 

Watch out for SDCC version

In the SDCC compiler (regardless of OS), version 4.5.0 has a bug that makes it unusable for the STM8 platform. The bug is already fixed, but you need to be careful and install version 4.4.0, 4.6.0 or newer, or a nightly build.

Quick one-command install

If you don’t want to assemble everything by hand, one command is enough. The script installs the SDCC compiler, OpenOCD, stm8-gdb, make, git, python and the VS Code / VSCodium extension. If a package manager is missing (Homebrew on macOS, Chocolatey on Windows), it installs that too. The scripts are in the toolchain repository, so have a look at them before running. You can run them repeatedly; anything already installed is skipped.

Linux (Debian, Ubuntu, Mint, …; amd64):

1
curl -fsSL https://gitlab.com/spseol/mit-no/STM8S-toolchain/-/raw/main/.make/install/linux.sh | bash

macOS (Apple Silicon):

1
curl -fsSL https://gitlab.com/spseol/mit-no/STM8S-toolchain/-/raw/main/.make/install/macos.sh | bash

Windows 10/11 (in PowerShell; asks once for administrator rights). You can choose the package manager, both variants do the same thing. With Chocolatey (the script installs it if missing):

1
irm https://gitlab.com/spseol/mit-no/STM8S-toolchain/-/raw/main/.make/install/windows.ps1 | iex

Or with winget (already included in Windows 10/11):

1
irm https://gitlab.com/spseol/mit-no/STM8S-toolchain/-/raw/main/.make/install/windows-winget.ps1 | iex

The script does not install the ST-Link driver for Windows (ST publishes it only after registration). If the board is not found, install STSW-LINK009.

The following chapters describe how to install each tool by hand, or compile it from source.

Linux

Basic Tools

On Linux you call something like:

1
sudo apt install git make

SDCC

SDCC - Small Device C Compiler is a C compiler for STM8. Why SDCC and how the toolchain uses it is described in the main article. Watch out for version 4.5.0 (see the warning above).

On Debian and derived distributions you install SDCC in the right version from our repository:

1
sudo apt -t mamut install sdcc sdcc-libraries

Otherwise SDCC is part of most Linux distributions; so you call something like:

1
sudo apt install sdcc sdcc-libraries

But check the version (sdcc -v) so you don’t end up with 4.5.0.

From source code

Sometimes it happens that your distribution doesn’t have SDCC in the right version, or you want to install a nightly build. I use the program Stow for installing non-distribution packages.

1
sudo apt install stow

Libraries and dependencies needed for the build can be installed like this:

1
sudo apt build-dep sdcc

Then just download the source code, unpack and install:

1
2
3
4
5
6
7
cd sdcc-sources-4.5.12  # this is the name of the directory with the sources
./configure --prefix=/usr/local/stow/sdcc-4.5.12
make
sudo make install

cd /usr/local/stow
sudo stow sdcc-4.5.12

One small note: SDCC supports many different platforms that I don’t need. So my ./configure looks like this:

1
2
3
4
5
6
7
8
./configure --prefix=/usr/local/stow/sdcc-4.5.12 \
--disable-z180-port --disable-r2k-port --disable-r2ka-port --disable-r3ka-port \
--disable-gbz80-port --disable-tlcs90-port --disable-ez80_z80-port --disable-z80n-port \
--disable-ds390-port --disable-ds400-port --disable-pic14-port --disable-pic16-port \
--disable-hc08-port --disable-s08-port --disable-pdk13-port --disable-pdk14-port \
--disable-pdk15-port --disable-mos6502-port --disable-sm83-port --disable-f8-port \
--disable-mos65c02-port --disable-r800-port --disable-f8l-port --disable-r4k-port \
--disable-r5k-port --disable-r6k-port --disable-ez80-port

OpenOCD

Open On-Chip Debugger is a tool for uploading a program to the chip and for debugging. How the toolchain uses it is described in the main article.

Installation on Linux is done with a simple command:

1
sudo apt install openocd

To enable openocd to do simple flashing, you need to add a script, see OpenOCD flashing script.

stm8flash

A program for uploading a program to the chip.

https://github.com/vdudouyt/stm8flash

On Debian and derived distributions there is a ready-made package in our repository:

1
sudo apt -t mamut install stm8flash

From source code

In most Linux distributions it needs to be built manually:

1
2
3
4
5
6
sudo apt install pkg-config libusb-1.0-0-dev

git clone --depth 1 https://github.com/vdudouyt/stm8flash.git
cd stm8flash
make
sudo make install

stm8-binutils-gdb

The STM8 port of GNU binutils is needed for linking and debugging. It contains the debugger stm8-gdb, whose use is described in A small STM8-GDB course.

Newer and nicer GDB v15.0

A significantly newer version of stm8-gdb based on GDB 15.0 is currently available. It brings improvements over the old version 8.1: working with it is clearer thanks to colours, and it is simply a newer version overall…

On Debian and derived distributions there is a ready-made package in our repository:

1
sudo apt -t mamut install stm8-binutils-gdb

A prebuilt package is also available on the releases page…

You can download the sources from my fork on GitLab:

1
2
git clone --depth 1  https://gitlab.com/spseol/mit-no/stm8-binutils-gdb.git
cd stm8-binutils-gdb

The build is very simple:

1
2
3
4
5
6
7
./configure \
  --prefix=/usr/local/stow/stm8-binutils-gdb \
  --target=stm8-none-elf32 \
  --program-prefix=stm8-

make -j$(nproc)
sudo make install

And again Stow.

1
2
cd /usr/local/stow
sudo stow stm8-binutils-gdb

Our toolchain needs GDB with Python support. ./configure turns it on by itself when it finds python3. You can verify it like this (it must print 1):

1
stm8-gdb -batch -ex 'python print(1)'

Legacy GDB 8.1

On the internet you will find various guides for building GDB version 8.1 from older sources. Specifically, it is the project stm8-binutils-gdb. It works well, but if you want to use it, I recommend rather our repo stm8-binutils-gdb-legacy, because its sources can be built even today, with the current Python 3.12+.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
curl -fSL 'https://gitlab.com/spseol/mit-no/stm8-binutils-gdb-legacy/-/archive/main/stm8-binutils-gdb-legacy-main.tar.bz2?ref_type=heads' \
 |  tar xj
cd stm8-binutils-gdb-legacy-main
export PREFIX=/usr/local/stow/stm8-binutils-gdb-legacy
./configure_binutils.sh
cd binutils-2.30+gdb-8.1-patched
make
sudo make install

cd /usr/local/stow
sudo stow  stm8-binutils-gdb-legacy

cgdb

cgdb is a colourful frontend for GDB. make debug opens it automatically; when cgdb is not installed, it starts GDB in TUI mode. More in the article A small STM8-GDB course.

1
sudo apt install cgdb

ccls

ccls is an LSP server for code completion and error highlighting in the editor. It is optional. Why I recommend it is described in the main article.

1
sudo apt install ccls

An alternative is clangd, which also works quite well (sudo apt install clangd).

macOS

Basic Tools

On macOS it should be easy, because it is also Unix. Just use HomeBrew:

1
brew install make git coreutils

SDCC

Watch out for version 4.5.0 (see the warning above). HomeBrew already offers SDCC in version 4.6.0, so just:

1
brew install sdcc

From source code

If you want a different version, for example a nightly build, download the source code, unpack it, and ….

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
brew install stow
cd sdcc-sources-4.5.12  # this is the name of the directory with the sources
export CPPFLAGS="-I/opt/homebrew/include"
export LDFLAGS="-L/opt/homebrew/lib"

./configure --prefix=/usr/local/stow/sdcc-4.5.12 \
--disable-z180-port --disable-r2k-port --disable-r2ka-port --disable-r3ka-port \
--disable-gbz80-port --disable-tlcs90-port --disable-ez80_z80-port --disable-z80n-port \
--disable-ds390-port --disable-ds400-port --disable-pic14-port --disable-pic16-port \
--disable-hc08-port --disable-s08-port --disable-pdk13-port --disable-pdk14-port \
--disable-pdk15-port --disable-mos6502-port --disable-sm83-port --disable-f8-port \
--disable-mos65c02-port --disable-r800-port --disable-f8l-port --disable-r4k-port \
--disable-r5k-port --disable-r6k-port --disable-ez80-port

make && sudo make install

cd /usr/local/stow
sudo stow sdcc-4.5.12

sdcc -v

OpenOCD

1
brew install open-ocd

For the flashing script see OpenOCD flashing script.

stm8flash

stm8flash is not in HomeBrew, so you have to build it. The project’s Makefile accounts for macOS and looks for the libusb library using pkg-config:

1
2
3
4
5
6
brew install libusb pkg-config

git clone --depth 1 https://github.com/vdudouyt/stm8flash.git
cd stm8flash
make
sudo make install

stm8-binutils-gdb

It works on a Mac with Apple Silicon (arm64). A volunteer tried the build from sources and the content of the prebuilt package on a clean MacBook (macOS 26), then also with a connected Nucleo-STM8S208RB: flashing, debugging through OpenOCD, make cgdb and the VS Code extension work.

Prebuilt package

From version v15.0.50-stm8.2 the releases have an installer .pkg and an archive .tar.gz with the same content (macOS 12 and newer). Their stm8-gdb has its own bundled Python, so make debug and the VS Code extension work and you do not need to install anything else (HomeBrew, Python).

(Built on a Mac with Apple Silicon (arm64).)

The best way to install the .pkg is the terminal:

1
sudo installer -pkg ~/Downloads/nazev.pkg -target /

(Replace nazev.pkg with the name of the downloaded file.) The installer is not signed, so when installing by clicking, you must right-click the file → Open. Unpack the archive with sudo tar -xzf stm8-binutils-gdb-macos-arm64.tar.gz -C /, or without administrator rights into your own folder and add it to PATH:

1
2
mkdir -p ~/stm8 && tar -xzf stm8-binutils-gdb-macos-arm64.tar.gz -C ~/stm8
export PATH="$HOME/stm8/usr/local/bin:$PATH"    # keep it in ~/.zprofile

Check (it must print 1):

1
stm8-gdb -batch -ex 'python print(1)'

PATH and VS Code

make cgdb and the VS Code extension need stm8-gdb and openocd in PATH.

Older release

Do not use v15.0.50-stm8.1: its stm8-gdb has no Python and its stm8-ld writes wrong addresses.

From source

The easiest way is the script contrib/build-macos.sh in the repository. It needs only the Command Line Tools (xcode-select --install) and Python 3.14 from python.org, not HomeBrew. It downloads and builds GMP and MPFR itself and makes the same package as the one in the releases:

1
2
3
git clone --depth 1  https://gitlab.com/spseol/mit-no/stm8-binutils-gdb.git
cd stm8-binutils-gdb
contrib/build-macos.sh ~/stm8-build-out     # result in ~/stm8-build-out/out/

By hand, the procedure is similar to GDB v15.0 on Linux, but you have to install GMP and MPFR from HomeBrew and pass them to ./configure, use the zlib of the system (the bundled one does not compile with the new SDK) and give Python explicitly, because the Command Line Tools have no python3-config:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
brew install gmp mpfr texinfo stow

./configure \
  --prefix=/usr/local/stow/stm8-binutils-gdb \
  --target=stm8-none-elf32 \
  --program-prefix=stm8- \
  --with-system-zlib \
  --with-gmp=$(brew --prefix gmp) \
  --with-mpfr=$(brew --prefix mpfr) \
  --with-python=/Library/Frameworks/Python.framework/Versions/3.14/bin/python3 \
  --disable-nls --disable-werror \
  --disable-sim --disable-gprofng --disable-gdbserver

make -j$(sysctl -n hw.ncpu)
sudo make install

cd /usr/local/stow
sudo stow stm8-binutils-gdb

Python from HomeBrew (--with-python=$(brew --prefix python)/bin/python3) works too. Without Texinfo (makeinfo) add MAKEINFO=true to both make and make install.

cgdb

cgdb is in HomeBrew:

1
brew install cgdb

make cgdb (and make debug) work with it on macOS if stm8-gdb is in PATH; otherwise cgdb says Debugger "stm8-gdb" not found.

ccls

1
brew install ccls

Windows

I spent a lot of time porting to Windows. But Microsoft throws quite a few obstacles in my way: I get it working — it works, an update comes — and I have to debug yet another problem. It just causes trouble and I have absolutely no motivation to fix it, because I don’t know when Microsoft will break my work again; and I haven’t even tried it on W11. Compilation is terribly slow. So my advice is:

Hint

If you really insist on Windows and have some good reason to use this underdeveloped OS, install VirtualBox and use the pre-prepared installation.

Nevertheless, at the moment it seems that the toolchain is fully functional on Windows too, so if you are brave and don’t mind that compilation is really slow, go for it:

Basic Tools

On Windows the easiest way to install is with Chocolatey:

1
choco install make git vscodium

If you don’t have Python yet, you can also install Python:

1
choco install python

Bash is part of the Git package. On Windows it is also worth setting up Bash a little so it works well with make. So copy the configuration from .make/bashrc to the home directory.

1
cp .make/bashrc ~/.bashrc

SDCC

On Windows the SDCC installation must be done by clicking through the installer. You can download it here: https://sourceforge.net/projects/sdcc/files/sdcc-win64/ and continue in the Windows-favourite way — by clicking. Watch out for version 4.5.0 (see the warning above).

OpenOCD

On Windows it is similarly simple thanks to Chocolatey:

1
choco install openocd

For the flashing script see OpenOCD flashing script.

STVP

The toolchain uses the STVP program for flashing on Windows.

STVP is for Windows only. If you have already installed STVD, you already have STVP installed, because it is part of its installation. It can also be installed separately — without STVD.

stm8-binutils-gdb

A ready-made binary package for Windows is available on the releases page: the installer stm8-binutils-gdb-windows-x64-setup.exe and the archive stm8-binutils-gdb-windows-x64.zip with the same content. Just download and install it.

If you want to compile it yourself, you will find the installation script contrib/build-windows.sh in the repository stm8-binutils-gdb.

cgdb

I have no verified procedure for Windows. Moreover, I expect that Windows users will rather use the VSCode plugin

ccls

Chocolatey does offer a ccls package, but it is old (a 2022 version) and unusable. Install ccls for Windows from our releases on GitLab instead.

An alternative is the clangd plugin for VS Code (for VSCodium it is on Open VSX). It also works well (verified 9 Nov 2026): the plugin downloads the required binaries itself.

OpenOCD Flashing Script

To enable openocd to do simple flashing, you need to add a script that can do it. It is part of the toolchain (file .make/stm8s-flash.cfg, make flash uses it, nothing to add). If you use openocd without the toolchain, add it to the end of the stm8s.cfg configuration file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
proc program_device {filename flashstart} {
  halt
  wait_halt
  load_image $filename $flashstart
  sleep 10
  reset halt
  resume
  sleep 10
  shutdown
};

On Linux the full path might look like this: /usr/share/openocd/scripts/target/stm8s.cfg. On macOS with HomeBrew most likely $(brew --prefix)/share/openocd/scripts/target/stm8s.cfg. If you installed on Windows using Chocolatey, it will most likely be this path: C:\ProgramData\chocolatey\lib\openocd\tools\install\share\openocd\scripts\target\stm8s.cfg.

Historical Solutions

The following two tools are more of a historical leftover and in the vast majority of cases you don’t need them. Why they exist at all is described in the article on dead code removal.

SDCC-gas

https://github.com/hainguyen8y/sdcc-gas

The project is most likely dead

The original XaviDCR92/sdcc-gas repository has disappeared from GitHub (404), so I link to a copy by another user (same history, last commit from 10 Nov 2019). The original page is also preserved in the Wayback Machine. More in the separate article.

For everything to work you need to download the source code mentioned above and build it. I do it like this (I use Stow):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
sudo apt install stow
sudo apt build-dep sdcc

cd sdcc-gas
./configure --prefix=/usr/local/stow/sdcc-gas
make
sudo make install

cd /usr/local/stow
sudo stow sdcc-gas

SDCC-gas also needs stm8-binutils-gdb.

I have not tried building SDCC-gas on macOS or Windows.

sdccrm

https://github.com/sealj553/sdccrm

The original repository has disappeared

The XaviDCR92/sdccrm repository has disappeared from GitHub (404) and development is most likely dead. I therefore link to a working copy by another user. The original state is also preserved in the Wayback Machine. More in the separate article.

You have to build sdccrm from source code. It is a fairly small program with no dependencies, so it can be compiled easily on Linux and on Windows — but just in case, a Windows binary is included in the toolchain in the file .make/sdccrm.exe.

On Linux:

1
apt install gcc

or on macOS:

1
xcode-select --install

or on Windows:

1
choco install mingw

and then just:

1
2
cd sdccrm
make