Introduction to STM8S Series
If you’re an electronics student, professional, present or an upcoming enthusiast, you’ve probably heard or used an Arduino at least once. We all know and love Arduino, it’s simplicity and ease of use is what has made the entry into electronics so much easier and accessible for so many.
What makes Arduino, or more so it’s IDE so good is its robust system of libraries. Albeit adds more abstraction towards programming of microcontrollers making it not so ideal for professional level work, but for beginners and those who are interested in learning about basic projects, Arduino and Arduino IDE proves to be a very useful and helpful tool.
Now another great thing about Arduino IDE is support not just for Arduino Boards, but many other types of boards such as ESP32, Adafruit etc. or in our case today, STM8.
Specifically speaking, we’ll be working on the STM8S003F3 development board.
New Product Idea?- Contact Us
STM8S Family and STM8S003F3 Board
Before we dive into the setup process, lets discuss our board in use. ST’s STM8S series of mainstream 8-bit microcontrollers cover a large variety of applications in the industrial, consumer and computer markets, particularly where large volumes are concerned.
The STM8S003F3 board is part of the STM8S’s value line which offers the best price/performance ratio among all their 8-bit microcontrollers. The board provides a 16Mhz CPU, flash memory of 8KB, RAM of 1KB and an integrated EEPROM. With a 20 Pin TSSOP/QFN, it offers good performance at a substantially low price, making it easy for those who are just starting out in their embedded journey or those not looking to spend a large amount of money.
For more information you can visit this page: https://www.st.com/en/microcontrollers-microprocessors/stm8s003f3.html
Setting up the Arduino IDE
You can use STM8 boards due to a tool built by Michael Mayor called Sduino. The great thing about this is that it supports most of the popular STM8S family of boards, allows for Arduino style programming and allows use of the Standard Peripheral Library which allows you to compile any program built on the native STM8 IDE on Arduino IDE. Even though we are working on the STM8S003F3 board, the procedure is same for all other boards.
Let’s get into the installation and setup of Sduino.
STEP 1: If you’re completely new to Arduino and haven’t installed the IDE, go ahead and install the version compatible with your OS from the official Arduino website.
STEP 2: Once Arduino IDE has been installed successfully, open it and from the top menu bar select File -> Preferences. This will open the preference window where you will be able to see a section called “Additional Boards Manager URL.” In this section go ahead and paste this URL, and then click OK.
https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_index.json
STEP3: Once you’ve entered the URL and pressed OK, a status bar will execute some processes briefly. After this, either from the top menu bar again select Tools -> Boards -> Board Manager or from the left menu bar select the second option.
Once board manager has opened, type in Sduino, and it should pop up. Once you see it, select the latest version and click on the install button. If done successfully, it should show it on the terminal window.
NOTE: (“no unique root dir in archive” error)
During my installation I faced an issue of “error: searching package root dir: no unique root dir in archive”.
If the installation failed for you due to similar reasons please try the following methods:
Method 1: Follow the steps in this link: https://github.com/tenbaht/sduino/issues/150
Method 2: Add this link in the “Additional Boards Manager URL” similar to how it is done in Step 2. If you have more than one URL in the section, please separate them with a comma (,).
https://github.com/akashkapashia/stm8_arduino/raw/master/package_sduino_stm8_index.json
Once your installation is successful, we can now move onto programming the board.
LED Blink Program on STM8S003F3 with Arduino IDE
STEP 1: Before beginning programming your board, we’ll need to do the required connections. For that you’ll need three things,
- STM8S003F3 Development Board
- ST Link V2 (This will help us program the board since it has no data lines in USB)
- Jumper Cables for connection
- Once you have both of them, connect the 3.3V, SWIM, GND, and RST/NRST pins from the board to the ST Link accordingly via the jumper cables. Attached is a pin diagram for reference.
Once connected it should look like this:
Once the connections are done, connect the ST Link via any USB port in your laptop. The drivers should install automatically.
STEP 2: Once you made all your connections, go ahead and launch Arduino IDE if you haven’t already. If your board is not auto detected, from the top menu select Tools -> Board -> Sduino STM8 plain C Core -> STM8S103F3 Breakout Board. There is no specific board for STM8S003F3 board but fret not, selecting this board will work with our board perfectly fine.
STEP 3: Once the board is detected, from the top menu select File -> Examples -> Generic Examples (Below the greyed-out section which says “Examples for STM8S103F3 Breakout Board) -> Basics -> Blink.
STEP 4: Once the example sketch has loaded, select your programmer as ST-Link V2 or whichever one you are using.
STEP 5: Finally, you are all set. Either hit Ctrl + U or press the right facing arrow below the menu bar to upload the code to the board. Once the upload is successful, you’ll see the internal LED on the STM8S board.
Understanding the Code Working
In the above diagram you can see the pinout of our STM8S003F3 board along with the corresponding Arduino pin map in green lines.
The example code is as follows:
From the pinout diagram you can see that the internal LED of the board is on pin PB5 which corresponds to the D3 pin of the Arduino. Therefore, we can re-write this code to be:
This will work the exact same way as the initial code.
Conclusion
That’s it. See how simple it was to write a whole program and upload it, and the best part is it was written in the Arduino language. No need for register definitions, or writing header files. Everything is already written and integrated for you to use and enjoy. This could be very helpful to those starting out or those who have a tight deadline as it makes the entire process compared to how you’d do it normally in the native STVD extremely simple and fast.
Happy Programming!
For More Product and Information – Click Here
Follow us on Instagram- Click Here