Introduction: Setup ST Visual Develop With the Cosmic STM8 Compiler

This is how I setup the Integrated Development Environment (IDE) to program STM8 microcontrollers from ST Microelectronics (ST) with Windows 10. I do not claim this is the right way, but it works well for me.
In this Instructable it will look like a lot of work, but it actually isn't that much work at all.


Coffee and some patience

PC with Windows 10

Internet access

STLink debugger/programmer

Step 1: Download the Cosmic Compiler and ST Microelectronics IDE (STVD)

You will need to register on the site and the site and download several programs from them. Additionally you need a license to use the Cosmic compiler. This license is free and valid for a year, after which you simply ask for a new license. The license is valid only for the pc on which the request is made.
I think it is paid for by ST as a service for the the companies that use their hardware, but I'm not sure about that. (I know there is another compiler, SDCC, that is open source but I do not have any experience with it.)

I'll start with the download of the Cosmic compiler because the request for a license is handled by a employee of Cosmic so it can take some time, if you send the request in a weekend you will probably have to wait until the next week. In that time we can download and install the IDE from ST. So go to:

Scroll down until you see the yellow block "STM8 free tools with no limits", click on the "Register and Download" link and fill in the requested info. After that you can download the compilers. There are two compilers and two programs called Idea_STM8 and IdeaCXM in the download, we'll only use the STM8 compiler of it.

Step 2: Installing the Cosmic Compiler(s)

Run the downloaded program as administrator of your pc (you'll need the admin password) so it can install in the "Program Files (x86)" directory. Simply follow the instructions, accept the license (I haven't read it, does anyone?), fill in your name and some company name and click next through then next screens. After installing all files, it wants to put itself in the "path", I made it register itself in HKEY_LOCAL_MACHINE so that it will work for all users of the pc, not just the administrator.

Take care to read the information in the next screens and select what you want or not, e.g. I don't want any icons on the desktop.

At the end of the install the Readme.txt opens telling you that you can regiiter the software in two ways. With me the "On the Web" method didn't work so I chose the email option. Fill in the User, Company and Email with your real name and email address, I do not have a company so I just made up a nice name. Then select "Write to File", save it in a place where you and administrator have access to: C:\ worked for me. You can send this file as an attachment to an email or copy the text in it an put that in the body of your email to Cosmic. The email address is:

and make sure you put: "STM8FSE_2020 License Request" as the subject. Finish the installation and let your pc restart. And then just wait for the license to arrive.

Step 3: Download and Install ST Visual Develop

In the meantime download and install the ST Visual Develop software.

Go to:

Scroll to the bottom of the page and click on "Get Software", accept the License Agreement (I didn't read it either...) and Login if you already have a login with ST or register if you do not yet have a login. The ST site is rather slow, so you may have to wait for a response of it for several seconds, just wait patiently, it will work.

Save the downloaded zip-file and open it, extract the software to where Windows wants it to. Start the installation of ST Visual develop by running "sttoolset_pack42.exe" asadministrator. Click through the first screens, again accepting the license agreement (and again without reading it) and accepting most of the options ST suggests. No, I don't know why ST chose directory names like "st_toolset" either. Again, I didn't want desktop icons and I didn't read the Release notes.

The first time I installed the ST Toolset it failed by hanging at the end of the install. When I ended the install via the taskmanager and tried to start ST Visual Develop I got a screen telling that there had been an "anomaly". After which the program started.....

I re-installed and the second time it went well. Another restart of Windows later the program was installed correctly and started without error messages.

Step 4: Some Options in STVD

We need to set several option in ST Visual Develop (STVD)
Go to - Tools - Options - Toolset. Select the Toolset called "STM8 Cosmic" and set its "Root path" to :

"C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8"

The "Bin path" can remain empty, the "Include path" will already be "HSTM8" and the "Lib path" will be "Lib", those are all correct. Click Apply and OK, the warning(s) you will receive are about other Toolsets so they can be ignored.

Take a look at the other tabs of the Options, you may want to change some of the options.

In the tab "Debug" I selected Automatic File Saving because it annoyed me when after every edit it asked if I wanted to save before a compilation. Of course It want my edits saved!

In the tab "Edit" I disabled the Long Line - Enabled by default and I have changed the tab-size from 2 to 4 and the font from "Courier New" to "Consolas" with a point size of 12.

But these settings are personal preferences, not important and can be done later.

Step 5: First Program (blinky)

It is time to get programming. To do that we need a so called workspace where STVD saves information about the projects in it.
Click on File - New Workspace - Create Empty Workspace, I usually give the workspace the name of the type of microcontroller I will be using for the project in it. So I will chose "STM8S103" and I will put it in a directory with the same name.

Now you can "right-click" the Workspace (STM8S103.stw) and create a new project in it. Then click New Project and give it the name you want, also create a directory to put this project in, STVD does not do that by itself! Select the STM8 Cosmic toolchain and check if the Toolchain root is "C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8" Click OK.

Next select the microcontroller you will be using, here I will choose the STM8S103F3P, and click Select, OK

The project is created and you can open the folders to see what files have been created by STVD. Now CLOSE ST Visual Develop and save the changes in the workspace and your new project. We will overwrite some files and add more to prepare STVD for use with the Cosmic compiler.

Step 6: Overwrite and Add Files

The files needed can be downloaded from:

and save them in a new folder, I call this folder my Template

In the previous step we created the project in its own project folder. Copy ALL files and folders you downloaded from Gitlab into this project folder. It will replace some files that are already there.

The standard library is used (see main.h)
stm8s_conf.h is already editted to exclude USE_FULL_ASSERT)

stm8s_it.c is already editted to include TIMER4 UPDATE IRQ handling (for systick and DELAY)

Step 7: Restart ST Visual Develop and Finish Project Setup

When you restart STVD you will be presented a very empty screen.

To get to your project select File - Recent Workspace - "the name you gave it" STVD will open the last (and still only) project. You can take a first look at the files, but we're not ready yet.

First add the following files:

stm8s_it.c to Source Files

stm8s_it.h and main.h to Include Files (see pictures)

Now create the folders in the project folder:






standard_lib/scr (see pictures)

And after that add all the files in the corresponding disk-folders to the new folders in the project. In the end it should look like the last picture above.

Step 8: The Project Settings

We are nearly ready...

GO TO: Project -> Settings -> General

- Toolset should be STM8 Cosmic

- choose "Project specific toolset path"

- change Root path into: C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8

- include path should be Hstm8, library path should be Lib

GO TO: Project -> Settings -> C-Compiler -> Category General

– change the Optimizations to Customize

– change Compiler Message Display from "Display errors only" to "Display errors & Warnings”

– add STM8S103 HSE_VALUE=16000000UL to the Preprocessor Definitions

– (or the STM8S103 or other microcontroller type and the actual HSE value you use)

GO TO: Project -> Settings -> C-Compiler ->Category Optimizations

For DEBUG select:

– Disable for Debugging (-no)

– Split Functions in Separate Sections (+split)

For RELEASE select :

– Split Functions in Separate Sections (+split)

– Speed Optimization (+fast) (STM8 Cosmic>= 4.3.2)

– or choose Minimize code size (+compact )

(but not both +fast and +compact)

GO TO: Project -> Settings -> C-Compiler -> Category Preprocessor

- additional include libraries should be:

standard_lib\inc ; lib\inc ;. ← add the "dot"

- check this for both Debug and Release Settings

GO TO: Project -> Settings -> Linker

- in the Category Output, tick "Generate Map file"

- if you need support for floating point variables, in the Category General tick Float (this will increase the size of the code, so do this only when needed)

- do this for both Debug and Release Settings

And finally:

click OK and try REBUILD_ALL to check for warnings / errors. If all goes well the code is compiled without any errors and linked into a S19 file that you can find in the Debug folder.

Step 9: Programming the Microcontroller

That last step is to get the code into the microcontroller itself. There are several ways to do this, here I'll show how to do it with the "Light Programmer" that is part of STVD.

In the menu-bar you will find it under Tools - Programmer

GO TO: Tools -> Programmer -> Settings:

– change Hardware to "ST-LINK"

GO TO: Tools -> Programmer -> Memory Areas
– DATA MEMORY: should be empty

– PROGRAM MEMORY -> Add: projectname\Debug\xxx.s19 file or

– PROGRAM MEMORY -> Add: projectname\Release\xxx.s19 file when you compiled in release mode

The option bytes are interesting to check but ususally are correct. I think it is best to change the option bytes with a separate program: ST Visual Programmer that I will not discusse here.

NOW CLICK OK, this is important, do this before programming the microcontroller or you will keep setting all the options mentioned above.

GO TO: Tools -> Programmer -> Program

click "Start" to upload the code to the MCU and admire you blinking led :-)

Step 10: Problem Solving

For reasons unknown to me it can happen that Debugging doesn't work The solution seems to be to unregister the DAO350.LL file and re-register it.

To do this start cmd as administrator and run the next commands:

Regsvr32 /u "C:\Program Files (x86)\Common Files\Microsoft Shared\DAO\DAO350.DLL"

Regsvr32 "C:\Program Files (x86)\Common Files\Microsoft Shared\DAO\DAO350.DLL"

It can also happen that as soon as you want to start the Light Programmer, STVD will crash, sometimes with an "out of memory" error. If this happens, copy the file ProgrammerAddOn.DLL over the one in the /STVD folder.

Using the EEProm

When data needs to go into the EEPROM, uploading via the Light Programmer does
NOT work with me. The solution I found is to open a DEBUG session, that will take care of programming both the PROGRAM MEMORY and DATA MEMORY (eeprom)

I had some minor problems with access to files and folders from both Cosmic and STVD, this is because I use Windows as a regular user and not as administrator. I know it isn't the right way to solve it, but I simply gave all regular users on the pc Modify rights in the folders:

C:\Program Files (x86)\STMicroelectronics\st_toolset

C:\Program Files (x86)\COSMIC\FSE_Compilers

When Debugging doesn't start with the message to select a target, the program hasn't set the ST-Link as the Debug Instrument. Select that option on the main taskbar and set the Debug Instrument Selection to Swim ST-Link


Some people have reported they experience a "side by side error" when starting STVD. This seems to be related to Microsoft Visual C++ 2005 Redistributable. Re-installing it solved the problem. The lastest version at this moment is the Microsoft Visual C++ 2005 Service Pack 1 Redistributable and can be downloaded from the Microsoft website.

Step 11: Stlink V2 and STM8S103F3p Module

Not much to say, just to show the STlink-V2 and STM8S103F3P that I use. I have both the genuine STLink made by ST Microelectronics as the cheap clone I bought via Ebay, both work fine. The STM8S103 modules all come from Ebay, Aliepress or other, I don't think that the official dealers as Farnell or Mouse will have the STM8S103 as modules, but you can get them as bare parts.