STM8 on Raspberrypi

Hi
I used Arduino a lot and since last year using PIO for my coding.
thanks for making advanced things simpler.
BTW i am going to learn how to use STM8 but my computer is just a RPI4 4GB, i tried to init a STM8 project with pio project init --ide vim --board stm8s003f3 and, while installing requirements got this error UnknownPackageError: Could not find the package with 'platformio/toolchain-sdcc @ ~1.30901.0' requirements for your system 'linux_aarch64'
it’s easy to know there is no package of SDCC for this CPU architecture,
the idea is:

  1. use os built-in SDCC, it’s working perfect on my system
  2. compile it manually for PIO
    is there any way to do one of solutions? or any other solutions?
    thanks

Oh, that’s good! That means you can create a PlatformIO-compatible package and reference it.

For that, first of all, create a new folder and in there copy all SDCC files in the same way that the regular toolchain-sdcc package does, e.g., as seen in the version for ARM32:

https://dl.registry.platformio.org/download/platformio/tool/toolchain-sdcc/1.30901.11242/toolchain-sdcc-linux_armv6l-1.30901.11242.tar.gz

grafik

I’ll assume that this will be done under /home/user/toolchain-sdcc.

Next, you want to add a package.json in the root of that folder with a content that declares compatibility with linux_aarch64:

{
  "name": "toolchain-sdcc",
  "version": "1.30901.11242",
  "description": "Small Device C compiler suite",
  "keywords": [
    "build tools",
    "compiler",
    "assembler",
    "linker",
    "preprocessor"
  ],
  "homepage": "http://sdcc.sourceforge.net",
  "license": "GPL-2.0-or-later",
  "repository": {
    "type": "svn",
    "url": "https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc"
  },
  "system": [
    "linux_aarch64"
  ]
}

Finally, you go make a local edit to your platform file, that is,

~/.platformio/platforms/ststm8/platform.py

you modify

to say

    if "arduino" in variables.get("pioframework", []):
        self.packages["toolchain-sdcc"]["version"] = "symlink:////home/user/toolchain-sdcc"
   else:
        self.packages["toolchain-sdcc"]["version"] = "symlink:////home/user/toolchain-sdcc"
1 Like

Dude,
i didn’t get it how it worked, but it worked.
i passed that level
i but i have this error now:

UnknownPackageError: Could not find the package with 'platformio/tool-stm8binutils @ 0.230.0' requirements for your system 'linux_aarch64'

so if i use 32-bit instead of 64-bit raspbian os it will be okay? this would be last solution if it will work

thanks you very fast reply dear [maxgerhardt]

Using a 32-bit Raspbian will work for toolchain-sdcc, but tool-stm8binutils is not available for Linux ARM32, see https://registry.platformio.org/tools/platformio/tool-stm8binutils/compatibility.

The code comes from https://stm8-binutils-gdb.sourceforge.io/. You would need to compile that yourself, the 2020 version.

This holds the stm8-gdb and other utilities like stm8-size as its most important part.

Once you have the compiled package in the same folder structure as the Linux version

https://dl.registry.platformio.org/download/platformio/tool/tool-stm8binutils/0.230.0/tool-stm8binutils-linux_x86_64-0.230.0.tar.gz

you again add a package.json to it

{
  "name": "tool-stm8binutils",
  "version": "0.230.0",
  "description": "STM8 toolchain with GDB debugger",
  "keywords": [
    "toolchain",
    "build tools",
    "compiler",
    "assembler",
    "linker",
    "preprocessor",
    "stmicroelectronics",
    "stm8"
  ],
  "homepage": "https://stm8-binutils-gdb.sourceforge.io/",
  "license": "GPL-3.0-or-later",
  "system": [
    "linux_aarch64"
  ],
  "repository": {
    "type": "git",
    "url": "https://git.code.sf.net/p/stm8-binutils-gdb/code"
  }
}

Then you can edit your ~/.platformio/platforms/ststm8/platform.json

to be

    "tool-stm8binutils": {
      "type": "uploader",
      "owner": "platformio",
      "version": "symlink:///home/user/tool-stm8binutils"
    },

assuming the new tool is under /home/user/tool-stm8binutils

i couldn’t compile stm8-binutils, it at the middle of compiling says maybe you want to install make, which doesn’t make scene.
i am going to try box64. use PIO in x86_64 on RPI

I think you’re talking about the error

/home/max/stm8-binutils-gdb-sources/binutils-2.30/missing: 81: makeinfo: not found
WARNING: 'makeinfo' is missing on your system.
         You should only need it if you modified a '.texi' file, or
         any other file indirectly affecting the aspect of the manual.
         You might want to install the Texinfo package:
         <http://www.gnu.org/software/texinfo/>
         The spurious makeinfo call might also be the consequence of
         using a buggy 'make' (AIX, DU, IRIX), in which case you might
         want to install GNU make:
         <http://www.gnu.org/software/make/>

makeinfo is used to create PDF files from the LaTeX files. Doing

sudo apt-get install texinfo texi2html

will install it and it should go through.

I managed to compile stm8-binutils natively for AArch64 on my Raspberry Pi 3B.

This means that you can skip the compiling step and can edit the platform.json as said above, but with a version of

    "tool-stm8binutils": {
      "type": "uploader",
      "owner": "platformio",
      "version": "https://github.com/maxgerhardt/tool-stm8binutils-aarch64.git"
    },

(this expects that git is installed on the Pi)

FYI: There’s also a stripped branch with smaller binary sizes, (13MB instead of 50MB), to use it you can just

      "version": "https://github.com/maxgerhardt/tool-stm8binutils-aarch64.git#stripped"
1 Like

thanks a lot dear maxgerhardt
it’s working perfectly fine,
you rock.
you are double awesome.
i used full version (first link) not stripped down(second link).
before changing platform.json and testing i also installed texinfo texi2html packages.
thanks again

Can you create and upload a tar.gz file from your working toolchain-sdcc package that works on linux_aarch64? The PlatformIO people might be able to add it to the registry. (tar -czvf toolchain-sdcc.tar.gz /home/user/toolchain-sdcc)

in $HOME/.platformio/platforms/ststm8 just edited:
platform.json:

{
  "name": "ststm8",
  "title": "ST STM8",
  "description": "The STM8 is an 8-bit microcontroller family by STMicroelectronics an extended variant of the ST7 microcontroller architecture. STM8 microcontrollers are particularly low cost for a full-featured 8-bit microcontroller.",
  "homepage": "https://www.st.com/en/microcontrollers/stm8-8-bit-mcus.html",
  "license": "Apache-2.0",
  "keywords": [
      "dev-platform",
      "STMicroelectronics",
      "STM8",
      "8-bit"
  ],
  "engines": {
    "platformio": "^6"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/platformio/platform-ststm8.git"
  },
  "version": "2.1.0",
  "frameworks": {
    "arduino": {
      "package": "framework-arduinoststm8",
      "script": "builder/frameworks/arduino.py"
    },
    "spl": {
      "package": "framework-ststm8spl",
      "script": "builder/frameworks/spl.py"
    }
  },
  "packages": {
     "toolchain-sdcc": {
      "type": "toolchain",
      "owner": "platformio",
      "version": ">=1.40100.0,<1.40201.0",
      "optionalVersions": [
        "~1.30901.0"
      ]
    },
    "framework-arduinoststm8": {
      "type": "framework",
      "optional": true,
      "owner": "platformio",
      "version": "~0.50.0"
    },
    "framework-ststm8spl": {
      "type": "framework",
      "optional": true,
      "owner": "platformio",
      "version": "0.20301.181217"
    },
    "tool-stm8binutils": {
      "type": "uploader",
      "owner": "platformio",
      "version": "https://github.com/maxgerhardt/tool-stm8binutils-aarch64.git"
    },
    "tool-stm8gal": {
      "type": "uploader",
      "optional": true,
      "owner": "platformio",
      "version": "~1.5.0"
    },
    "tool-stm8flash": {
      "type": "uploader",
      "optional": true,
      "owner": "platformio",
      "version": "~1.1.0"
    },
    "tool-openocd": {
      "type": "uploader",
      "optional": true,
      "owner": "platformio",
      "version": "~2.1000.0"
    }
  }
}

and platform.py:

# Copyright 2014-present PlatformIO <contact@platformio.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from platformio.public import PlatformBase


class Ststm8Platform(PlatformBase):

    def configure_default_packages(self, variables, targets):
        if "arduino" in variables.get("pioframework", []):
            self.packages["toolchain-sdcc"]["version"] = "symlink:////home/whisper/.platformio/packages/toolchain-sdcc"
        else:
            self.packages["toolchain-sdcc"]["version"] = "symlink:////home/whisper/.platformio/packages/toolchain-sdcc"


        return super().configure_default_packages(variables, targets)

    def get_boards(self, id_=None):
        result = super().get_boards(id_)
        if not result:
            return result
        if id_:
            return self._add_default_debug_tools(result)
        else:
            for key in result:
                result[key] = self._add_default_debug_tools(result[key])
        return result

    def _add_default_debug_tools(self, board):
        debug = board.manifest.get("debug", {})
        upload_protocols = board.manifest.get("upload", {}).get(
            "protocols", [])
        if "tools" not in debug:
            debug["tools"] = {}

        # Configure OpenOCD debugging.
        # Only via ST-Link for now
        for link in ("stlink",):
            if link == "stlink":
                server_args = ["-s", "$PACKAGE_DIR/scripts"]
                if debug.get("openocd_board"):
                    server_args.extend([
                        "-f", "board/%s.cfg" % debug.get("openocd_board")
                    ])
                else:
                    assert debug.get("openocd_target"), (
                        "Missing target configuration for %s" % board.id)
                    server_args.extend([
                        "-f", "interface/stlink-dap.cfg",
                        # transport protocol swim is automatically selected, no need to set it
                        "-f", "target/%s.cfg" % debug.get("openocd_target")
                    ])
                    server_args.extend(debug.get("openocd_extra_args", []))

                debug["tools"][link] = {
                    "server": {
                        "package": "tool-openocd",
                        "executable": "bin/openocd",
                        "arguments": server_args
                    }
                }
            debug["tools"][link]["onboard"] = link in debug.get(
                "onboard_tools", [])
            debug["tools"][link]["default"] = link in debug.get(
                "default_tools", [])

        board.manifest["debug"] = debug
        return board

in $HOME/.platformio/packages/toolchain-sdcc creted a file named package.json:

{
  "name": "toolchain-sdcc",
  "version": "1.30901.11242",
  "description": "Small Device C compiler suite",
  "keywords": [
    "build tools",
    "compiler",
    "assembler",
    "linker",
    "preprocessor"
  ],
  "homepage": "http://sdcc.sourceforge.net",
  "license": "GPL-2.0-or-later",
  "repository": {
    "type": "svn",
    "url": "https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc"
  },
  "system": [
    "linux_aarch64"
  ]
}

also before editing all the files:

sudo apt install sdcc

not sure this one is requred or not:

sudo apt install texinfo texi2html