STM8 toolchain with GDB debugger and SDCC for cygwin

This is the open source STM8 development toolchain effort with gnu tools binutils, gdb, gas, objdump etc. STM8 is a 8-bit microcontroller platform from STMicroelectronics. Everything is based on the latest versions of the sources.

From version 2018-03-04 sdcc and openocd for stm8 does no longer have to be patched. Sdcc has built in support for gdb (dwarf2 debug format) and openocd support debugging of stm8 micros.

gdb 8.1
binuils 2.30

Contributions are welcome, testing the tools is of course the main issue. If you have suggestions, bug reports or wishes post a comment to the stm8-binutils-gdb discussion forum.

DOWNLOAD SOURCES

The actual sources for gdb and binutils are in the gnu project repositories. The stm8-binutils-gdb project is just containing a collection of patches applied to the official source code from the gnu project.

The stm8-binutils-gdb patches and build scripts are available from SourceForge.

DOWNLOAD BINARIES

Binaries for 32 bit cygwin are no longer supplied. It is how ever still possible to compile the sources for cygwin32.

Precompiled binaries of sdcc, openocd and binutils for cygwin64 can be installed by running the setup-x86_64.exe :

setup-x86_64.exe -X -s https://sourceforge.net/projects/stm8-binutils-gdb/files/cygwin/

Cygwin setup is much less than optimal for doing these types of installations so make sure you select the packages you want to update or install.

These packages are available:
openocd
sdcc
stm8-binutils-gdb

Make sure to select another mirror in addition to sourceforge.net to supply other required packages.

GDB

A new stm8 target was added to gdb. In addition two new remote settings were added to facilitate debugging with IDE's like eclipse. These settings will make gdb behave like if it is debugging native code removing the necessity to use remote, load and continue commands.

set remote run-connect on (default is on)

The run-connect setting makes gdb automatically connect to localhost port 3333 (openocd server port) when run command is entered.

set remote run-load on (default is on)

The run-load setting makes gdb automatically load the program when run command is entered.

BINUTILS

The regular tools like ld, objcopy, readelf, objdump etc.

GAS

A new stm8 assembler (as).

OPENOCD

A new target for stm8 in addition to updated and fixed SWIM support. Although stm8 debugging support is not yet released for OpenOCD it is available from the git source tree.

A few target configuration scripts are available in the target folder:

stm8s.cfg – generic stm8s
stm8l.cfg – generic stm8l
stm8l152.cfg
stm8s003.cfg
stm8s105.cfg

SDCC

The latest version of SDCC is 3.7.0 and support debugging with dwarf2 format. SDCC is available from sdcc.sourceforge.net

BUILDING BINARIES

Building the binaries is basically the process of downloading the sources and applying the patches. There are helper scripts to assist with the process.

Also note you need some libraries for TUI mode to work. Among those are ncursesw.

First set your installation directory if you want it in a specific location. Otherwise skip this step to keep the default (/usr/local).

export PREFIX=<path>

To download, patch and configure:

./patch_binutils.sh
./configure_binutils.sh

Next step is the regular building and install:

cd binutils-2.30
make
make install
cd ..

USAGE EXAMPLES

Compiling with sdcc and debug info:

sdcc -mstm8 led.c --out-fmt-elf --all-callee-saves --debug --verbose --stack-auto --fverbose-asm  --float-reent --no-peep

launch openocd in a second shell:

openocd.exe -f interface/stlink.cfg -f target/stm8s105.cfg -c "init" -c "reset halt"

 

or if you prefer the generic stm8s configuration (for medium size flash stm8s)

openocd.exe -f interface/stlink.cfg -f target/stm8s.cfg -c "init" -c "reset halt"

Currently config files for stm8s003, stm8s105 and stm8l152 are available.

Then start gdb:

stm8-gdb test.elf --tui
start

or if you prefer to load manually:

stm8-gdb test.elf --tui
target extended-remote localhost:3333
load
break main
continue

USING ECLIPSE CDT AS GDB FRONTEND

Using eclipse cdt as gdb front end is now much more straight forward with the modifications of the way gdb ‘run’ command works. What is happening when ‘start’ or ‘run’ command is entered is gdb automatically connects to openocd server on localhost:3333. This is similar to entering the commands ‘target ext localhost:3333’ and ‘load’ then ‘continue’ which is familiar to you who are used to debug with ‘Insight gdb’ or gdb with TUI (which is not that bad actually).

To create a ’debug’ project in eclipse, open ‘File’ menu and click ‘Import’. Click ‘C/C++ Executable’.
Click ‘Next’

 

In the Import Executable dialog browse to your elf file you wish to debug.
Click ‘Next’.

 

Now a project will be created. Use the defult settings or change project name.
Click Finish.

 

Now the ’Debug Configurations’ dialog is automatically shown.
Click the ‘Debugger’ tab.

 

Browse to where the stm8-gdb.exe binary is located.
Next select ‘Source’ tab.

 

To use eclipse in windows with cygwin as ‘operating system’ for gdb some configuration of eclipse is necessary. This step is specific when using cygwin and can be skipped if you use eclipse with Linux.

We have to map the path relations between cygwin and windows.  Basically what happens is when gdb sees a reference to ‘/cygdrive/c/temp/test’ it will be converted into a windows path ‘c:/temp/test1’.

Under the tab ‘Source’ click Add and then ‘Path Mapping’

 

In the Path Mappings dialog enter the cygwin path and the windows path.
Click OK.

 

Now it should look like this:
Click Apply then Debug

 

The program should load and break on the first line in main():