This is the open source STM8 development toolchain effort with binutils, gdb, gas, openocd and sdcc. STM8 is a 8-bit microcontroller platform from STMicroelectronics. Everything is based on the latest versions of the sources.
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.
Precompiled binaries for cygwin can be found here:
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.
The regular tools like ld, objcopy, readelf, objdump etc.
A new stm8 assembler (as).
A new target for stm8 in addition to updated and fixed SWIM support. Hopefully this will be merged upstream.
SDCC already had a back end for stm8. Unfortunately not so much debugging info although most of the debugging code was already available. However it is still lacking dwarf CFI (call frame info) so sdcc hade to be patched to use a frame pointer to assist gdb unwinding the stack. The soft frame pointer register is enabled with the --debug and --out-fmt-elf option. The sdlk linker was updated to supply proper entry point address in the ELF header.
The startup code now also includes initialization of the stackpointer.
Building the binaries is basically the process of downloading the sources and applying the patches. There are helper scripts to assist with the process. In addition there are also config scripts for sdcc, openocd and binutils-gdb. If you want explicit configuration options edit these config scripts.
First set your installation directory if you want it in a specific location. Otherwise skip this step to keep the default(s).
To download, patch and configure:
Until stm8 openocd official binaries are available:
Next step is the regular building and install:
The (separately) supplied binaries are for cygwin-32. The binaries require a number of dynamic libraries (dll’s) not available in the supplied archives. Until a setup script for obtaining these libraries automatically is available they have to be installed with cygwin setup program. A good way to figure out what packages to download is to use cygwin package search.
The required libraries are:
cygexpat-1.dll => /usr/bin/cygexpat-1.dll (0x58c80000)
cygftdi1-2.dll => /usr/bin/cygftdi1-2.dll (0x67e00000)
cyggcc_s-1.dll => /usr/bin/cyggcc_s-1.dll (0x5bca0000)
cygiconv-2.dll => /usr/bin/cygiconv-2.dll (0x4b790000)
cygintl-8.dll => /usr/bin/cygintl-8.dll (0x43ca0000)
cyglzma-5.dll => /usr/bin/cyglzma-5.dll (0x3f200000)
cygncursesw-10.dll => /usr/bin/cygncursesw-10.dll (0x42200000)
cygstdc++-6.dll => /usr/bin/cygstdc++-6.dll (0x3aa10000)
cygusb0.dll => /usr/bin/cygusb0.dll (0x39950000)
cygz.dll => /usr/bin/cygz.dll (0x36f50000)
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-v1.cfg -f target/stm8.cfg -c "init" -c "reset halt"
or if you will be using stlink-v2:
openocd.exe -f interface/stlink-v2.cfg -f target/stm8.cfg
Then start gdb:
or if you prefer to load manually:
target extended-remote localhost:3333
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++
Import Executable dialog browse to your elf file you wish to debug.
project will be created. Use the defult settings or
change project name.
’Debug Configurations’ dialog is automatically shown.
Click the ‘Debugger’ tab.
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
should look like this:
Click Apply then Debug
The program should load and break on the first line in main():