STMicroelectronics STSW-STM8008 User Manual
Pubblicità
Pubblicità
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
4
5
Contents
Contents
1
2
3
UM0991
Overview of STM8 software development toolchains . . . . . . . . . . . . . . 6
ST Visual Develop (STVD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
ST Visual Programmer (STVP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
C and assembly compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
IAR Embedded Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Installing the development toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Downloading and installing STVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Downloading and installing the compilers . . . . . . . . . . . . . . . . . . . . . . . . . 9
Installing the Cosmic compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Installing the Raisonance compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Downloading and Installing IAR Embedded Workbench . . . . . . . . . . . . . 16
Description of firmware library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
STM8L15x standard firmware library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Description of the STM8L15x standard firmware library . . . . . . . . . . . . 22
STM8L15x standard firmware library online help . . . . . . . . . . . . . . . . . 23
Configuring the option bytes for your application . . . . . . . . . . . . . . . . 24
Building and running your project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Description of the STM8L-DISCOVERY development package . . . . . 27
Application code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Running the STM8L-Discovery examples . . . . . . . . . . . . . . . . . . . . . . . . 29
With IAR Embedded Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Creating your own project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Creating your project structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Creating your STVD project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2/52 Doc ID 17891 Rev 2
UM0991
6
7
Contents
Linking the libraries to your STVD project . . . . . . . . . . . . . . . . . . . . . . . 36
Creating your IAR Embedded Workbench project . . . . . . . . . . . . . . . . . 39
Linking the libraries to your IAR project . . . . . . . . . . . . . . . . . . . . . . . . . 42
Updating the STM8L15x standard firmware library . . . . . . . . . . . . . . . . 45
Building, debugging and running your application with STVD . . . . . 46
Debugging your application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Doc ID 17891 Rev 2 3/52
List of tables
List of tables
UM0991
4/52 Doc ID 17891 Rev 2
UM0991
List of figures
List of figures
Doc ID 17891 Rev 2 5/52
Overview of STM8 software development toolchains
1
UM0991
Overview of STM8 software development toolchains
●
●
To develop, compile and run an application software on an STM8L microcontroller, the following software toolchain components are required:
● Integrated development environment (IDE) composed of the ST Visual Develop (STVD) and the ST Visual Programmer software interface (STVP)
Compilers
Firmware libraries: they are optional, and allow to easily create a new application
STMicroelectronics provides a free software package (ST_toolset) including STVD and
STVP.
You may also use the IAR Embedded Workbench for STMicroelectronics STM8. This toolchain is made up of the following components:
● Integrated development environment for building and debugging embedded applications.
● Compiler
Warning: IAR Embedded Workbench supports STM8L firmware library versions 1.3.0 and higher
1.1 ST Visual Develop (STVD)
STVD is a full-featured development environment. It is a seamless integration of the Cosmic and Raisonance C compilers for STM8 microcontroller family. These compilers are free when developing code up to 16 Kbytes.
STVD main features are:
●
●
●
●
●
Seamless integration of C and ASM compilers
Full-featured debugger
Project management
Syntax highlighting editor
Integrated programming interface
6/52 Doc ID 17891 Rev 2
UM0991
Figure 1.
STVD overview
Overview of STM8 software development toolchains
1.2
1.3
ST Visual Programmer (STVP)
STVP is a easy-to-use graphical interface allowing to read, write and verify the code and data programmed in your STM8 microcontroller Flash program memory, data EEPROM and option bytes. STVP also features a project mode for saving programming configurations and automating programming sequences.
C and assembly compilers
The C and assembly compilers are seamlessly integrated into the STVD development environment. They allow to directly configure and control the building of your application from an easy-to-use graphical interface.
The supported compilers are the following:
● Cosmic C compiler for STM8 (free version up to 16 Kbytes of code and temporary storage of up to 32 KBytes)
●
For more information, refer to http://www.cosmic-software.com.
Raisonance C compiler for STM8 (free up to 32Kbytes of code)
●
For more information, refer to http://www.raisonance.com.
STM8 assembler linker
This is a free assembly toolchain included in the STVD toolset. It allows you to assemble and link your application source code.
Doc ID 17891 Rev 2 7/52
Overview of STM8 software development toolchains
1.4
UM0991
IAR Embedded Workbench
IAR Embedded Workbench is a set of development tools for building and debugging embedded system applications using assembler and C. It provides a completely integrated development environment that includes a project manager, editor, build tools and C-SPY debugger. The C compiler for STM8 which is included in the toolset is free for up to 8Kbytes of code.
The STM8L15x standard firmware library is a complete package consisting of drivers for all the standard peripherals of STM8L15x microcontrollers. It is written in strict ANSI-C code and is fully MISRA C 2004 compliant.
Refer to
Section 3.1: STM8L15x standard firmware library
and for details on the installation and configuration of this library
8/52 Doc ID 17891 Rev 2
UM0991
2
Installing the development toolchain
Installing the development toolchain
2.2
Note:
STVD software is available at http://www.st.com.
To install STVD, download the installation software and follow each step of the installation wizard.
When the installation is complete, the executable is available from
START>Programs>ST Toolset>Developement Tools>ST Visual Develop or under
C:\Program Files\STMicroelectronics\st_toolset\stvd.
Downloading and installing the compilers
●
●
●
Cosmic and Raisonance compilers are compatible with STVD. They are available together with their documentation at the following urls:
Cosmic: http://www.cosmicsoftware.com/download_stm8_16k.php
Cosmic: http://www.cosmicsoftware.com/download_stm8_32k.php
Raisonance: http://www.mcu-raisonance.com
Please note that the Cosmic 32K version does not include direct support from Cosmic.
A free license is required to use the compilers.
To install the Cosmic compiler, follow the sequence described below:
Doc ID 17891 Rev 2 9/52
Installing the development toolchain UM0991
1.
Step 1
Connect to http://www.cosmicsoftware.com/download_stm8_16k.php, or to http://www.cosmicsoftware.com/download_stm8_32k.php and fill in the information
).
Click Submit to access the download page.
Figure 2.
Cosmic compiler form
10/52 Doc ID 17891 Rev 2
UM0991 Installing the development toolchain
Download and run the installation software wizard (see
).
Figure 3.
Downloading Cosmic compiler software wizard
Follow the wizard instructions to install the Compiler (see
register for a free license and click Register by Email. You will receive the license file by e-mail. Note that the procedure is not done automatically, it may take a few hours or a few days (after the week-end), depending on your location and time zone, before you receive your license file.
Doc ID 17891 Rev 2 11/52
Installing the development toolchain
Figure 4.
Cosmic compiler installation wizard
UM0991
Copy the licence file that you have received into the corresponding directory \Program
files\COSMIC\CXSTM8_16K\License or \Program
files\COSMIC\CXSTM8_32K\License (see Figure 5
).
Figure 5.
Cosmic compiler
12/52 Doc ID 17891 Rev 2
UM0991 Installing the development toolchain
To install the Raisonance compiler, follow the sequence described below:
1.
Step 1
Download Ride7 and the Raisonance kit RKit-STM8 from http://www.mcuraisonance.com/microcontrollers-link-free-download.html, and follow the installation wizard instructions (see
Figure 6.
Raisonance compiler installation wizard
2. Step 2 - Register for a free 32 Kbyte license a) You need a computer serial number. To get it, open Ride, click Help>Licence, and enter your name, you company, and select Manual Activation. The computer serial key will appear as shown in
b) To get your free 32Kbyte activation code, go to http://www.mcu-
raisonance.com/stm8_registration.html (see Figure 7
). Fill the question form with
your personal information (see Figure 8
), and the registration form with your serial key (see
After this operation, you will receive your activation code by e-mail
Copy the activation code received by e-mail into installation window (see
you will be granted a free 32Kbyte Raisonance compiler licence to be used by STVD.
Doc ID 17891 Rev 2 13/52
Installing the development toolchain
Figure 7.
Activation code registration
UM0991
Figure 8.
Personal information form
14/52 Doc ID 17891 Rev 2
UM0991
Figure 9.
Serial key information form
Installing the development toolchain
STVD uses the default compiler defined at the first launch of the toolchain. This compiler is not defined during the installation.
You can select a different compiler for a specific project in the General tab of the STVD
Project>Settings window. Browse to the root path depending on the the compiler you want
Root pathes for compilers are :
● Cosmic 16K
C:\Program Files\COSMIC\CXSTM8_16K
● Cosmic 32K
C:\Program Files\COSMIC\CXSTM8_32K
● Raisonance 32K
C:\Program Files\Raisonance\Ride
Doc ID 17891 Rev 2 15/52
Installing the development toolchain
Figure 10.
Selecting the Cosmic compiler for the Discover project
UM0991
2.3
Note:
Downloading and Installing IAR Embedded Workbench
IAR Embedded Workbench for STM8 is available at http://www.iar.com in the Downloads tab. It integrates the IAR C Compiler and assembler.
To install IAR Embedded Workbench, follow the sequence described below:
1.
Step1
Download the installation software, either the 30-day evaluation edition or the 8 KBlimited Kickstart edition according to your requirements, from http://www.iar.com and follow the installation wizard instructions.
The procedure described here is for the 8 KB-limited Kickstart edition installation only.
2. Step1
Fill in the Product Registration and Download form (
Registration. An email asking you to confirm the registration is then sent to the address you have specified in the registration form. It might take some time before to receive the email, as the operation is manual.
16/52 Doc ID 17891 Rev 2
UM0991 Installing the development toolchain
Figure 11.
Product Registration and Download form
Open the mail and click the URL. A web page opens with the License Number and the
License Key. This page also give you information on how to download and install the product. (see
To download the product, click the Europe (HTTP site) URL. (see
Once IAR Embedded Workbench downloaded, the installation process starts automatically.
Doc ID 17891 Rev 2 17/52
Installing the development toolchain
Figure 12.
Download software
UM0991
18/52
Go through the installation steps and copy the License Number to the License# field
)
Doc ID 17891 Rev 2
UM0991
Figure 13.
Enter User Information
Installing the development toolchain
Enter your License Key in the License Key textbox (see
Click Next to finish the installation process.
Doc ID 17891 Rev 2 19/52
Installing the development toolchain
Figure 14.
Enter license key
UM0991
20/52 Doc ID 17891 Rev 2
UM0991
3 Description of firmware library
Description of firmware library
The STM8L15x microcontroller family is provided with the STM8L15x standard firmware library. It is strongly recommended to use the library to develop your project as proposed in the the STM8L-Discovery development package and implemented in the Discover project
(see Section 5.1: Description of the STM8L-DISCOVERY development package ).
The development package also contains the WavesGenerator project which don’t use the
STM8L standard firmware library except for the LCD driver.
The STM8L standard firmware library is part of the STM8L-DISCOVERY development package that is available from the STM8L-DISCOVERY web page at http://www.st.com/stm8l-discovery.
Warning: Make sure you have the latest version of the STM8L standard firmware library (see http://www.st.com/mcu).
3.1 STM8L15x standard firmware library
The STM8L15x standard firmware library contains a collection of routines, data structures, and macros covering the features of the STM8L15x peripherals, as well as a description of
the device drivers (see Figure 15 ).
The STM8L15x standard firmware library allows to develop an application on any
STM8L15x device without the need for in-depth study of each peripheral specifications. It saves significant time that would otherwise be spent in coding, while simultaneously reducing application development and integration cost.
It contains a set of examples for each peripheral. All these examples are provided with workspace and project definition files for STVD and C compilers and for IAR Embedded
Workbench for STM8 to allow loading and compiling them easily into you development environment. These examples are developed to run on an STM8L15x device with
STMicroelectronics STM8L1526-EVAL evaluation board.
They have to be considered as example codes to develop your own application. Some examples have already been tailored to run on the STM8L-DISCOVERY. They are available from the STM8L-DISCOVERY web pages at http://www.st.com/stm8l-discovery.
Doc ID 17891 Rev 2 21/52
Description of firmware library
Figure 15.
STM8L15x standard firmware library architecture main.c
stm8l15x.h
Application layer
Register definition
Memory mapping type definition stm8l15x_conf.h
Configures the library
UM0991 stm8l15x_adc.h
stm8l15x_exti.h
stm8l15x_iwdg.h
stm8l15x_beep.h
stm8l15x_flash.h
stm8l15x_lcd.h
stm8l15x_syscfg.h
stm8l15x_wfe.h
stm8l15x_tim1.h
stm8l15x_wwdg.h
stm8l15x_clk.h
stm8l15x_gpio.h
stm8l15x_pwr.h
stm8l15x_tim2.h
stm8l15x_comp.h
stm8l15x_i2c.h
stm8l15x_rst.h
stm8l15x_tim3.h
stm8l15x_dac.h
stm8l15x_irtim.h
stm8l15x_rtc.h
stm8l15x_tim4.h
stm8l15x_dma.h
stm8l15x_itc.h
stm8l15x_spi.h
stm8l15x_usart.h
STM8L152 resources
The stm8l15x.h header file contains the definitions of constants and register structures for all peripherals. Uncomment #define USE_STDPERIPH_DRIVER when using the
STM8L15x standard firmware library. It also includes common types definition used by the peripheral drivers. In addition, stm8l15x.h must be included in your main() routine.
The stm8l15x_conf.h file of the STM8L15x standard firmware library is used to configure the library by enabling the peripheral functions that are only used by your application (see
).
The peripheral interrupt function file, stm8l15x_it.c, must be modified to include the code to handle the interrupts used by your application.
Each peripheral driver is made up of the following files:
● The source code stm8l15x_<periph>.c containing all the software functions required to use the corresponding peripheral.
● The header stm8l15x_<periph>.h including the peripheral function prototypes as well as the variables, constant and structures used within these functions.
The flow that must be followed to create your application software using the STM8L15x standard firmware library is described in
Section 5.3: Creating your own project
.
22/52 Doc ID 17891 Rev 2
UM0991 Description of firmware library
Figure 16.
stm8l15x_conf.h peripheral define statements
3.1.2 STM8L15x standard firmware library online help
An online help, STM8L15x_stdperiph_lib_um.chm, is available inside the firmware
installation directory to help you with the structure of the library (see Figure 17
).
Figure 17.
STM8 firmware library online help home page
Doc ID 17891 Rev 2 23/52
Configuring the option bytes for your application
4 Configuring the option bytes for your application
UM0991
The option bytes allow to configure the device hardware features and memory protection.
They are stored in a dedicated memory block. Refer to the option bytes section of the
STM8L152x6 datasheet for a detailed description.
STVP can be used to program the STM8L option bytes. It is part of the free software package provided by STMicroelectronics. This easy-to-use tool has a graphical interface allowing to read, write and verify the STM8 Flash programming memory, data EEPROM and option bytes.
The STVP executable is available from the Windows start menu.
1.
Open the STVP GUI and select Configure>Configure ST Visual Programmer from the main menu toolbar. The configuration dialog box opens.
the ports that are compatible with the selected hardware are displayed.
depend on your programming equipment. program (see
).
Figure 18.
Select your MCU
24/52
STM8L152C6T6 option bytes and their respective values are displayed in the window
).
Doc ID 17891 Rev 2
UM0991 Configuring the option bytes for your application
Figure 19.
STVP option byte selection menu
7. To program an option byte to a new value: a) Click the option byte description, and select the value.
b) Click
c) If the operation has completed successfully, a confirmation message is displayed
in the Output window (see Figure 21
).
Doc ID 17891 Rev 2 25/52
Configuring the option bytes for your application
Figure 20.
STVP option byte programming menu
UM0991
Figure 21.
STVP option byte programming message
26/52 Doc ID 17891 Rev 2
UM0991
5
Building and running your project
Building and running your project
5.1 Description of the STM8L-DISCOVERY development package
ST provides a complete development package, the STM8L-Discovery_dev. It allows to easily get started with the STM8L-DISCOVERY by simplifying application code development and execution using the standard peripherals drivers. This package can be downloaded together with the present user manual from http://www.st.com/STM8L-discovery.
The package is structured as follow:
Figure 22.
STM8L-Discovery_dev package content
5.1.1 Libraries
The library is located in the Libraries directory.
● STM8L15x_StdPeriph_Driver
This directory contains the source and header files of the STM8L standard firmware library
Warning: It is strongly recommended to upgrade the library as soon as
new releases are available (see Section 5.4
Doc ID 17891 Rev 2 27/52
Building and running your project
5.1.2
UM0991
Application code examples
The application code examples are located in the Project directory:
● Discover
The Discover demonstration firmware comes preprogrammed in the STM8L-
DISCOVERY. This demo displays the STM8L152C6T6 Idd consumption on the STM8L-
Discovery LCD while the MCU is in Run or in low power saving modes. This example uses the STM8L15x standard firmware library. For more details on the Discover application code implementation and library configuration, refer to application note
AN3269 Discover STM8L15xx power saving modes using the built-in Idd measurement
feature of STM8L-Discovery. The Discover application project is compatible both with
Cosmic, Raisonance compilers and also with IAR Embedded Workbench.
●
●
WavesGenerator
This application transforms the STM8L-Discovery into a basic wave generator. This code has been optimized and use only the LCD driver of the library. Refer to application note AN3252 Building a wave generator using the STM8L-DISCOVERY for details on the WavesGenerator application software code implementation and library configuration.
The WavesGenerator project is compatible both with Cosmic and Raisonance compilers and also with IAR Embedded Workbench.
Project_template
This directory contains a standard project template that should be used to start any application software development.
Each project is structured as follows:
● inc
This directory contains all the header files for your application, including the configuration files for the standard firmware library (STM8L15x_conf.h). These files are used to tailor the library for your application.
● src
●
This directory contains all the source files dedicated to your application code, such as
main.c, stm8l15x_it.c, and stm8_interrupt_vector.c (interrupt mapping file used only for
Cosmic compiler).
STVD\Cosmic (or \Raisonance)
●
This directory is used to store STVD workspace files (for example discover.stw). It includes the project and workspace for the Cosmic or Raisonance compiler, depending on the compiler you have selected.
EWSTM8
This directory is used to store IAR Embedded Workbench workspace files (for example discover.eww). It also include the project file (for example discover.ewp).
28/52 Doc ID 17891 Rev 2
UM0991
5.2
Building and running your project
Running the STM8L-Discovery examples
Before starting developing your own application, run one of the examples provided with the development package to check if is is correctly configured. Take care to read the examplerelated documentation before proceeding because some examples may require additional hardware to work properly.
Follow the steps below:
1.
Install the development toolchain (see
Section 2: Installing the development toolchain
)
– Cosmic or Raisonance compiler
– STVD
2. Download the STM8L-Discovery_dev.zip file and extract the directory STM8L-
Discovery_dev on your PC (see
Section 5.1: Description of the STM8L-DISCOVERY development package
)
From START>Programs>ST Toolset>Development Tools>ST Visual Develop b) Browse for the project file .stw of the example you intend to run according to the compiler you have installed:
– Discover example: STM8L-
Discovery_dev\Project\Discover\STVD\Cosmic\Discover.stw or STM8L-
Discovery_dev\Project\Discover\STVD\Raisonance\Discover.stw
– WavesGenerator example: STM8L-
Discovery_dev\Project\WavesGenerator\STVD\Cosmic\WavesGenerator.stw or
STM8L-
Discovery_dev\Project\WavesGenerator\STVD\Raisonance\WavesGenerator.stw
4. Configures STVD to use ST-LINK as debug instrument (see
8. The application code example you have selected is now running. Check if it operates in compliance with what is described in the associated application note. You can also use
STVD debug capabilities to run the code step by step and monitor the variables (see
Section 6.2: Debugging your application
).
Doc ID 17891 Rev 2 29/52
Building and running your project
Figure 23.
Selecting the debug instrument
UM0991
5.2.2 With IAR Embedded Workbench
Follow the steps below:
1.
Install the development toolchain (see
Section 2: Installing the development toolchain
)
– IAR Embedded Workbench for STM8
2. Download the STM8L-Discovery_dev.zip file and extract the directory STM8L-
Discovery_dev on your PC (see
Section 5.1: Description of the STM8L-DISCOVERY development package
)
3. Run IAR Embedded Workbench
From START>Programs>IAR Systems>IAR Embedded Workbench for
STMicroelectronics STM8>IAR Embedded Workbench b) Browse for the project file .eww of the example you intend to run :
– Discover example: STM8L-
Discovery_dev\Project\Discover\EWSTM8\Discover.eww
– WavesGenerator example: STM8L-
Discovery_dev\Project\WavesGenerator\EWSTM8\WavesGenerator.eww
4.
Configures IAR to use ST-LINK as debug instrument (see Figure 23 ):
a) Right click your project name ??? then select Options.
30/52
8. The application code example you have selected is now running. Check if it operates in compliance with what is described in the associated application note. You can also use
Doc ID 17891 Rev 2
UM0991 Building and running your project
IAR debug capabilities to run the code step by step and monitor the variables (see IAR
Embedded Workbench help).
Figure 24.
Selecting the debug instrument
5.3 Creating your own project
This section explains step by step how to create your own application project using either
STVD or IAR Embedded Workbench environments. The firmware library can be used or not according to the kind of application code to develop.
All projects must be created starting from STM8L-Discovery_dev development package
(see Section 5.1: Description of the STM8L-DISCOVERY development package ).
Doc ID 17891 Rev 2 31/52
Building and running your project
5.3.1
UM0991
Creating your project structure
The best way to proceed is to start from the Project_template directory:
1.
Extract the content of STM8L-Discovery_dev.zip file on your PC.
the
Your STVD or IAR project comes already structured thus simplifying the project creation.
Figure 25.
Creating your project structure
5.3.2 Creating your STVD project
1.
Open STVD and click File>Open Workspace
2. Browse for the Workspace location and select STVD_workspace.stw in the Cosmic or Raisonance directory depending on the compiler you intend to use:
– For Cosmic, select \STM8L-
DISCOVERY_dev\Project\My_own_project\STVD\Cosmic\STVD_workspace.s
tw.
– for Raisonance, select \STM8L-
DISCOVERY_dev\Project\My_own_project\STVD\Raisonance\STVD_workspa
ce.stw.
stvd_project appears in the STVD workspace window as shown in Figure 26
. Its structure is slightly different from the structure of My_own_project directory in STM8L-
Discovery_dev package:
– User\src has the same content as \STM8L-
DISCOVERY_dev\Project\My_own_project\src.
– STM8L15x_StdPeriph_Driver\src contains the STM8L standard library source files.
– User\inc contains My_own_project include files.
– STM8L15x_StdPeriph_Driver\src contains the STM8L standard library include files.
32/52 Doc ID 17891 Rev 2
UM0991 Building and running your project
Figure 26.
Creating the STVD workspace for your project
3. Check that the compiler (STM8 Cosmic or Raisonance) and its path are correct by selecting Project>settings from the STVD main menu (see
).
Figure 27.
Checking the selected compiler list. Make sure that MCU selected is displayed in the selected MCU field before clicking
OK (see
).
Doc ID 17891 Rev 2 33/52
Building and running your project
Figure 28.
Select the MCU
UM0991
34/52 Doc ID 17891 Rev 2
UM0991 Building and running your project
5.
Configure STVD to use ST-LINK as debug instrument (see Figure 23
):
):
– Right click on the STM8L15x_StdPeriph_Driver\inc directory under stvd_project
– Select Add Files to Folder
– Browse the sm8l15x.h file location in \STM8L-
DISCOVERY_dev\Libraries\ STM8L15x_StdPeriph_Driver\inc.
sure is present of your main.c file.
Figure 29.
Copy stm8l15x.h to Include Files/FWLib
Doc ID 17891 Rev 2 35/52
Building and running your project UM0991
Note:
If no library linked to your STVD project
If your application does not require any library, follow the instructions below:
1.
Edit stm8l15x.h and comment #define USE_STDPERIPH_DRIVER to be able to use the register structures, memory mapping, and constant definitions for each peripheral.
For an example of application code that only partially uses the library, refer to the
WavesGenerator project in the STM8L-DISCOVERY development package.
Figure 30.
No library linked
Linking the STM8L15x standard firmware library to your STVD project
This section explains step by step how to link the STM8L standard firmware library to your
STVD project.
Prior to linking the library to your project, check that the STM8L library is up-to-date. If it is not, download the latest release (see
Section 5.4: Updating the libraries ).
Follow the steps described below to link the STM8L standard firmware library to your STVD project:
36/52 Doc ID 17891 Rev 2
UM0991 Building and running your project
1.
Edit stm8l15x.h and uncomment #define USE_STDPERIPH_DRIVER (see
).
Figure 31.
Linking the STM8L15x standard firmware library - step 1
DISCOVERY_dev to User\inc of your STVD project.
In stm8l15x_conf.h, uncomment the define statements corresponding to the peripherals used by your application.
The .c and .h files corresponding to the peripherals which define statement are uncommented must be copied from STM8L-
DISCOVERY_dev\Libraries\STM8L15x_StdPeriph_Driver\inc and STM8S-
DISCOVERY_dev\Libraries\STM8L15x_StdPeriph_Driver\src into
STM8L15x_StdPeriph_Driver\inc and STM8L15x_StdPeriph_Driver\src of STVD project, respectively.
You can also decide to copy the whole drivers (.c and .h files) from the library to your
STVD project.
Doc ID 17891 Rev 2 37/52
Building and running your project
Figure 32.
Linking the STM815x standard firmware library - step 2
UM0991
38/52 Doc ID 17891 Rev 2
UM0991 Building and running your project
your Embedded Workbench project
1.
Open IAR Embedded Workbench and click File>Open>Workspace
2. Browse for the Workspace location and select workspace.eww in the EWSTM8 directory :
– \STM8L-
DISCOVERY_dev\Project\My_own_project\EWSTM8\workspace.eww.
project - Debug appears in the workspace window as shown in
. Its structure is slightly different from the structure of My_own_project directory in STM8L-
Discovery_dev package:
– User\src has the same content as \STM8L-
DISCOVERY_dev\Project\My_own_project\src.
– User\inc contains My_own_project include files.
– STM8L15x_StdPeriph_Driver\src contains the STM8L standard library source files
– STM8L15x_StdPeriph_Driver\inc contains the STM8L standard library include files
Doc ID 17891 Rev 2 39/52
Building and running your project
Figure 33.
IAR Embedded Workbench workspace window
UM0991
3. Check that Additional Include Directories Paths are correct. This list is to point out your project and library include files. The argument variable $PROJ_DIR$ automatically point to the directory of the current project.
– right click on project - Debug in the workspace window
– select Options
– select Category C/C++ Compiler in the left window
– select the Preprocessor tab
– right andLibrary and User header files as well as their pathes are correct
Figure 34.
Checking the Additional Include Directories path
40/52 Doc ID 17891 Rev 2
UM0991 Building and running your project
4. Select the MCU to be used: right click on projects - Debug in the workspace window then select options and General Option as Category. Then browse the Device
STM8L152C6 from the STM8L list. Make sure that MCU selected is displayed in the
Device field before clicking OK (see Figure 35 ).
Figure 35.
Select the MCU
Doc ID 17891 Rev 2 41/52
Building and running your project
5.
Configure IAR to use ST-LINK as debug instrument (see Figure 23
):
UM0991
– Right click on the STM8L15x_StdPeriph_Driver/inc directory in the IAR workspace window.
– Select Add->Add Files
– Browse the sm8l15x.h file location in \STM8L-
DISCOVERY_dev\Libraries\ STM8L15x_StdPeriph_Driver\inc.
sure is present of your main.c file.
Figure 36.
Copy stm8s.h to Include Files/FWLib
42/52
If no library linked to your IAR project
If your application does not require any library, follow the instructions below:
Doc ID 17891 Rev 2
UM0991
Note:
Building and running your project
1.
Edit stm8l15x.h and comment #define USE_STDPERIPH_DRIVER to be able to use the register structures, memory mapping, and constant definitions for each peripheral.
For an example of application code that only partially uses the library, refer to the
WavesGenerator project in the STM8L-DISCOVERY development package.
Figure 37.
No libraries linked
Linking the STM8L standard firmware library to your IAR project
This section explains step by step how to link the STM8L standard firmware library to your
IAR project.
Prior to linking the library to your project, check that the STM8L library is up-to-date. If it is not, download the latest release (see
Section 5.4: Updating the libraries ).
Follow the steps described below to link the STM8L standard firmware library to your IAR project:
1.
Edit stm8l15x.h and uncomment #define USE_STDPERIPH_DRIVER (see
).
Figure 38.
Linking the STM8L standard firmware library - step 1
Doc ID 17891 Rev 2 43/52
Building and running your project UM0991
DISCOVERY_dev to User\inc of your IAR project.
In stm8l15x_conf.h, uncomment the define statements corresponding to the peripherals used by your application.
The .c and .h files corresponding to the peripherals for which the define statements are uncommented must be copied from STM8L-
DISCOVERY_dev\Libraries\STM8L15x_StdPeriph_Driver\inc and STM8L-
DISCOVERY_dev\Libraries\STM8L15x_StdPeriph_Driver\src into
STM8L15x_StdPeriph_Driver\inc and STM8L15x_StdPeriph_Driver\src of IAR project, respectively.
You can also decide to copy the whole set of drivers (.c and .h files) from the library to your STVD project.
Figure 39.
Linking the STM8L standard firmware library - step 2
44/52 Doc ID 17891 Rev 2
UM0991
5.4 Updating the libraries
Building and running your project
To update the STM8L15x standard firmware library:
1.
Download the new release from http://www.st.com/mcu.
DISCOVERY_dev”\Libraries\STM8L15x_StdPeriph_Driver.
Doc ID 17891 Rev 2 45/52
Building, debugging and running your application with STVD UM0991
Note:
with STVD
Once your have developed your application code, created your workspace environment, and launched STVD, you can start building, debugging and programming your application for the target microcontroller.
This section refers to STVD, if you are using IAR Embedded Workbench, please refer to the
IAR Getting Started documentation.
6.1 Building application
Once your project is created, the build context is enabled by default. It allows to access all the commands required to set up, customize, and build your application.
The build configuration is available by selecting Build>Configurations from the STVP main menu toolbar. It allows you to change the application building settings.
Two preset configurations are available in STVD:
● Debug
This configuration creates a version of your application that allows using all the STVD advanced debugging features. When using this configuration, output files are saved in the Debug directory in your workspace directory.
● Release
This configuration creates a version of your application that uses the default optimization for your toolset. This version of your application is ready to be programmed to your target microcontroller.
Follow the sequence below to build a project:
1.
Ensure that the Debug configuration is selected by clicking Build>Configurations. If the Debug configuration is not selected, highlight it and click Set Active (see
).
Figure 40.
Selecting the project configuration
46/52 Doc ID 17891 Rev 2
UM0991 Building, debugging and running your application with STVD
2. Once the build options are correctly configured, configure your project settings: compiler, assembler, and linker. You can then customize these options. For more information on the available options for your toolset, refers to the STVD online help available by clicking Help in the STVD main menu toolbar.
3. Once your MCU is selected (Project > Settings > MCU Selection) and your building options are configured, use the Build menu to build and rebuild your application, or compile your source files (see
).
4. The build command lines and possible warnings and/or errors are displayed in the
build tab of the Output window (see
).
Figure 41.
Building your project
Figure 42.
Building successful message
Doc ID 17891 Rev 2 47/52
Building, debugging and running your application with STVD UM0991
Once your application has been successfully built, access the Debug context from the
STVD main menu to access the debugging features that are supported by your debugging instrument. The debug instrument must be selected before starting debugging.
1.
Select Debug Instrument > Target settings from the STVD main menu toolbar.
2. Select
context. STVD then connects to your debug instrument, loads the code into the microcontroller Flash memory, and provides access to the debug commands and
menus. You can now start debugging your application (see Figure 43 ).
Figure 43.
Debugging your application
48/52
Several debug windows are available in STVD. You can access them by selecting View
menu when a debug session is ongoing.
One of the most useful windows is the Peripheral registers window. It can be used to display the content of the STM8L105C6 peripheral registers during the debug session. (see
).
The Watch window displays the values the code variables. Just drag and drop a variable from your code into the Watch window.
The information displayed in the debug windows are refreshed when the program is stopped
(for example by a break point). (see
Doc ID 17891 Rev 2
UM0991 Building, debugging and running your application with STVD
Figure 44.
Peripheral registers window
Figure 45.
Watch window
For more information on building and debugging features, refer to embedded STVD online help page (Help>Help Home Page).
Doc ID 17891 Rev 2 49/52
Building, debugging and running your application with STVD
Figure 46.
STVD online help
UM0991
50/52 Doc ID 17891 Rev 2
UM0991 Revision history
Table 1.
Date
Document revision history
14-Sep-2010
07-Mar-2011
Revision
1
2
Changes
Initial release.
Updated STVD software downloading address to http://www.st.com
under Section 2.1: Downloading and installing STVD .
Doc ID 17891 Rev 2 51/52
UM0991
Please Read Carefully:
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED
WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS
OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT
RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING
APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY,
DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE
GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.
© 2011 STMicroelectronics - All rights reserved
STMicroelectronics group of companies
Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan -
Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com
52/52 Doc ID 17891 Rev 2
Scarica
Pubblicità