Program STM8S Development Board with ST-Link v2

I successfully programmed development board having STM8S103F3P6. It is quite simple to make it blink LED. For me, it was second easiest after Arduino Uno to get started. I used SDCC as the C compiler, ST-Link v2 clone as programmer, and stm8flash to flash the binary file through ST-Link.

STM8S103F3P6 minimal development board
STM8S103F3P6 minimal development board

Required Software

As I already mentioned, just two software are required to program STM8 microcontrollers in Linux machines, they are SDCC and stm8flash.


SDCC (Small Device C Compiler) is an open source C compiler supporting many microcontrollers including STM8 series. We can get binary distribution from their website At the time of this writing, it is 3.6.0 version I used.


It is a utility program helping to transfer compiled binary file to STM8 microcontroller’s flash memory through ST-Link V1 or V2. It is hosted at GitHub repository

Required Hardware

  1. (Obviously) STM8 Development Board (The one I used is having STM8S103F3P6. I assume it will work with any STM8)
  2. ST-Link V1 or V2 (I used cheap Chinese clone of ST-Link V2)
ST-Link V2 for programming STM8 and STM32 microcontrollers
ST-Link V2 for programming STM8 and STM32 microcontrollers

The development board is having a built in LED connected to PB5 pin. So, I did not use any external LEDs here. Thanks to Sduino team for the schematic at, which helped me to identify what pin the test LED is connected to. It was difficult for me to identify it myself.

As per the schematic, test LED is active low, which means it will be ON when pin is LOW.


#define PB_ODR		*(unsigned char*)0x5005
#define PB_DDR		*(unsigned char*)0x5007
#define PB_CR1		*(unsigned char*)0x5008

// Unsigned int is 16 bit in STM8.
// So, maximum possible value is 65536.
unsigned long int dl; // Delay

int main() {
	PB_ODR = 0x00;	// Turn all pins of port D to low
	PB_DDR |= 1 << 5; // 0x00100000 PB5 is now output
	PB_CR1 |= 1 << 5; // 0x00100000 PB5 is now pushpull

	while(1) {
		PB_ODR ^= 1 << 5; // Toggle PB5 output

		for (dl = 0; dl < 18000; dl++) {}

It is a modified version of the program I received from YouTube video

This program does not depend on any other library and can be compiled directly.


Run following command to compile above program using SDCC, assuming file is named as blink.c.

sdcc blink.c -lstm8 -mstm8 --out-fmt-ihx -oBLINK.ihx

If successful, above command will output nothing!


Connect ST Link V2 with STM8 board as following:

ST-LinkSTM8 board
3.3V → 3V3

Connect ST-Link V2 in USB port of the computer and run given command to flash the program.

stm8flash -c stlinkv2 -p stm8s103f3 -w BLINK.ihx

Please change the microcontroller name in above command as needed.

Hope it helps!

4 responses to “Program STM8S Development Board with ST-Link v2”

  1. I use Eclipse & sdcc .
    void timer1_CAP_isr (void) __interrupt (12) {
    I have the following error.
    Unused declaration of function ‘timer1_CAP_isr’
    But the interruption doesn’t work

Leave a Reply

Your email address will not be published. Required fields are marked *