cd00194637 Getting Started With stm8s and Stm8af Microcontrollers Stmicroelectronics
cd00194637 Getting Started With stm8s and Stm8af Microcontrollers Stmicroelectronics
Application note
Getting started with STM8S and STM8AF microcontrollers
Introduction
This application note complements the information contained in STM8S and STM8AF
datasheets by describing the minimum hardware and software environment required to build
an application around these 8-bit microcontrollers.
This document also contains detailed reference design schematics with descriptions of the
main components, and some hardware recommendations.
Some of the information given in Section 9: Software toolchain and Section 10: Setting up
the development environment has a wider scope, to know if it applies to STM8 MCUs
different from those of the STM8S and STM8AF Series contact your local representative.
Contents
2 Power supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 Power supply overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Main operating voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 Power-on/power-down reset (POR/PDR) . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Clock management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.1 Clock management overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2 Internal clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 External clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5 Reset control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.1 Reset management overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6 Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.1 Printed circuit board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.2 Component position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.3 Ground and power supply (VSS, VDD) . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.4 Decoupling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.5 Other signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.6 Unused I/Os and features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.7 User options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
7 Reference design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
7.1 Components reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
7.2 Schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
8 Development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
9 Software toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
9.1 Integrated development environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
9.2 Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
9.3 Firmware library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
12 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
List of tables
List of figures
2 Power supply
VDDA
Analog
signal Analog functions
VSSA
VCAP
VDD/VDDIO1
Logic
VDDIO2
IOs
VSSIO2 VDDIO VSSIO
OSCIN
VDDIO VSSIO
XTAL
OSCOUT
Star connected ai15330
Note: The capacitors must be connected as close as possible to the device supplies (especially
VDD in case of dedicated ground plane).
Placing a crystal/resonator on OSCIN/OSCOUT is optional. The resonator must be
connected as close as possible to the OSCIN and OSCOUT pins. The loading capacitance
ground must be connected as close as possible to VSS.
ESR C ESL
Where:
ESR is the equivalent series resistance Rleak
ESL is the equivalent inductance
Recommendations
All pins need to be properly connected to the power supplies. It is important to have the
lowest possible impedance for these connections, including pads, tracks and vias. This is
typically achieved with thick track widths and dedicated power supply planes in multi-layer
printed circuit boards (PCBs).
In addition, each power supply pair has to be decoupled with 100 nF filtering ceramic
capacitors (C) with one chemical capacitor (1 to 2 µF) in parallel on the STM8S or STM8AF
device. The ceramic capacitors (including CEXT capacitor between VCAP and VSS pins)
need to be placed as close as possible or below the appropriate pins, on the opposite side
of the PCB. Typical values are 10 nF to 100 nF, but exact values depend on the application
needs. Figure 3 shows the typical layout of the VDD/VSS and VCAP/VSS pairs.
&
&(;7
YLDWR9'' YLDWR966
0&8
069
VIN_EXT REXT
CEXT CSAMP
Equation 1:
C VIN = C SAMP + C EXT
where:
• CVIN is the total equivalent capacitor on the path of VIN
• CSAMP is the equivalent sampling capacitance
• CEXT is the total external capacitance on the path of VIN to the macro pin. This includes
parasitic routing capacitance, pad and pin capacitance and external capacitance. To
ensure proper and accurate sampling the following equation must be satisfied
Equation 2:
3
( R SW + R EXT ) × ( C SAMP + C EXT ) < ⎛ ------⎞ × T S
⎝ 10⎠
where:
• RSW = 30 kΩ
• REXT is the total external resistance on the path of VIN
• CSAMP = 3 pF
• TS = 0.5 µs (for 2 MHz input CLK)
Equation 2 is specific for REXT and CEXT when designing an analog input interface for the
ADC.
Refer to the STM8S or STM8AF datasheets and/or to reference manual RM0016 (available
on www.st.com) for more details.
4 Clock management
OSCIN
16 MHz/128 kHz
Prescaler WDG/AWU
internal RC
Timer
For more details refer to the section on clock management in the datasheet
STM8
OSCIN OSCOUT
External clock
(I/O available)
External source
STM8
OSCIN OSCOUT
Crystal/ceramic resonators
Q1
CL1 CL2
Load capacitors
The values of the load capacitors CL1 and CL2 are heavily dependent on the crystal type and
frequency. The user can refer to the datasheet of the crystal manufacturer to select the
capacitances. For best oscillation stability CL1 and CL2 normally have the same value.
Typical values are in the range from below 20 pF up to 40 pF (Cload: 10 to 20 pF). The
parasitic capacitance of the board layout also needs to be considered and typically adds a
few pF to the component values.
Recommendations
In the PCB layout all connections have to be as short as possible. Keep any additional
signals, especially those that could interfere with the oscillator, locally separated from the
PCB area around the oscillation circuit using suitable shielding.
5 Reset control
VDD_IO
RPU
External reset
Output characteristics
• A valid pulse on the pin is guaranteed with a pulse whose duration is higher than 20 ns
on the internal output buffer.
• After a valid pulse is recognized, a pulse of at least 20 µs is guaranteed on the pin,
starting from the falling edge of A.
Pad
Reset requested
Input characteristics
• All pulses with a duration lower than 75 ns are filtered
• All train/burst spikes with a ratio of 1/10 must be filtered. This means that a negative
spike of up to 75 ns is always filtered, when a 7.5 ns interval between spikes occurs
(ratio 1/10).
• All pulses with duration longer than 450 ns are recognized as valid
• After a valid pulse is recognized, an internal pulse of at least 30 ns is guaranteed
>7.5 ns >7.5 ns
450 ns
Pad
<75 ns <75 ns <75 ns
>30 ns
System reset
Negative train of glitch filtered Reset requested
6 Recommendations
6.4 Decoupling
The standard decoupler for the external power is a 100 µF pool capacitor. Supplementary
100 nF capacitors must be placed as close as possible to the VSS/VDD pins to reduce the
area of the current loop.
As a general rule, decoupling all sensitive or noisy signals improves electromagnetic
compatibility (EMC) performance.
There are two types of decouplers:
• Capacitors close to components. Inductive characteristics, which apply to all capacitors
beyond a certain frequency, must be taken into account. If possible, use parallel
capacitors with decreasing values (0.1, 0.01, ... µF).
• Inductors. Although often ignored, ferrite beads, for example, are excellent inductors
due to their good dissipation of EMI energy and there is no loss of DC voltage (which is
not the case when simple resistors are used).
7 Reference design
7.2 Schematics
Figure 10. Reference design
& 3$
3$26&287 3(,&B6'$
S)
Q) 3$7,0B&+>7,0B&+@ 3(7,0B%.,1
0+]
;
& 3$8$57B5; 3(
3$8$57B7; 3(63,B166
&
3$8$57B&. 3($,1
9&$3
9&$3 3($,1
&
S)
) 3%$,1>7,0B&+1@ 3)$,1
&ORFN +6( 3) 5
3%$,1>7,0B&+1@ 3)95()
5HVHW 3) 5
3%$,1>7,0B&+1@ 3)95()
3%$,1>7,0B(75@ 3)$,1
3%$,1>,&B6&/@ 3)$,1
6$$
3%$,1>,&B6'$@ 3)$,1
3%$,1 3)$,1
3%$,1 3)$,1
3&$'&B(75 3*&$1B7;
3&7,0B&+ 3*&$1B5;
3&7,0B&+ 3*
3&7,0B&+ 3*
3&7,0B&+ 3*
3&63,B6&. 3*
3&63,B026, 3*
&1
3&63,B0, 62 3*
3'7,0B&+>7,0B%.,1@
>&/.B&&2@ 3+
3'6:,0 3+
3'7,0B&+>7,0B&+@ 3+
3'7,0B&+>$'&B(75@ 3+
6: ,0 FRQQHFWRU
3'7,0B&+>%((3@ 3+7, 0B(75
'HEXJ
3'8$57B7; 3+7,0B&+1
6$$
3'8$57B5; 3+7,0B&+1
3'7/ ,>7,0B&+@ 3+7,0B&+1
6$$
9'',2B 3,
6$$
9'',2B 3,
9'' 3,
9''$ 3,
& & & & & 966 3,
Q) Q) Q) Q) ) 966$ 3,
966,2B 3,
966,2B 3,
0&8
'HFRXSOLQJ &DSDFLW RU
; = ALTERNATE FUNCTION REMAPPING OPTION )F THE SAME ALTERNATE FUNCTION IS SHOWN TWICE IT INDICATES AN EXCLUSIVE CHOICE NOT A
DUPLICATION OF THE FUNCTION BJD
8 Development tools
Development tools for STM8S and STM8AF microcontrollers include the STice emulation
system supported by a complete software tool package including C compiler, assembler and
integrated development environment with high-level language debugger.
NVM
Internal RC
Pin 1 VDD
Pin 2 SWIM pin
Pin 3 VSS
Pin 4 Reset
VDD 1 1 VDD
2 2
STM8
3 3
4 4
SWIM cable
Caution: It is recommended to place the SWIM header as close as possible to the STM8S or
STM8AF device, as this minimizes any possible signal degradation caused by long PCB
tracks.
Emulation system
Connection flex
Connection adapter
Adapter socket
Connection flex
• 60-pin or 120-pin cable for connection to the application board
Connection adapter
• Links the connection flex to the footprint of the STM8S or STM8AF microcontroller
Adapter socket
• Package-specific socket for connection adapter and STM8S or STM8AF
microcontroller
Free ST/STM8 toolset: STVD and STVP running on your PCdrive STice
SWIM connector
(SWIM protocol linked to microcontroller
for STM8, or ICC protocol
for ST)
ST microcontroller on
application board
9 Software toolchain
To write, compile and run the first software on an STM8S or STM8AF device, the following
components of the software toolchain are required (see Figure 16):
• Integrated development environment
• Compiler
• Firmware library (optional, used to ease the start-up)
9.2 Compiler
STM8S and STM8AF devices can be programmed by a free assembler toolchain which is
included in the ST toolset.
As the core is designed for optimized high-level-language support, the use of a C compiler
is strongly recommended.
C compilers for STM8 are offered by the third party companies Cosmic and Raisonance.
A free version of the C compiler with up to 16 Kbytes of generated code is available at
www.cosmic-software.com and www.raisonance.com.
The development environment for STM8S and STM8AF microcontroller setup looks
different, depending upon the supplier of the software (SW) and upon the hardware (HW)
tools.
Typical setups are described below for the following SW and HW tools:
• STM8 C compiler from Cosmic
• ST toolset and STM8 firmware library from STMicroelectronics
• HW debug interface “Rlink” from Raisonance
• STM8 evaluation board from STMicroelectronics
Figure 23. Connecting the debug instrument to the STM8 evaluation board
Rlink adapter
for STM8
5 V power supply
Caution: On the Rlink ICC/SWIM adapter board, the “SWIM” jumper must be set.
If there is no pull-up on the application SWIM line, the “ADAPT” jumper is also set.
In any case, “PW-5V” and “12MHz” jumpers must not be set.
The LCD display on the STM8 evaluation board indicates a successful debug session (see
Figure 26).
10.3.6 Follow up
Step by step, additional peripherals of STM8S and STM8AFdevices can be run, following on
from the initial debug session described above.
Many features of STM8S and STM8AFdevices are supported by dedicated hardware on the
STM8 evaluation board. The necessary software drivers (CAN driver, LIN driver, buttons,
memory cards, buzzer, etc) are delivered in the STM8 firmware library.
Application
• STM8S datasheets:
– STM8S207xx STM8S208xx
– STM8S105xx
– STM8S103K3 STM8S103F3 STM8S103F2
– STM8S903K3 STM8S903F3
– STM8S003K3 STM8S003F3
• STM8AFdatasheets:
– STM8AF52xx STM8AF6269/8x/Ax STM8AF51xx STM8AF6169/7x/8x/9x/Ax
– STM8AF622x/4x STM8AF6266/68 STM8AF612x/4x STM8AF6166/68
• How to program STM8S and STM8AF Flash program memory and data EEPROM
(PM0051)
• STM8S and STM8AF microcontroller families reference manual (RM0016)
• STM8 CPU programming manual (PM0044)
Tools
• STM8 firmware library and release note (detailed descriptions of the library are
included as help files)
• STice advanced emulation system for ST microcontrollers data briefing
• STice user manual
• Cosmic C compiler user manual
• STM8/128-EVAL evaluation board user manual (UM0482)
• ST visual develop tutorial (included as help files in the ST-toolchain)
• ST visual develop (STVD) user manual
• STM8 SWIM communication protocol and debug module user manual (UM0470)
The microcontroller discussion forum on www.st.com can be used by developers to
exchange ideas. It is the best place to find different application ideas. In addition, the
website has a knowledge base of FAQs for microcontrollers, which provide answers to
many queries and solutions to many problems.
12 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.