ESP-14 experiments – Stage 1: Overview and STM8S

Hardware overview

The ESP-14 is kind of like a multi-core ESP8266, combining an ESP8266 mcu with a STM8S003F3 mcu (内部图 means internal diagram):tb2nrdeefxxxxbmxpxxxxxxxxxx_882680026The purpose of this combination is to provide more I/O pins than a regular ESP8266 based board such as ESP-12x, acting as an I/O extender.
The STM8S003F3 mcu is 20-pin packaged low-cost 8bit mcu running at 16MHz, with 8kb flash memory and 1kb RAM.
It sports 16 GPIOs, of which 5 multiplexed 10-bit ADC channels, and UART Tx (PD5) and Rx (PD6). Well, unfortunately, the UART ports are also two of the ADC ports, so this will restrict to 3 available ADCs, 2UART and 11 digital IOs (configurable as I2C or SPI bus too).
The ESP-14 board’s 22 pins breaks out all of STM8’s pins, plus the ESP8266 VCC and  GPIO0 pins, to control flashing of the ESP.

As found out by Benjamin De Jong, and Mark the STM8’s PD5 and PD6 pins are connected to the ESP8266’s Rx and Tx pins. It is not clear if other pins are connected internally too or not.

Software setup

ESP8266 flashing and programming

Once you know that Rx/Tx of the ESP are pins M_PD5/M_PD6, and GPIO0 is available to set the Flash mode, programming the ESP8266 part of ESP-14 will be  business as usual, using your regular USB/TTL for flashing.
If you are used to Node-MCU’s DTR/CTS-driven automatic reset and flash mode setting, you will need to go back to the good old method of resetting the ESP while pulling down GPIO0.
Here resetting will mean removing power from E_VCC (pin 14) and then putting it back. A bit of a hack…

STM8 flashing and programming

Not so for the STM8, at least not for us ESPers…
Here we enter the world of low-end STMicro MCUs that are flashed and debugged through the Single Wire Interface Module (SWIM) protocol.
20160113_231318.jpgFor this you will need a ST-Link V2 USB dongle, which is required to talk to the STM8 programming (flashing) and in-chip debug interfaces.
SWIM actually uses 4 wires, GND, VCC, RESET and SWIM. See SWIM protocol details. I got myself a cheap dongle on AliExpress and it works great:

It shows in the window peripherals as STM32 STLink



STM8 Tools and information

Reference hardare information can be found on STMicro’s web site.
More specifically, the datasheet for STM8S003F3, and STM8S103F3. Those two chips are essentially the same, but the 103F3 is available in cheap (<$1) boards that I will use for experimenting STM8 programming.

STMicro’s site provides free tools to handle STM8:

  • STVD: ST Visual develop IDE for developing ST7 and STM8 applications.
    This will among other things give the C header files for the STM8Sx03F3 with pin definitions.
    You get a with an installer EXE inside that will install both STVD and STVP (flasher tools).
    You may want to install the USB drivers when prompted. Otherwise they can be installed later with st_toolset\stlink>stlink_winusb_install.bat.

    Use st_toolset\stlink>ST-LinkUpgrade.exe to verify that the STLink can be connected to and upgrade the firmware if need be.
  • STSW-LINK009: ST-Link, ST-Link/V2, ST-Link/V2-1 USB driver signed for XP, Windows7, Windows8 (also included in STVD)
  • STM-Studio: STM Studio run-time variables monitoring and visualization tool for STM8 and STM32 microcontrollers.

The web site has plenty of information on STM8 and STM32 mcus:

STM8 Toolchain/compilers:

There are several ways to get a free compiler to build STM8 code binaries:

I finally elected to use IAR because it is available and has eclipse integration, although most tutorials and the STVD env uses Cosmic (or Raisonnance which does not have free licences). But I could not get the Cosmic download, web site is stuck somehow…

There is no Arduino ‘boards.txt’ support for STM8, and contrarily to STM32 it is not supported by either, so we’re pretty much bare here.

First Blink program

As I mentionned, I used a cheap STM8S103F3P6 (8k) board, available for $1, for testing.

After installing all software, upgrading the STLink dongle firmware to the latest using SVDP, I connected the 4 SWIM pins of the STM8 board to the STLink dongle:20160113_231630.jpg

The STM8 I had was initially flashing its red Test LED, but after I connected STVP to it it stopped, presumably I had reset the flash…

To verify the SWIM is working, start the STVP UI, Select STLink/SWIM/STM8S003F3. Then try to Read/current Tab the memory. You may get an error stating that ROP is ON, but at least this validates the connectivity to the STM8 chip.

IAR setup:

Need to setup, from Options context menu in workspace:

  • include files to point to st_toolset\include (C/C++ compiler/Preprocessor/additional includes)
  • debugger to use SWIM: Driver set to STLink rather than Simulation
  • compiler, disable optimization otherwise empty ‘wait’ loops will be removed!
First blinky code

Create a new C project, replace main code with this one:

#define __CSMC__
#include "STM8S003F3.h"
int main() {
        int d;
        // Configure pins
        PB_DDR = 0x20;
        PB_CR1 = 0x20;
        // Loop
        do {
                PB_ODR ^= 0x20;
                for(d = 0; d < 29000; d++) { }
        } while(1);

(taken from

Run make, then Download and Debug

=> the test LED blinks!

Now, one thing that’s becoming obvious is that the programming model is closer to the metal on STM8 than when you have a neat and cosy Arduino board definition for it… No digitalRead(pin) here, just plain low-level memory-mapped I/O instead.

Using STM8S Libraries

STMicro provides a set of libraries at STSW-STM8069 STM8S/A Standard peripheral library, with higher-level macros to drive the various interfaces.

Now, while writing this, I realized that using the STM8 as a I/O slave, I would have to find ‘drivers’ coded for the STM8 for the various peripherals we commonly use, e.g DS18B20, WS2812, DHT11, HX711, …

What’s Next

To be continued… Next instalments will deal with making use of ESP14’s STM8S, now that I know how to deal with that little fella, and having ESP8266 and STM8 talk to each others…

See ESP-14 experiments – Stage 2: Breadboarding


8 thoughts on “ESP-14 experiments – Stage 1: Overview and STM8S

  1. mager

    Pairing the esp with a smaller, slower, less capable MCU that is sifficult to programm does not make sense to me, one could add more IO eith an I2C port extender

    1. Greg Ware Post author

      I fully agree, the author of also conjectures on that, and has interesting explanation.
      Practically, ESP-14 is about adding wifi to existing STM-8 setups rather than extending ESP, but both approaches are valid depending on where you’re coming from.
      It would be nice to elaborate on the esp-link ( project and add ESP-14/STM8 specific code to drive the ADCs of the STM8 more or less transparently (not for real-time bit-banging, but reading analog values from sensors would be doable)
      Adding OTA to the ESP once for all would also simplify coding.

  2. Eduardo de Mier

    Hi Greg.
    Very nice Post. I am starting the design for a data logger with WIFI. The STM8 could do the logging & wakeup management. My question is: How much energy is spent every time the ESP8266 is woken and searches for a WLAN? 99.99% of the time it would not find the right WLAN (by name) and go back to sleep. If this happens once every minute, how much current is consumed on the average?
    Best regards.
    Eduardo de Mier

  3. Gerhard

    Thanks for sharing this Greg, did you find ‘drivers’ for the STM8 – I am very interested in using DS18B20 Sensors with the ESP-14

  4. Benjamin

    I find your tutorials useful but i’ve found nodeMCU and i was wondering if i can use it with this ESP14 with this programmer instead an ftdi.Do you Know something?

    1. Greg Ware Post author

      Late answer, sorry, NodeMCU is a open hardware ESP8266 based board, which also comes with a LUA firmware.
      So, yes, you can flash LUA on ESP-14, but then it will not help much to handle the STM8 which drives the exposed pins.

  5. Pingback: ESP8266 Resource »

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s