UM0991
User manual
Developing and debugging
your STM8L-DISCOVERY application code
Introduction
This document complements the information in the STM8L datasheets by describing the
software environment and development recommendations required to build an application
around the STM8L-DISCOVERY. It also explains how to use the STM8L firmware library
provided by STMicroelectronics, in order to develop cost-effective applications.
In addition, ST provides a development package which can be used to build an application
running on the STM8L-DISCOVERY. This package includes application code examples and
a project template.
The STM8L-DISCOVERY is based on the STM8L15x MCU however it can be used to get to
know the main features of other STM8L microcontrollers.
Reference documents
●
●
●
●
●
●
STM8L-DISCOVERY user manual (UM0970)
ST Visual Develop (STVD) user manual (UM0036)
Discover STM8L15x power saving modes using the built-in I
DD
measurement feature of
the STM8L-Discovery (AN3269)
Building a wave generator using the STM8L-DISCOVERY (AN3252)
STM8L15x reference manual (RM0031)
STM8L15xx datasheet
March 2011
Doc ID 17891 Rev 2
1/52
www.st.com
Contents
UM0991
Contents
1
Overview of STM8 software development toolchains . . . . . . . . . . . . . . 6
1.1
1.2
1.3
1.4
1.5
ST Visual Develop (STVD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
ST Visual Programmer (STVP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
C and assembly compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
IAR Embedded Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Firmware libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2
Installing the development toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1
2.2
Downloading and installing STVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Downloading and installing the compilers . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.1
2.2.2
2.2.3
Installing the Cosmic compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Installing the Raisonance compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Compiler settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3
Downloading and Installing IAR Embedded Workbench . . . . . . . . . . . . . 16
3
Description of firmware library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.1
STM8L15x standard firmware library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.1.1
3.1.2
Description of the STM8L15x standard firmware library . . . . . . . . . . . . 22
STM8L15x standard firmware library online help . . . . . . . . . . . . . . . . . 23
4
5
Configuring the option bytes for your application . . . . . . . . . . . . . . . . 24
Building and running your project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.1
Description of the STM8L-DISCOVERY development package . . . . . 27
5.1.1
5.1.2
5.1.3
Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Application code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Project structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
5.2
Running the STM8L-Discovery examples . . . . . . . . . . . . . . . . . . . . . . . . 29
5.2.1
5.2.2
With STVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
With IAR Embedded Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.3
Creating your own project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.3.1
5.3.2
Creating your project structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Creating your STVD project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2/52
Doc ID 17891 Rev 2
UM0991
5.3.3
5.3.4
5.3.5
Contents
Linking the libraries to your STVD project . . . . . . . . . . . . . . . . . . . . . . . 36
Creating your IAR Embedded Workbench project . . . . . . . . . . . . . . . . . 39
Linking the libraries to your IAR project . . . . . . . . . . . . . . . . . . . . . . . . . 42
5.4
Updating the libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.4.1
Updating the STM8L15x standard firmware library . . . . . . . . . . . . . . . . 45
6
Building, debugging and running your application with STVD . . . . . 46
6.1
6.2
6.3
Building your application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Debugging your application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Online help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Doc ID 17891 Rev 2
3/52
List of tables
UM0991
List of tables
Table 1.
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4/52
Doc ID 17891 Rev 2
UM0991
List of figures
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Figure 8.
Figure 9.
Figure 10.
Figure 11.
Figure 12.
Figure 13.
Figure 14.
Figure 15.
Figure 16.
Figure 17.
Figure 18.
Figure 19.
Figure 20.
Figure 21.
Figure 22.
Figure 23.
Figure 24.
Figure 25.
Figure 26.
Figure 27.
Figure 28.
Figure 29.
Figure 30.
Figure 31.
Figure 32.
Figure 33.
Figure 34.
Figure 35.
Figure 36.
Figure 37.
Figure 38.
Figure 39.
Figure 40.
Figure 41.
Figure 42.
Figure 43.
Figure 44.
Figure 45.
Figure 46.
STVD overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Cosmic compiler form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Downloading Cosmic compiler software wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Cosmic compiler installation wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Cosmic compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Raisonance compiler installation wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Activation code registration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Personal information form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Serial key information form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Selecting the Cosmic compiler for the Discover project . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Product Registration and Download form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Download software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Enter User Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Enter license key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
STM8L15x standard firmware library architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
stm8l15x_conf.h peripheral define statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
STM8 firmware library online help home page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Select your MCU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
STVP option byte selection menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
STVP option byte programming menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
STVP option byte programming message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
STM8L-Discovery_dev package content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Selecting the debug instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Selecting the debug instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Creating your project structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Creating the STVD workspace for your project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Checking the selected compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Select the MCU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Copy stm8l15x.h to Include Files/FWLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
No library linked . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Linking the STM8L15x standard firmware library - step 1. . . . . . . . . . . . . . . . . . . . . . . . . . 37
Linking the STM815x standard firmware library - step 2. . . . . . . . . . . . . . . . . . . . . . . . . . . 38
IAR Embedded Workbench workspace window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Checking the Additional Include Directories path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Select the MCU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Copy stm8s.h to Include Files/FWLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
No libraries linked . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Linking the STM8L standard firmware library - step 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Linking the STM8L standard firmware library - step 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Selecting the project configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Building your project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Building successful message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Debugging your application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Peripheral registers window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Watch window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
STVD online help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Doc ID 17891 Rev 2
5/52