STM8 8 Bit Microcontroller Tutorial

Getting Started with STM8 Microcontrollers Using Arduino IDE

STM8 Microcontroller Tutorial – Getting Started with STM8S103F3 + Arduino IDE

Learn how to program the STM8S103F3 8-bit microcontroller using Arduino IDE: wiring, setup, blink example, code explanation, debugging tips & project ideas.

πŸ“˜ Introduction

Why STM8?

The STM8 family are low-cost, low-power 8-bit microcontrollers from STMicroelectronics. They’re a great choice for simple embedded projects where you don’t need the power of a 32-bit MCU (STM32), but still want reliable peripherals (timers, ADC, UART). For hobbyists and learners, the STM8S103F3 board provides an inexpensive platform and can be programmed using Arduino-style workflows.

STMicroelectronics' STM8 family of 8-bit microcontrollers offers a perfect balance between cost, performance, and reliability. These MCUs are designed for general-purpose, low-power, and automotive-grade applications, making them suitable for both hobbyists and professional engineers.

The STM8 series supports development in C and C++, and thanks to open-source tools, you can now program it directly from the Arduino IDE — making embedded development easier and more accessible than ever.

⚙️ Overview of the STM8 Family

The STM8 architecture is based on a high-performance 8-bit Harvard core with enhanced stack pointer operations, advanced addressing modes, and new instructions for fast and safe development.

Series Description Typical Application
STM8S Mainstream MCUs Consumer electronics, industrial controllers
STM8L Ultra-Low-Power MCUs Battery-operated and energy-saving devices
STM8AF Automotive MCUs Car body control, lighting, in-vehicle systems
STM8AL Automotive Low-Power MCUs Hybrid automotive and low-power modules

πŸ”© Required Components

To follow this tutorial, you'll need a few essential components:

Component Description
STM8S103F Development Board Main MCU development board
ST-Link V2 Programmer Used to upload and debug your program
Breadboard For prototyping connections (optional)
Jumper Wires For connecting the ST-Link to the STM8 board

Picture for STM8F103 Breackout Board

MR60BHA1 mmWave Sensor

STM8F103 Breackout Board Pinout

MR60BHA1 mmWave Sensor

🧩 Hardware Setup

πŸ”Œ Connecting the ST-Link V2 to the STM8S103F Board

The ST-Link V2 programmer communicates with the STM8 board through the SWIM interface (Single Wire Interface Module). Below is the pin connection table.

ST-Link Pin STM8 Pin Function
3.3V 3.3V Power supply
SWIM SWIM Data/programming line
GND GND Ground reference
RST NRST Reset signal
ST-Link V2 Pinout
Figure 1: ST-Link V2 Programmer Pinout showing connection points
Note: Since the on-board LED is already connected to PB5, no external LED is required for this blink example.

πŸ’» Setting Up the Arduino IDE for STM8

Traditionally, STM8 microcontrollers were programmed using STVD or Cosmic C Compiler, but now with the sduino project, you can use the Arduino IDE — a simpler and beginner-friendly environment.

1Install Arduino IDE

Download the latest version of the Arduino IDE from the official website:

πŸ‘‰ https://www.arduino.cc/en/software

Install it according to your operating system.

2Add STM8 Board Support

  1. Open Arduino IDE.
  2. Go to File → Preferences.
  3. In the field "Additional Boards Manager URLs", paste this link:
https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_index.json
  1. Click OK.

3Install "sduino" Package

  1. Go to Tools → Board → Boards Manager.
  2. Search for sduino.
  3. Click Install and wait until the installation completes.

4Select Your STM8 Board

Once installation is complete:

  • Restart the Arduino IDE.
  • Go to Tools → Board → STM8S103F3 (or select your board version).

✅ Your IDE is now ready to program the STM8 development board! πŸŽ‰

🧠 Arduino Pin Mapping for STM8S103F3

Each STM8 pin has a corresponding Arduino-style digital pin number. For example, the on-board LED is connected to PB5, which maps to Arduino pin 3.

So, when you write:

digitalWrite(3, HIGH);

You're actually toggling the PB5 pin high, turning the LED ON.

πŸ’‘Writing and Uploading Your First Program

Let's upload the classic Blink example to verify that everything works correctly.

🧾 Code Example – LED Blink

void setup() {
  // initialize digital pin LED_BUILTIN as an output
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on
  delay(1000);                       // wait for 1 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off
  delay(1000);                       // wait for 1 second
}

πŸ” Code Explanation

Function Description
pinMode(LED_BUILTIN, OUTPUT) Configures the LED pin as output
digitalWrite(pin, HIGH/LOW) Sets the pin to high (LED ON) or low (LED OFF)
delay(1000) Waits for 1000 milliseconds (1 second) before next toggle

This simple loop makes the onboard LED blink continuously — a classic first project to confirm the board and IDE setup.

πŸš€ Uploading the Program

  1. Connect the ST-Link V2 to your STM8S103F board.
  2. Plug the programmer into your computer's USB port.
  3. In Arduino IDE, select the correct COM Port under Tools → Port.
  4. Click Upload.

The upload process will compile the code and flash it to your STM8 board.

If successful, you'll see:
✅ "Done Uploading"
and your LED will begin to blink!

Troubleshooting Tips

  • Ensure correct SWIM and NRST pin connections.
  • Install the latest ST-Link drivers from STMicroelectronics' official site.
  • If upload fails, try pressing the Reset button on your STM8 board just before upload.

🧩 What's Next?

Now that you've successfully uploaded your first program, you can try:

  • Controlling multiple LEDs
  • Reading analog values with ADC
  • Using UART or I²C for communication
  • Implementing PWM for dimming LEDs or controlling motors

The STM8 platform, though 8-bit, offers industrial-grade performance and reliable peripherals — making it a powerful, budget-friendly choice for embedded development.

🏁 Conclusion

The STM8 microcontroller family is a versatile, low-cost platform for learning and building real-world embedded applications. With sduino and the Arduino IDE, programming STM8 boards becomes incredibly easy — combining Arduino's simplicity with STM's powerful hardware.

Whether you're a beginner exploring microcontrollers or a developer working on low-power or automotive-grade systems, STM8 gives you a dependable foundation for all kinds of embedded projects.

Happy Making! πŸš€

0 comments:

Post a Comment