Starting STM8 Microcontrollers
Codes generated by Cosmic C compiler have s19 file extensions. It is similar to typical hex file format, containing user code as hex values. Well since we don’t need to modify finally generated output files, it doesn’t really matter in which format it is. All we will need is to upload them to our target MCUs. We can do it in two ways – either by using STVP or STVD.
Firstly, let’s check the method with STVP. Run STVP software. For the first time the following window will appear. From here we have to select ST-Link programmer, SWIM interface and our target chip.
STVP interface looks like any other programmer interface as shown below:
Notice the mid tabs at the bottom of the hex values. From here we can see the hex values for program memory, data/EEPROM memory and configuration settings. The configuration setting bits are intended for setting some special hardware configurations or extending features of the target as well as setting memory readout protection.
Try not to mess with security or protection bit at first or during tests as it will lock your chip up, rendering it useless. You won’t simply be able to write it again until you unlock it. Unless needed, we won’t be changing any default configuration bit. One thing to note is the fact that upon new compilation and build, the newly generated output file is automatically reloaded. The rest of the stuffs like loading or saving a s19 file, reading, writing and others are as simple as like with other programmers. I won’t be explaining these steps as I assume that readers of this article already know how to do all these from their previous experiences with other MCUs.
Now we will explore how we can upload a code to our target using STVD. After compiling and building a project successfully without any error, the compiler will generate a s19 output file either in Debug or Release folder depending on which mode of compilation selected. By default, Debug mode is selected unless the coder changed it and so our desired s19 file will be in this folder. First, we need to open the programmer interface. We can do that either by clicking the icon as shown below:
or we can go to Tools >> Programmer.
We will get a new window as shown below:
As the name of the new window suggests, it is a light-weight programmer interface but good enough for our purpose. Notice that there are many options and four tabs. Here again we need to select programmer, programming interface (SWIM) and erase/blank check options. Then we go to the next tab to select files for EEPROM (if any) and Program (also Flash/Code) memory as shown below. You can add/remove files just as usually.
Next, we set configuration bits if needed from the tab as shown below:
Finally, we are ready to upload code. Just hit the start button and wait for the process to finish.
Every time a code is programmed, it is verified automatically.