STM8 Debugging on M1 Mac

STM8 Debugging on M1 Mac

I decided to venture into the true unknown by attempting to debug an STM8 using my Mac running Apple Silicone (M1 Max). It’s very awkward, but it works. Here’s what I had to do.

Software Setup

Unlike the STM32 line of MCUs, the STM8 does not use STM32CubeIde. Instead, it uses this ancient looking IDE called STVD, which only works on Windows. Fortunately, the STM8 is supported by PlatformIO . However, there are a couple of things that need to be tweaked for debugging to work.

Here is my PlatformIO config:

platform = ststm8
board = stm8s003k3
framework = spl
upload_protocol = stlinkv2
build_type = debug
build_flags = --debug --out-fmt-elf
build_unflags = -Og -ggdb2 -g2

Boards Config

PlatformIO did not have the exact MCU that matched the one I was using. So I created a file called stm8s00k3 underneath the boards directory with the following content:

    "build": {
      "core": "sduino",
      "extra_flags": "-DSTM8S_003 -DSTM8S003",
      "f_cpu": "16000000L",
      "cpu": "stm8",
      "mcu": "stm8s003k3t6",
      "variant": "standard"
    "debug": {
      "svd_path": "STM8S003K3.svd",
      "openocd_target": "stm8s003"
    "frameworks": [
    "upload": {
      "maximum_ram_size": 1024,
      "maximum_size": 8192,
      "protocol": "stlinkv2",
      "protocols": [
    "name": "ST STM8S003K3 chip",
    "url": "",
    "vendor": "ST"

SDCC Compiler

The official compiler provided by ST for the STM8 is not MacOS compatible. So you will need to install sdcc instead (Small Device C compiler). Fortunately, PlatformIO should automatically do this for you when you setup the platform.

Python 2.7

For debugging, PlatformIO is relying on a modified GDB called stm8-gdb . The tool has not been updated in a very long time and as such, it is only compatible with Python 2.7. The easiest way to install Python is just go to the official site and install the 2.7 package. PlatformIO will not install Python automatically on your system.

x86 Version of Homebrew

So here’s the catch, that stm8-gdb I mentioned earlier was not built for the Apple silicone architecture. Therefore, PlatformIO downloads the Intel version of the stm8-gdb. However, that version relies on the x86 version of the libmpfr.6.dylib (multi-precision floating point library) being available on your system. If you’re running a Mac with Apple silicone then you will only have the arm version of that library.

Since stm8-gdb is open source, you could compile it for the Apple architecture. However, when I tried to do this, I ended up going down a huge rabbit hole of errors and missing dependencies. In the interest of time, I just installed the x86 version of Homebrew. You can have the x86 and arm version of homebrew installed at the same time.

Once the x86 version was installed, I installed the x86 version of the multi-precision floating point library:

arch -x86_64 brew install mpfr 

Copy Objdump

Admittedly, I don’t quite remember that error that I ran to, but I have this down in my notes so I assume it was important. I believe there was a something missing from the sdcc install that PlatformIO does. In any case I needed to copy stm8-objdump from /.platformio/packages/tool-stm8binutils/bin to /.platformio/packages/tool-sdcc/bin

Hardware Setup

I ordered this STM8SVLDISCOVERY board from DigiKey. If you plug it into your Mac and try to upload sample code from PlatformIO you will probably get this error: another process has device opened for exclusive access.

The issue is that this dev board comes with an older version of the STlink (STlink V1). There is some issue with the kext that makes STlink V1 debuggers not work on newer MacOS installs. If you really want to get the STlink V1 to work, then there is a work around that involves going into your system recovery and disabling some stuff. I wasn’t ready to mess around with all these settings.

Instead, I just plugged my STLink V2 debugger into the discovery board. The V2 debugger has a SWIM breakout that I plugged into the appropriate pins on the discovery board. I then connected the power and ground(s) and changed the jumper accordingly.

STM8 with STLinkV2 debugger


After I completed all of the above, I was able to get STM8 debugging working on my M1 Mac. At this point I was able to add breakpoints, pause, flash, etc.