There’s not a great number of useful examples for the stm8s chips that use sdcc. This repository aims to fix this. The examples are currently targeting the STM8S103F3P6 and were tested with the according dev board that is available online for <1$.
- Peripherals Datasheet (has all the details on common peripherals, such as timers, UART, SPI etc)
- STM8S103F3P6 Datasheet (MCU-specific details)
- You’ll need a programmer, e.g. stlink-v2 or the esp8266-based esp-stlink
- Get stm8flash.
$ make
$ stm8flash -c stlinkv2 -p stm8s103f3 -w led.ihx
led.c
sets up a timer and uses the onboard LED to blink in defined intervals.
serial.c
demos using the UART to transmit serial data.
serial_interrupt.c
sets up an interrupt handler to perform serial transmission without busy wait.gpio_interrupt.c
wakes up from halt mode via external gpio interrupt on B4.
sound.c
uses a timer and an interrupt to create 8-bit PWM output on a pin.
You can directly attach a speaker and will hear a low-volume tone:
For better sound-quality add a 2.2μF capacitor to GND as a low-pass filter: