Open8S208Q80

EX-STM8-Q48a-105

STM8/128-EVAL

STM8L101-EVAL

Getting started with STM8 development using free software: Dhrystone and Whetstone on the STEVAL-ISA164V1

This short tutorial shows how to compile the Dhrystone and Whetstone benchmarks and execute them on an STMicroelectronics STEVAL-ISA164V1 board.
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 Small Device C Compiler (SDCC), version 3.6.0 or later to compile C programs for the STM8.

stm8flash, to write programs onto devices.

Hardware setup

The STEVAL-ISA164V1 is connected to power and for the serial interface via the mini-USB port (we use the integrated USB-to-serial converter of the STEVAL-ISA164V1 board). To write our program to the board, an ST-LINK/V2 is attached to the SWIM port. The host computer is running a terminal program configured for 9600 baud, no parity, 8 bits, 1 stop bit and no flow control. We used gtkterm.

Get SDCC

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.

Get stm8flash

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.

A bit of custom code was necessary to make Dhrystone run using SDCC on the STEVAL-ISA164V1. See the files dhry.h and portme.c for details. The file portme.c basically combines clock() from the timer demo and putchar() from the serial demo.

Put Dhrystone onto the board

Assuming stm8flash and dhrystone.ihx are in the same directory, the board is attached through an stlinkv2 device, ./stm8flash -c stlinkv2 -p stnrg388a -w dhrystone.ihx will write Dhrystone onto the board. Dhrystone 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. They should look like this (the benchmark numbers may vary depending on the SDCC version used to compile Dhrystone):

Whetstone

Download a version of Whetstone adapted for use with SDCC and the STEVAL-ISA164V1 board, and proceed as with Dhrystone above. SDCC 3.6.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.6.0 are not really comparable to those from other platforms. Unlike Dhrystone, Whetstone runs the benchmark before doing any text output, so don't worry when it takes some time until output appears on the terminal.

Since printf() 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 63.3633 KIPS.

More about stm8flash

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.

More about SDCC

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).