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 | |
MacOS¶
On macOS it should be easy, because it is also Unix. Just use HomeBrew:
1 | |
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 | |
If you don’t have Python yet, you can also install Python:
1 | |
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 | |
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 | |
Otherwise SDCC is part of most Linux distributions; so you call something like:
1 | |
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 | |
Libraries and dependencies needed for the build can be installed like this:
1 | |
Then just download the source code, unpack and install:
1 2 3 4 5 6 7 | |
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 | |
MacOS¶
HomeBrew already offers SDCC in version 4.6.0, so just:
1 | |
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 | |
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 | |
MacOS¶
1 | |
Windows¶
On Windows it is similarly simple thanks to Chocolatey:
1 | |
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 | |
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 | |
From source code¶
In most Linux distributions it needs to be built manually:
1 2 3 4 5 6 | |
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 | |
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 | |
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 | |
(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 | |
And again Stow.
1 2 | |
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 | |
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 | |
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 | |
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 | |
MacOS¶
Unverified. cgdb is in HomeBrew:
1 | |
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 | |
MacOS¶
1 | |
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 | |
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 | |
or on Linux:
1 | |
or on macOS (unverified):
1 | |
and then just:
1 2 | |