Compiler Comparison
RTOS Availability
STM8AF LED Timer
STM8AF Serial
STM8AF Benchmarks
STM8AL LED Timer
STM8AL Serial
This short tutorial shows how to compile the Whetstone benchmark and execute it on an sduino UNO board. The STM8S105K6 on the sduino UNO has only 2 KB of RAM. So other popular benchmarks like Dhrystone (needs about 5 KB of RAM), Coremark (needs about 2.5 KB of RAM) and stdcbench (needs about 3.5 KB of RAM) are not an option. The author used a Debian GNU/Linux system, but the tutorial should work for other Linux distributions, *BSD or other Unices.
The tools we use are
The sduino UNO is connected to power and for serial I/O via a USB cable. To write our program to the board, an ST-Link v2 is attached (RESET to RESET on the 8-pin power header, SWIM to pin 7 on the digital I/O header). On the USB end of the serial interface is connected to a computer running a terminal program configured for 9600 baud, no parity, 8 bits, 1 stop bit and no flow control. We used gtkterm.
Depending on your operating system there might be an easy way to install SDCC 3.5.0 or newer using a package system or similar (e.g. apt-get install sdcc on Debian). While SDCC 3.4.0 should be sufficient for this tutorial, you might want to try a newer version in case you encounter any bugs. In particular, SDCC 3.4.0 has an issue with the library search path; this can be worked around by explicitly specifying the path to the standard library when linking.
SDCC binaries or a source tarball can be downloaded from its website.
The stm8flash source can be found at its GitHub location, where there is also a download link for a zip archive of the sources. To compile it, a C compiler, such as gcc, pkg-config and libusb need to be installed. Unzip the archive (e.g. using unzip stm8flash-master.zip) change into the directory stm8flash-master and type make
. In case there are any errors, such as header files not found, check that pkg-config and development files for libusb are installed.
Download a version of Whetstone adapted for use with SDCC and the sduino UNO board.
Download, and unpack it using tar -xzf whetstone-stm8s105k6-uart2-sdcc-3.8.0.tar.gz
, change into the directory whetstone-stm8s105k6-uart2-sdcc-3.8.0.
You can then compile Whetstone by typing make
. In the end there should be a file whetstone.ihx. Like all other current compilers targeting the STM8, sdcc 3.8.0 does not support double
. It replaces double
by float
and emits a warning to the user. Thus the scores from Whetstone obtained using sdcc 3.8.0 are not really comparable to those from other platforms.
A bit of custom code was necessary to make Whetstone run on the sduino UNO. See the file portme.c
for details. It basically combines clock()
from the timer demo and putchar()
from the serial demo.
Assuming stm8flash and serial.ihx are in the same directory, the board is attached through the integrated stlinkv21 device, ./stm8flash -c stlinkv21 -p stm8l152r8 -w stdcbench.ihx
will write stdcbench onto the board. stdcbench will run and report its results via USART1. You can see them using a terminal program configured for 9600 baud, no parity, 8 bits, 1 stop bit and no flow control. They should look like this (the benchmark numbers may vary depending on the SDCC version used to compile stdcbench):
Assuming stm8flash and whetstone.ihx are in the same directory, the board is attached through an stlinkv2 device, ./stm8flash -c stlinkv2 -p stm8s105k6 -w whetstone.ihx
will write Whetstone onto the board. Whetstone will run and report its results via the UART. You can see them using a terminal program configured for 9600 baud, no parity, 8 bits, 1 stop bit and no flow control. Whetstone runs the full benchmark before doing any text output, so don't worry when it takes some time until something appears on the terminal. The output should look like this (the benchmark numbers may vary depending on the SDCC version used to compile Dhrystone):
Loops: 10, Iterations: 1, Duration: 8830 msec. C Converted Double Precision Whetstones: <NO FLOAT> KIPS
Since printf()
from sdcc 3.8.0 does not have float support by default, you have to calculate the KIPS score from the data in the first row by hand: Multiply Loops by 100, divide by the duration in seconds. In this case we get a score of 113.2502 KIPS.
stm8flash was written by Valentin Dudouyt. It works both with stlink (including the one integrated on the discovery boards) and stlinkv2 devices. The programmer can be selected using -c stlink
or -c stlinkv2
. The target device is selected using the -p
option (to get a list of target devices, use the -p
option with an option argument that is not an stm8 device, e.g. -p help
. stm8flash will treat filenames ending in .ihx
or .hex
as Intel hex, and other filenames as binaries.
SDCC was initially written by Sandeep Dutta for the MCS-51, and has a relatively conservative architecture (see Sandeep Dutta, "Anatomy of a Compiler", 2000). It has been extended by various contributors and more recently, incorporated some cutting-edge technologies, in particular in register allocation (see Philipp Klaus Krause, "Optimal Register Allocation in Polynomial Time", 2013). The stm8 backend was mostly written by Philipp Klaus Krause for his research into bytewise register allocation and spilling (see Philipp Klaus Krause, "Bytewise Register Allocation", 2015).
SDCC is a C compiler that aims to be compliant with the C standards.
Important compiler options for STM8 developers include:
-c
to compile into object files to be linked later--std-c99
for compilation in C99 mode (some C99 features, e.g. variable-length arrays are not yet supported in sdcc though)--opt-code-size
for optimization for code size--max-allocs-per-node
to select the optimization level. the default value is 3000. Higher values result in more optimized code, longer compiler runtime, and higher memory usage during compilation.