Starting STM8 Microcontrollers

STM8S003K3 Discovery

Hardware Tools

The list of hardware tools needed is not very long.  We will obviously need a STM8 board and I prefer a Discovery board over other boards since it comes with a built-in ST-Link programmer/debugger hardware. If you have some other board like the ones I already showed, you will need a ST-Link programmer. I recommend an additional ST-Link programmer apart from the one available on board.

ST-LINK

ST-Link programmers/debuggers communicate with target STM8 micros via SWIM interface. This interface is the standard for all STM8 micros. Basically, it is a four-wire interface with two wire (VDD and GND) being used for powering the target. The rest two are reset I/O and SWIM I/O. In the official ST-Link V2 programmer unlike other ST-Link programmers, there is a dedicated port for SWIM interface with STM8 inscribed near it. Cheap USB flash drive-sized ST-Links are also available in the market and they are portable and as good as the official ones.

SWIM Interface

Apart from these we will also require some basic electronic lab stuffs like a USB-to-serial converter, connecting/jumper wires, LEDs, buttons, various types of sensors, etc. that are typically found in a common Arduino starter kit.

Arduino Starter Kit

It is yet better if you have either a logic analyser or oscilloscope. A good multimeter and a well-regulated DC power supply/source are must haves. You can also use a cell phone charging power bank as a power source since Disco boards have USB ports.

Saleae Logic 4

Software Tools

Just like any other software developer, my choice of language for software development is C language. I don’t want to spend time coding complex stuffs in assembly language. Apart from that I chose C language for the fact that STMicroelectronics has provided a Standard Peripheral Library (SPL) that is very easy to use. With SPL, it becomes totally unnecessary to program each register with meaningless numbers and maintain coding sequence. We will never need to access registers for any reasons as everything is done under the hood of SPL. All sequences are deal inside the SPL. All that we will ever need is the clear concept of each hardware block, their working principles, their capabilities and limitations.

We will need an Integrated Development Environment (IDE) and a C-language toolchain. The best stuffs you can get your hands on at zero costs are ST Visual Develop (STVD) IDE and Cosmic C compiler. Both are free but a rather difficult to use at first. STVD also comes with a programmer software tool called ST Visual Programmer (STVP). We’ll need STVP to upload codes to target STM8 micros.

Cosmic used to be a paid tool just like your PC’s antivirus software but at the time of writing this article, the Cosmic team has made it absolutely free for STM8 family. However, to use it you will need to register and acquire a license key via email. Usually this procedure of acquiring license and registration is maintained automatically by the software company’s server but with Cosmic it is different story. You will need to wait for some guy at Cosmic end to respond to your license request. It may take a few minutes or even a day but still the best part is getting a full version compiler for nothing.

STVD

You can get

STVD from here: http://www.st.com/en/development-tools/stvd-stm8.html and

Cosmic C compiler from here: http://www.cosmic-software.com/download.php.

You need to register in order to download both software. For Cosmic you will also need to acquire a free license for it work. So just fill in some basic info about you.

COSMIC 1

Firstly, we will need to install STVD. Installation procedure is simple and same as typical software installation. Just click next, next and next. After that we will need to install Cosmic C compiler. Again, just next, next and next until the screen as shown below.

COSMIC 2

After installation, you’ll prompted for licence. You must register your license unless you have already registered. If you have already registered, then you’ll be asked if to overwrite registration. You should skip reregistering.

COSMIC 2b

For the first run, you’ll get the following screen looking for a valid license.

COSMIC 3

You must fill all the starred (*) points to complete the process of registration. Select “Write to File” option and save the file as a text (.txt) file. The file name should be “CM8_license.txt”. Send this file to stm8_Free@cosmic.fr with subject “STM8FSE, STM32 32K License Request”. Now you’ll need to wait for the Cosmic team to respond to you. They’ll send you an email back with an electronic key license. The file will have a name like “license.lic” and the email will have some instructions.

This was my emailed license.

Email

Once you get the license, you’ll need to show the software its location and complete the licensing process as shown below. Save the license file in a secured location.

COSMIC 4

COSMIC 5

COSMIC 6

At the end of this process, we can enjoy the compiler without any limitations.

I also recommend that you download Sublime Text (https://www.sublimetext.com/) or Notepad++ (https://notepad-plus-plus.org/) for viewing your code with ease. These are very cool software. This is not mandatory though.

Code

Continue Reading ...

Related Posts

5 comments

Leave a Reply

Your email address will not be published. Required fields are marked *