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. Each tool has its own section with a procedure for Linux, macOS and Windows.

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

Unverified procedures

I wrote some of the macOS procedures from documentation, but I have nothing to test them on. They are marked as unverified. If you try them, please let me know whether they work.

Basic Tools

Linux

On Linux you call something like:

1
sudo apt install git make

MacOS

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

1
brew install make git coreutils

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 does work on Windows, so if you are brave:

On Windows the easiest way to install is with Chocolatey:

1
2
choco install make git
choco install vscodium  mingw

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

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

Linux

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

MacOS

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

Windows

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

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.

Linux

Installation on Linux is done with a simple command:

1
sudo apt install openocd

MacOS

1
brew install open-ocd

Windows

On Windows it is similarly simple thanks to Chocolatey:

1
choco install openocd

Flashing script

To enable openocd to do simple flashing, you need to add a script that can do it. It is either part of the toolchain or you can 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 (unverified). 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.

stm8flash

A program for uploading a program to the chip. On Windows it is replaced by STVP.

https://github.com/vdudouyt/stm8flash

Linux

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

MacOS

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

Windows

On Windows the toolchain uses STVP instead of stm8flash.

STVP

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

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 (in Czech).

I recommend the newer version of stm8-gdb based on GDB v15.0.

Linux

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

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

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…

You can download the sources from my fork on GitLab:

1
2
3
# GitLab (recommended)
git clone --depth 1  https://gitlab.com/spseol/mit-no/stm8-binutils-gdb.git
cd stm8-binutils-gdb

(Better not to use the original fork, which ported the patches for GDB v8.1 into the current GDB, because it contains a few bugs.)

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

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

MacOS

Unverified. The procedure is the same as for GDB v15.0 on Linux. But GDB needs the GMP and MPFR libraries, which you have to install from HomeBrew and pass to ./configure:

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

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

./configure \
  --prefix=/usr/local/stow/stm8-binutils-gdb \
  --target=stm8-none-elf32 \
  --program-prefix=stm8- \
  --with-gmp=$(brew --prefix gmp) \
  --with-mpfr=$(brew --prefix mpfr) \
  --disable-werror

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

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

The extra commands from the file .make/stm8gdb.py need 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)'

Windows

Compilation from source code is theoretically possible on Windows too; in practice I have never tried it. Personally I would go (if someone forced me to use Windows) the route of Windows Subsystem for Linux. WSL 2 installation is very simple. Unfortunately USB cannot be natively connected in WSL — but it can be solved.

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 (in Czech).

Linux

1
sudo apt install cgdb

MacOS

Unverified. cgdb is in HomeBrew:

1
brew install cgdb

Windows

I have no verified procedure for Windows. But cgdb is commonly available in WSL.

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.

Linux

1
sudo apt install ccls

MacOS

1
brew install ccls

Windows

I have no verified procedure for Windows.

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 main article.

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 main 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 main 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 Windows:

1
choco install mingw

or on Linux:

1
apt install gcc

or on macOS (unverified):

1
xcode-select --install

and then just:

1
2
cd sdccrm
make