A first look at the STM8

If you, like me, are in the habit of browsing eBay for cheap electronic bits and pieces, you may have stumbled upon this ridicuously cheap STM8 board (eBay, AliExpress). How does it compare with Arduino?

In this post, I’ll present my initial findings about the mysterious microcontroller and the board it comes on. If you’re so inclined, the chips can be purchased separately as well.

a photo of the stm8 board

What is the STM8

First a TL;DR for the impatient: It’s an inexpensive, low-specced 8-bit microcontroller manufactured by ST, which could replace the Arduino/ATMEGA in simple applications.

How it came about

The dawn of the 8-bit

8-bit microcontrollers have been around for a very long time, slowly fading in popularity as more powerful devices pushed them out of the spotlight. However, they never really went away.

The notorious 8051, for example, is still very much alive and kicking, partly because its copyright expired and it’s now fair play to clone it and build into whatever design the manufacturers please.

Hacker boom

Other families appeared over the years, but the real boom of the 8-bit came with Arduino and the whole “DIY hacking” phenomenon. You’re no doubt familiar with Atmel’s AVR line or Microchip’s PIC. AVRs, popularised by the Arduino project, and PIC’s, because of their low cost and Microchip’s eagerness to provide free samples, have dominated the hobbyist market, and kits and accessories for them have became a serious business (look at all those “Arduino modules” on eBay!).

It comes as no surprise that other chip manufacturers wanted their slice of the cake. One of those efforts apparently crystalised in ST Microelectronics’ STM8 line. You may know the company as a generic semiconductor manufacturer, and they’re also behind the popular STM32 line of Cortex-M microcontrollers (also cheaply available on eBay). STM8 haven’t really gone mainstream, but for whatever reason, they’s now cheap and widely available. Some variants of STM8 are used in automotive applications, but not the STM8S family we’ll focus on.


Features comparison

Arduino and it’s clones are predominantly built on AVR’s, commonly the ATMEGA328P. It runs at 16 MHz and has 32kB of FLASH, 2 kB of RAM and some EEPROM. There’s also the obligatory mix of peripherals, like timers, UARTS, SPI and I2C.

The STM8 chip we’ll look at, STM8S103F3, has a similar set of peripherals, but a substantially smaller memory space (8 kB FLASH, 1 kB RAM). It may not be able to replace the ATMEGA everywhere, but at the low cost, it well might in many places, and it makes it viable to literally embed it in places you wouldn’t even think of with more expensive devices. A “SPI to Neopixel” interface for 60 cents? No problem!

Advantages in architecture

The ATMEGA has one unpleasant flaw in it’s architecture: the Harvard memory design. FLASH and RAM share the same address space in an overlapping manner, maybe to save some address bits, so the same address can be in either of them. This is where your bothersome pgm_read_byte() and friends come from–it needs a special assembly instruction LPM to read data from FLASH. Not even the high level abstraction of avr-gcc will shield you from this problem. You’ll face a similar problem with the EEPROM, but that could be excused as you won’t it so often.

The STM8, possibly inspired by the STM32, appear as von Neumann, in that both memories are mapped to one linear address space with no overlap. Internally there are two buses, but it’s handled transparently. As a result, you can seamlessly store your constants in the program memory and even run code from RAM. This advantage may not be a gamechanger, but it’s helpful for debugging purposes (if you use the proprietary Windows IDE).

A look at the development board

The board I ordered and 20-something days later also received is marketed as “Minimum System Development Board for STM8S” and is fitted with STM8S103F3P6. Here’s a diagram stolen from one eBay listing, showing the main features:

photo from the listing

It’s indeed quite minimal, you can think of it as the Arduino Pro Mini’s little brother. Don’t let the USB connector fool you, there’s no USB capability here, not even FTDI; it’s just for power. There’s the tantalizing VUSB possibility, but the board lacks a crystal position for the necessary 12~MHz, and the DP/DM pins are hard to access. That’s not to say it’s not worth a try!

Here’s an actual photo of the board, top and bottom side:

pic front back

Powering the board

On the backside you can see a LT1117-3.3 in SOT223, which converts the input voltage from the RAW pins (the left corners) to 3.3 V. The board can also be powered via the USB connector, but the data lines are sadly not connected anywhere.

Both the input voltage and the regulated 3.3 V can be used for external circuits, they’re available on the bottom header. Confusingly, the “5V” pin is directly connected to the input, there’s no 5 V regulator. With USB connected, you’ll of course get something quite close to 5 V.

There are two more ways to power the board, namely the pins in the bottom row, and the “3V3” pin in the programming header. It appears you can simply connect an external 3.3 V source to either of the “3V3” pins and it’ll work. I was worried the LDO might not like that, but it works just fine.

This means you can power it straight from the programmer, but be super careful with larger loads: There’s a really tiny regulator in the ST-Link dongle (pics below). Easy to fry.

Blinky lights!

The board has 2 LEDs, one (blue) is always on, and the other (red) can be used for your blinking. On the specimen I received, the red LED is connected to pin B5. Out of the box, the micro is loaded with a simple blinking firmware, so you can try if it’s alive by just connecting it to USB.

Programming equipment

To successfully flash the STM8, you’ll need (besides the STM8) an ST-Link programmer capable of SWIM (the debugging protocol the STM8 uses). Those can be purchased on eBay or AliExpress for a few dollars, so don’t forget to get one while shopping for the board. They’re cheap, so it might be wise to get two, in case you kill it. I managed to do that and don’t even know how.

The programmer supports STM8 as well as STM32, so if you find the STM8 too limiting and decide to try 32-bit, you’ll be ready. You can also use it as a simple USB powered power supply, but be careful about the current draw on the 3V3 line - check the tiny LDO on the thing:

A fun note: The programmer is available only because some clever hackers managed to steal the ST-Link blob from a firmware update. The dongles are essentially clones of the break-away part of Nucleo boards.