Vous êtes sur la page 1sur 9

STM8S Tutorials #1 Tools

As we progress in this tutorial series we will come across almost all the main features of this 8-Bit controller. In this tutorial series
we will focus mainly on STM8S series which is a medium code density member of STM8 family.

ST microelectronics provides rich tech support and evaluation platforms for a quick start. Most easy way to start with STM8
microcontroller is to grab aSTM8S Discovery board which is a low cost development board with all the necessary features to kick-
start application development using STM8 mcu.

STM8S Features

STM8 Core based on Harvard Architecture.

16MHz Operation w/ 3-stage Pipeline

32 KByte Program Memory

2 KByte RAM

Internal RC Oscillator

3, 16 Bit Timers, One Advance, Two Gen Purpose Timers

1, 8 Bit Timer

UART, SPI, I2C Blocks

10 bit, 10 Channel ADC

Single Wire Programming Interface (SWIM)

This series guides you to get started with your STM8S Discovery board. Subsequent posts on STM8S tutorial series will guide you
on further programming and interfacing with this feature rich 8-Bit controller. This particular post lists the necessary hardware and
software required to start application development.

Software Tools
These are minimum possible software tools required to start with STM8 Controllers in Windows OS. Go to following pages to
download required installation file.

1. STVD [ST Visual Develop IDE] IDE for compilation, debugging and project management

2. STVP [ST Visual Programmer] Burner Software

3. Cosmic C Compiler for STM8 MCU

Thats it, thats all you need to start application development using STM8S controller. Install these 3 software in your windows
based computer. [PS - Development tools for Linux based machines will be updated soon].

Once all three software packages are installed, next step is to configure STVP and STVD to work with STM8S Discovery Board.

STVP Configuration

To configure STVP to program STM8S105C6T6 controller on Discovery board go to Menu bar in STVP and choose

Configure ->Configure ST Visual Programmer


Note configure settings in Image below

STVP Configuration for STM8S Discovery Board

STVD Configuration
STVD is a great tool, it is used for efficient project management, debugging and overall IDE for STM8 controllers, but remember
STVD is not a C compiler, to develop application programs using C language we need a C compiler that understands the
language of STM8S internals and does all the cross compilation for STM8S. Cosmic C compiler is one such compiler. Cosmic
compilers size limited evaluation version is free for download at the link given in software tools section of this post. Once both
STVD and Cosmic compiler are installed in system it is necessary to link the path of cosmic C compiler with STVD. So that, STVD
knows where to look at, when it need to compile any C file.

Go to STVD-> Project->Settings

Choose following options in General Tab of Project Settings

STM8S STVD Settings to link Cosmic C compiler with STVD

Once configuration of STVP and STVD is done we are now ready to write our first firmware for STM8S105Cx MCU.
STM8 Tutorials #2 Hello World Program

Without much talks, lets create our first Hello World application for STM8S Discovery Board. As practiced in
embedded world, this time also, LED blinking is our way to say Hello to STM8S world.

STM8S Discovery has an on-board Green Colored user LED connected to PD0. We will blink this led on and off
with some delay in between.

STM8S Discovery LED connected to PD0

STEP 1: STVD Workspace/Project Creation

Create a new STVD Workspace from File menu

Step -1 Create Workspace


Step -2 Project Name

Step -3 Project Toolchain selection as Cosmic STM8

Step -4 Choose STM8S105C6 as Target MCU

Step 5 Review Project File Tree

STEP 2 Adding STM8S Register Definition header stm8s.h


To compile any C project for STM8S can not be done without mapping register definition into suitable names. This
file is very important and it will be there in all most all the upcoming projects. It maps register addresses with
suitable names. For example GPIOA base register is at 05000, this file has definition to map 05000 to a name as
GPIOA.

Add stm8s.h file into your project

Verify that stm8s.h has been added in your project

STEP 3 Writing the Code

1 #include "stm8s.h"
2 void myDelay(void);
3
4 void myDelay()
5 {
6 int i,j;
7 for(i=0;i<1000;i++)
8 {
9 for(j=0;j<100;j++);
10 }
11 }
12
13 main()
14 {
15 GPIOD->DDR |= 0x01; // PD.0 as Output
16 GPIOD->CR1 |= 0x01; // PD.0 as Push Pull Type Output
17 while (1)
18 {
19 GPIOD->ODR |=1<<0; // PD.o = 1
20 myDelay();
21 GPIOD->ODR &= ~(1<<0); // PD.0 = 0
22 myDelay();
23 }
24 }

STEP 4 Compile and Build the Project


Compile and build the necessary machine files by pressing F7. If build process does not produce any errors, our
code is successfully cross compiled and machine code is now ready to download on mcu program memory.

STEP 5 Download the code onto MCU Program Memory


Now, open STVP and open .s19 file from the Debug folder inside project directory.

After opening the .s19 file, choose Program current tab from STVP Menu options.
STVD after successful device programming

STM8 Tutorials #3 Handling Inputs


This is 3rd tutorial in series of tutorials on STM8 microcontroller by ST Microelectronics. In this tutorial, we will learn, how to
handle inputs on GPIO ports/pins of STM8S controller. We are considering only Polling method of reading inputs in this article,
Interrupt method will be covered later.

Reading input on any of the STM8S GPIO pin is very straight forward. Lets take this step by step.

Step 1 Declare the GPIO Pin/Port as Input

One has to declare any GPIO pin as input before any physical signal input can be read from that GPIO pin. To declare the GPIO
pin as Input we again need to set proper bits in DDR Register of corresponding port. Table below shows different combinations of
DDR, CR1 & CR2 registers in order to set any GPIO either as Input or Output and to enable or disable Pull ups and Interrupts.

STM8S GPIO Modes

In this experiment we are going to use GPIO as Input with Pull up but without Interrupts. So, for example if I want to use PE.7 as
input with Pull up enabled and Interrupt disabled. I need to write corresponding bit (bit 7) in DDR register of PORTE as 0.
1 GPIOE->DDR &= ~(1<<7); // Declare PE.7 as Input
1 GPIOE->CR1 |= 1<<7; // PE.7 Pull Up Enabled

Now, once we have set PE.7 as Input with Internal Pull-Up, we are now ready to read the input logic status at PE.7 Pin.

Step -2 Read Pin status from IDR Register

STM8S has ODR register to write on output port and IDR register to read from input port. IDR is a read-only 8-bit register. Logical
value at any bit of IDR register of a port, reflects the actual logical status of that pin of that port. For example, if Pin 7 of
IDR register of GPIOE is 0, that means, PE.7, if configured as input is currently set to logic 0.

Step 3 Schematic

Figure below shows the connections that Ive made to experiment with Inputs. Circuit has a tactile switch connected to PE.7
and 3 LEDs connected to PC.2, PC.4 and PC.6 respectively.

STM8S105_Input_GPIO_Tutorials_Schematic

Step -4 Code

below is main() function for input handling program. Whenever the user presses the switch at PE.7, the input pin
goes low, the code has a software wait for switch debounce. As the user presses the switch, it will glow all the LED
for approximately 1 second otherwise the LEDs remain off forever.
STM8S_input_handling_code

Vous aimerez peut-être aussi