Like an Arduino Nano just enough circuit to get you going. We need to program through the SWIM interface pins until we add a bootloader to program on USB. More on the board.
Contains the STM8S103 or STM8S003 MCU microcontroller unit from Thompson Semiconductor corporation. We will see long lists of chip numbers but these chips all have 1kB RAM and 8kB flash memory for programs. An 8bit processor comparable to an ATtiny or 8051 chip.
The boards are listed as STM8S003F3P6, STM8S103F3 and STM8S103K3T6. Specifications are the same, programs compile same for both. LED pin B5 for the little board and pin C3 for the big one.
SWIM Programming InterfaceTo upload your compiled binary executable program you need an ST-Link programmer device. We'll use an inexpensive ST-LinkV2. The SWIM pins are for STM8 and SWD is for other chips.
Look closely at the label printed on the programmer and the pins. Connect RST-SWIM-GND-3v3. You can power some boards from the ST-Link.
Get it for free. Fill out the webpageto download the compiler software package. Begin installation on your computer.
During the installation this screen popped up asking me to register for a license to use the STM8 Compiler. I had to Write to File and e-mail my request to stm8_Free@cosmic.fr with the title STM8FSE_2024 License Request.
I received an e-mail from Cosmic containing a license.lic file. It had to be copied into the folder C:\Program Files(x86)\COSMIC\FSE_Compilers\CXSTM8\License like this.
Thomson provides the Standard Peripheral Library to use with the STM8S product line. We want to benefit from the prewritten software by downloading and unzipping the package.
Only 15MB you can put a copy in your project folder. But I am keeping mine in Downloads.
Open ST Visual DevelopThis is the design studio program provided to develop software for STM8 processors. We can open and manage a project workspace in assembly language but we will need to install a compiler program to compose our C/C++ projects.
Look at the menus. Open sub-menus to see what other commands are there. The build menu compiles our source files into executable programs for us. There are keyboard shortcuts.
STVD installed sample files that will run on your computer. Look for the extension .stw for STVD Workspace. Files for a software project can be organized anywhere in your computer. Defaults are in C:\Program files (x86)\STMicroelectronics.
Create New WorkspaceLike in the assembly project create a new folder named cosmic that you can put the files into. Open STVD and create a new workspace named cosmic, make sure it uses our folder for workspace location.
New Project name cosmic and locate in the same folder cosmic. When STVD finds a compiler it can use it will fill out path information:
To write programs in C/C++ we need to use a compiler program that is not provided by Thomson. Compilers, software libraries and sample programs are available from several companies.
When STVD finds a compiler it can use it will fill out path information: Select STM8S003F3P MicroController Unit. It works with the boards in the picture.
Save the workspace. If we setup right we should see new default files in our project folder. Workplace files have the .stw extension. STVD automatically generates source files main.c and stm8_interrupt_vector.c.
This is a program that compiles and shows us we have a working toolchain. We are setup to program STM8 chips and we have code for it.
Expand the Source & Include Files folders and open the three text files. They are the same ones we saw in the folder. Right-click on icons and you will see extra commands that are on the menu bar. This is how we add and remove files and locate them by properties.
Build->BuildPress F7 on your keyboard or menu Build->Build and watch the text zip past at the bottom of the screen. We are watching the assembler and linker convert our source program into an executable.
A new file has been generated named cosmic.s19. This extension means it is a Motorola format program file, like a hex file. The output shows us that our toolchain is healthy and working. Plus we see exactly what options are added to each command.
We Made a New File?STVD generated output files in our project folder. Look inside the new Debug folder. When you check menus look for this name.
In the Debug folder the file we care about is stm8.s19. Some of the other text files are maps and listings that you can open with notepad. Notice all were generated at the same time. The Build->Clean command erases all of these.
Grammatically valid. We could upload this file to a processor or disassemble it. But it does not execute any function on the board.
GUI Graphical User Interface STVDExplore what you have, so far. Read the code. Look at the menus. Slide the windows around. Many technical features for flexibility.
Under the Build menu click the Build command and watch the text zip past at the bottom of the screen. Compile checks the code in your current file. Clean will erase the generated files in the Debug folder.
Look at the code in main.c it's just a while loop. The output does show us that our toolchain is healthy and working. Plus we see exactly what options are added to each command.
CodeSelect all of the default code in the main.c file and replace it with:
// toggle IO pins on PORTS A to D
#include "stm8s.h"
void simpleDelay(void){int n = 5000; while(n-- >0);}
main()
{ GPIOA->DDR = 0xFF;GPIOB->DDR = 0xFF;GPIOC->DDR = 0xFF;
GPIOD->DDR = 0xFF;GPIOE->DDR = 0xFF; // PORTs A-E all out
while (1)
{ GPIOA->ODR = ~GPIOA->ODR;GPIOB->ODR++;--GPIOC->ODR;
GPIOD->ODR = ~GPIOD->ODR; // toggle pins
simpleDelay();}}
If you performed the Arduino project you will recognize the code. We turn on 8bit IO ports on the chip as outputs then loop mathematics to toggle the IO pins.
The first line of code is #include"stms8s.h" so the compiler needs to find a header file in the folder with main.c. It's a file that maps out the circuits and ports on the STM8S chip. And we need a copy with line 48 uncommented like this.
The files could already be located in our project folder or they can be somewhere else. Download the attached header file and blinky code. Place them in the project folder with main.c. Use notepad to check we are putting a modified stm8s.h file like this.
Expand the Source and Include folders. Right click and look at the Add Remove Files command. Menu Build->Build or press F7 on you keyboard and watch the bottom of the screen for successful build.
Right click directly on the Source Files icon and click Add Files. Locate our modified copy of stm8s.h file in the project folder. Open to add to our project.
To our source add stm8s_conf.h it is located in the SPL folder STM8S_StdPeriph_Lib\ProjectSTM8S_StdPeriph_Template. The red output text is being helpful.
SPL has header files at STM8S_StdPeriph_Lib\Libraries\STM8S_StdPeriph_Driver\inc. Open the folder and select all with ctrl-A. Open, like before. There is a second stm8s.h file but it will not be read by our compiler.
Generates our .s19 file using cxstm8 command and plenty of extra files. The clean command erases all of our output and leaves our source files.
The default is to create a file in the Debug folder. Looks a lot like Intel hex file.
We often call these software loads firmware. The idea is that we are putting software into a solid device. Program STM8S Processors with ST-Link SWIM Interface shows how to connect our development board to the PC.
Menu File->Open and navigate to the debug folder inside the cosmic directory located somewhere on your computer. You can filter to see .hex, .s19 or all files.
The numbers on the screen are the ones and zeros of our firmware.
Program->Current tabWatch text scroll at the bottom to show progress. I have to exit for my board to restart.
Change the value of n in simpleDelay to speed up or slow down the light. LED pin B5 for the little board and pin C3 for the big one.
Comments
Please log in or sign up to comment.