There are several introduction articles for software development of the STM8 microcontroller from STMicroelectronics. Most of them are for MS Windows and different IDE’s. STMicroelectronics offers the STVD-STM8 IDE. It’s fairly dated and MS Windows only. The manufacturer is aware of this shortcomings and recommends to use IAR Studio instead. Unfortunately it only usable with a commercial license for quite some money, not up-to-date and MS Windows only too. The good news is there is a free development environment for STM8 with all bells and whistles that even runs under Mac OS X: Eclipse.
Setup Development Environment
Before we can start developing a firmware of the STM8 microcontroller we have to setup the hardware components of the development environment. You need a development board for the microcontroller and connect it with a Mac.
- USB to Serial adapter cable
Connect STM8 development board to Mac
- supply power to the STM8L-DISCOVERY board over USB
- power supply is handled via the Micro-USB connector of the board (the right USB port at the top image)
- → the two red LED’s are shining
- connect the USB-Serial adapter cable from Prolific via Serial connectors with the STM8L-DISCOVERY board
- black (GND) at GND
- white (RxD) at PC3
- green (TxD) at PC2
- see picture
- alternative connect the USB-Serial adapter cable from Olimex via Serial connectors with the STM8L-DISCOVERY board
- blue (GND) at GND
- green (RxD) at PC3
- red (TxD) at PC2
- connect the USB-Serial adapter cable with the Mac via USB port
- build up the connection via terminal in Eclipse
- see lower description
Eclipse can be configured to allow development of C++ firmware cod for the STM8 with editing, flashing and
debugging. There are some steps that are critical to get Eclipse to work with the STM8 board.
1. Install HomeBrew on Mac
- HomeBrew is used to comfortably install necessary tools over the command line
- only needed to be installed if not installed yet
- maybe ‚brew doctor‘ shows errors that have to be fixed before using HomeBrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew update brew doctor
2. Setup of Programmer ST-Link/V2
- ST-LINK/V2 is a programmer and debugger for STM8 and STM32
- can be installed with HomeBrewn
brew install autoconf automake pkg-config libusb libusb-compat stlink st-util -h
|st-util does not recognize the DISCOVERY board and has problems using it. A quick research shows that the tool only supports the SWD-mode for STM32-MCU’s. The STM8-MCU’s need the SWIM-mode. This mode is only usable with the tool stm8-flash that is not well-maintained. This tool does not allow debugging at the moment. Conclusion: Debugging of STM8 code is not usable under Linux or Mac OS X.|
3. Install SDCC Cross-Compiler
- SDCC is a free cross-complier for multiple microcontrollers with great compatibility and able to generate excellent results.
brew install sdcc sdcc -v
4. Install STM8Flash
git clone https://github.com/vdudouyt/stm8flash.git cd stm8flash make make install cd .. rm -R stm8flash stm8flash
5. Test if the STM8L-DISCOVERY board is responding
stm8flash -c stlinkv2 -p stm8l152?6 -r test.ihx
6. Install Eclipse
- Check if the Java runtime is up-to-date (
java -version) , and update the runtime. At the time of writing the current version is Java 8 update 181.
- Download Eclipse. Current version is Photon V4.8.0.
- During the installation choose the C/C++-edition.
- Start Eclipse and install updates: Menu Help → Check for Updates
7. Install SDCC-Plugin in Eclipse
- Download and unzip the Mac OS X Version of the CDCC Eclipse plugin from Sourceforge.net
- Open the installation folder of Eclipse in Finder: <user-home>/eclipse/cpp-photon/
- Open context menu of eclipse.app (right click) → Show Package Contents
- Navigate to the sub folder Contents/Eclipse/dropins
- move the unzipped folder of the SDCC plugin (net.sourceforge.eclipsesdcc-1.0.0-macosx.carbon.ppc) to the folder dropins
- maybe you have to restart Eclipse
- Check if the plugin was installed
- Eclipse → About Eclipse → Installation Details → Installed Software → scroll down list and look for „SDCC Compiler Plug-in„
8. Connect the STM8 to the Mac
- supply the STM8L-DISCOVERY board via USB with power and connect it with the USB to Serial adapter cable to the Mac
- see top description for details
9. Setup Terminal
- Depending on what USB-Serial adapter is used a suitable driver should be installed. To use the Prolific adapter install the driver Prolific-Serial/PL2303_MacOSX_1_6_1. The installation requires a restart of the whole system.
- In Eclipse it is possible to use the Serial port over the integrated terminal: Window → Show View → Terminal
- Open the connection in the terminal window over the icon Launch Terminal
- Terminal type → Serial Terminal
- Serial Port → /dev/cu.usbserial
- The STM8L-DISCOVERY board has to be connected with the USB-adapter to the system and need to be up and running! Only then the Serial device is shown in the drop down list.
- Baud rate → 38400
10. Load Projekt in Eclipse
- create a STM8 example project or load one
11. Test it!
- Open the terminal window in Eclipse
- Run → Run… or button with Run-icon
- you can ignore the error
Program "sdcc" not found in PATH
- you can ignore the error
- the terminal window shows the respond of the program running on the STM8
- you can ignore the unreadable sign in front of the message
- you should now see the programs output
alive :)in the terminal window