Home

Getting started with the STM8S and STM8A

image

Contents

1. m External Dependenci Binterrupt Bnostack void trapISR ic st asm EK color nextState Further interrupts are maski Determine next state case RED nevr rarezbFFN S ime WATCHDOG SOFTWARE WDG_HALT RESET gt Run Application stopped Breakpoint 1 trapISR at timer c 69 gem sem AM M ode w sa timer c olx Further i Determine nex case RED nextState GREEN break case OFF nextState OFF break default nextState currentStateci break Go to next state and update traced var if state nextState stateOccurence lt MAX currentState nextState state currentState stateOccurence 4 Doc ID 14651 Rev 5 25 40 www BDTIC com ST STM8 software toolchain AN2752 9 1 9 2 26 40 Integrated development environment The integrated development environment ST visual develop STVD provides an easy to use efficient environment for start to finish control of application development from building and debugging the application code to programming the microcontroller STVD is delivered as part of the free ST toolset which also includes the ST visual programmer STVP programming interface and the ST assembler linker To build applications STVD provides seamless integration of C and assembly tool chains for ST including the Cosmic and Raisonance C compilers and the ST assembler linker When debug
2. Doc ID 14651 Rev 5 31 40 www BDTIC com ST Setting up the STM8 development environment AN2752 10 3 10 3 1 32 40 Running the demonstration software To run the demonstration software on the STM8 evaluation board the project has to be compiled and the correct HW tool must be selected before the debug session can be started Compiling the project The project can be compiled using the Build function in the Build menu see Figure 21 Figure 24 STVD Building the project 1 ST Visual Develop project stw main c C File Edit View Project Build Debug Debug instrument Tools Window Compile main c Ctrl F7 haa Build F7 Workspace Rebuild All ies project stw z a P Batch Build Tidg44 project ds Source Files Clean E Include Files pr n External Depen faut i i Uver Configurations r adat 8 tttttt 9 in t THE Doc ID 14651 Rev 5 ST www BDTIC com ST AN2752 Setting up the STM8 development environment 10 3 2 Selecting the correct debug instrument In the example below the Rlink tool is used for communicating via the SWIM interface with the on board debug module of the STM8 The Rlink tool can be selected from the Debug Instrument Selection list in the Debug Instrument Settings dialog see Figure 22 Figure 22 STVD Selecting the debug instrument Debug Instrument Settings Target Debug Instrument Se
3. 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 TWO AUTHORIZED ST REPRESENTATIVES 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
4. e Connection flex Flexible cable 60 pin or 120 pin depending on the target microcontroller that relays signals from the STice to the application board e Connection adapter Links the connection flex to the footprint of the target microcontroller on the users application board e Adapter socket Socket that solders to the application board in place of the microcontroller and receives the connection adapter The above accessories are not included with the STice system To determine exactly what is required for any supported microcontroller refer to the online product selector on www st com Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 STM8 development tools Figure 14 STice in emulation configuration Free ST STM8 toolset STVD and STVP running on your PCdrive STice LM _ STice SYSxxx Includes all emulation resources MEB TEB and PEB if l lt CF FPxxx Connection flex to connect to application board l 12 2 5 a L d ON M N ff A LO AS xxxx Adapter socket on application NS LT e Pd board to plug in emulator in place of Jr ADixxxx Connection M microcontroller l adapter to link connection P cable to microcontroller KRZY 8 2 3 In circuit programming and debugging In the in circuit debugging programming configuration STice allows the application to be programmed in the microcontroller and for the application to be debugged while it runs on the microcontroller on the app
5. v AN2752 Sf Application note Getting started with the STM8S and STM8A Introduction This application note complements the information in the STM8S and STMB8A datasheets by describing the minimum hardware and software environment required to build an application around an STM8S and STMB8A 8 bit microcontroller device It is divided into the following sections Power supply Analog to digital converter ADC Clock management Reset control and development Debugging tool support STMB8 software toolchain Setting up the STM8 development environment This application note also contains detailed reference design schematics with descriptions of the main components In addition some hardware recommendations are given August 2011 Doc ID 14651 Rev 5 1 40 www st com www BDTIC com ST Contents AN2752 Contents 1 Hardware requirements summary eese 6 2 Power supply i i unn tebe Parse RR ER ouam E OR RR AC Ress 7 2 1 Power supply overview 0000 nne 7 2 2 Main operating voltages 2 0 eee ss 8 2 3 Power on power down reset POR PDR 000 eee eee 8 3 Analog to digital converter ADC 200 cee eee eee eee 10 3 1 Analog power 25 saxi ues aca ra Aenean os eae cate eran Br ion a dis Be 10 3 2 Analog Input sese e RAE RRRERR ERA U RR RAGUC RE E AUR ROCK ed 10 4 Clock management eeseeeeeeeeeeeeeeee 12 4 1 Clock management overview lli
6. 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 40 40 Doc ID 14651 Rev 5 ky www BDTIC com ST
7. N STM8 wo A SWIM cable It is recommended to place the SWIM header as close as possible to the STM8S or STM8A device as this minimizes any possible signal degradation caused by long PCB tracks Emulator STice STice overview The STice is a modular high end emulator system which connects to the PC via a USB interface and to the application board in place of the target microcontroller It is supported by the free STM8 toolset IDE ST visual develop STVD programmer ST visual programmer STVP and STM8 assembler Please refer to the STice emulator for STMB8 for more details Figure 13 Connection description Emulation system Connection flex Connection adapter Adapter socket Doc ID 14651 Rev 5 21 40 www BDTIC com ST STM8 development tools AN2752 8 2 2 22 40 Emulation system STice e Emulator box e Cables for USB power supply trigger analyzer input Connection flex e 60 pin or 120 pin cable for connection to the application board Connection adapter e Links the connection flex to the footprint of the STM8S or STM8A microcontroller Adapter socket e Package specific socket for connection adapter and STM8S or STM8A microcontroller STice in emulation configuration In emulation configuration the STice is connected to the PC via a USB interface and to the application board in place of the target microcontroller being used
8. STVD MCU edit mode sssssssseeseeee err 30 STM8 firmware library online help manual 0 000 eee eee 31 STVD Building the project 0 0 cee eae 32 STVD Selecting the debug instrument liliis 33 Connecting the debug instrument to the STM8 evaluation board 055 34 STVD Starting the debug session 0 0000 cece tetas 35 STVD Run the software 36 STM8B evaluation board 0 rne 37 Doc ID 14651 Rev 5 5 40 www BDTIC com ST Hardware requirements summary AN2752 6 40 Hardware requirements summary In order to build an application around an STM8S or STMB8A device the application board should at least provide the following features Power supply Clock management Reset management Debugging tool support Single wire interface module SWIM connector Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Power supply 2 Power supply 2 1 Power supply overview The device can be supplied through a 3 0 V to 5 5 V external source An on chip power management system provides the 1 8 V digital supply to the core logic both in normal and low power modes It is also capable of detecting voltage drops on both main external 3 3 V 5 V and internal 1 8 V supplies The device provides e One pair of pads Vpp Vss 3 3 V x 0 3 V to 5 V 0 5 V dedicated to the main regulator ballast transistor supply e Two pairs of pads dedicated for Vpp jo V
9. on low voltage input as follows Vpgrr input analog reference positive The higher positive reference voltage for the ADC should be between 250 mV VppA For more details about Var values please refer to the STM8S or STM8A datasheets This input is bonded to VppA in devices that have no external Vpgef pin packages with 48 pins or less Vper input analog reference negative The lower negative reference voltage for the ADC should be higher than VssA For more details about Vref values please refer to the STM8S or STMBA datasheets This input is bonded to Vas in devices that have no external Vngr pin packages with 48 pins or less Analog input STM8S and STM 8A devices have 16 analog input channels which are converted by the ADC one at a time and each multiplexed with an I O The analog input interface of the ADC is shown in Figure 4 Figure 4 A Analog input interface Outside ADC nside ADC Vin SWsamp VIN_EXT Rext a L OCEgyr CsAMP Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Analog to digital converter ADC Equation 1 Cyin Cgamp Cext where e Cyn is the total equivalent capacitor on the path of Vin Caayp is the equivalent sampling capacitance Ceyxr is the total external capacitance on the path of Vix to the macro pin This includes parasitic routing capacitance pad and pin capacitance and external capacitance To ens
10. programming mode are managed through a single wire hardware interface based on an open drain line featuring ultra fast memory programming Coupled with an in circuit debugging module the SWIM also offers a non intrusive read write to RAM and peripherals This makes the in circuit debugger extremely powerful and close in performance to a full featured emulator The SWIM pin can be used as a standard I O with 8 mA capability which has some restrictions if the user wants to use it for debugging The most secure way to use it is to provide a strap option on the PCB Please refer to the STM8 SWIM communication protocol and debug module user manual UM0470 for more SWIM protocol details Figure 11 Debug system block diagram 100 kHz Osc v Peripheral SWIM entry DBG Comm cmp gt DM STM8 RAM layer decode pore A NVM Internal RC 8 1 2 SWIM connector pins The SWIM connector pins consist of 4 pins as described in Table 2 Table 2 SWIM connector pins Pin number Pin name Pin 1 Vpp Pin 2 SWIM pin Pin 3 Vss Pin 4 Reset 20 40 Doc ID 14651 Rev 5 Ar www BDTIC com ST AN2752 STM8 development tools 8 1 3 Caution 8 2 8 2 1 Hardware connection Figure 12 Hardware connection AD ICC SWIM adapter Application board SWIM connector Vpp 4 1 lt Voo 2 3 4
11. stm8 clk c 2 stm8_exti c P Step Into Fil stm8_flash TP step Over F10 stm8 gpio c a stm8 c c Ph Step Into ASM AIF LL stmB jtc c O Step Over ASM At F10 fypeDef GPIO Ini gt Disassembly stm amp iwdg P Step Out curii R5Def SPI cmies main c stmB linuarl 4 Run to Cursor Ctrl4F10 Ox8902 lt Delay 10 gt 0x85 POPU X stmB rst c Dx8903 lt Delay 11 gt 0x81 RET stm8 spic Bj Set PC bus main c 47 void main void stmB timL c Dx8904 main 0x5204 SUBU SP 0x0a stm8 tim2 c GPIO InitStructure GPIO Pi main c 56 GPIO InitStructure GPIO Mode GPIO MODE OUT PP LOW FA stm8 tim3 c A GPIO Init LEDS PORT amp GPIO 2 stm8_tim4 c f O0x8908 lt main 4 gt Ox6B02 LD 0x02 S9P A B stme_usart a Initialize SPI for cop B main c 57 GPIO InitStructure GPIO Pin LED1 PIN LED2 PIN LI A stma md 3 Ox890a lt main 6 gt OxA6OF LD A 0x0f 0x890c lt main 8 gt Ox6BO1 LD OxO1 SP s B WS Workspace mono lcd c mono lcd h Program Counter Stacks Index registers Pc OEA sP 0x17f3 x 0x100 v 0x89cc id Accumulator m Condition Flags A 0x00 cc Ox2a T OEA HEMET Nivel Concurrent IT Nested IT Core Registers 36 40 Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Setting up the STM8 development environment 10 3 6 The LCD display on the STM8 evaluation board indicates a successful debug session see Figure 26 Figure 26 STM8
12. to load and compile them easily into the development environment The examples run on the STMicroelectronics STM8 evaluation board and can be tailored easily to other types of hardware For additional information on the STM8 firmware library please contact STMicroelectronics Figure 17 STM8 firmware library examples Q0 STM8520x Firmware Library and Examples E Usage B Known Bugs and Limitations B Peripheral drivers footprint ADC Examples 2 AWU Examples 1 x BEEP Examples 1 e CLK Examples 4 EXT Examples 1 e FLASH Examples 4 e GPIO Examples 2 e I2C Examples 5 e ITC Examples 1 e IWDG Examples 1 x LINUART Examples 4 e RST Examples 2 e SPI Examples 3 x TIMER Examples 5 x TIMER2 Examples 5 x TIMER3 Examples 5 x TIMER4 Examples 1 USART Examples 3 wwDG Examples 1 Q Modules oO Data Structures E Data Fields File List Directories Globals Doc ID 14651 Rev 5 27 40 www BDTIC com ST Setting up the STM8 development environment AN2752 10 10 1 Note 28 40 Setting up the STM8 development environment The STM8 development environment setup looks different depending on the supplier of the software SW and hardware HW tools Typical setups are described below for the following SW and HW tools e STM8C compiler from Cosmic e ST toolset and STM8 firmware library from STMicroelectron
13. A datasheets Removed Section 5 2 Hardware reset implantation Table 1 Component list updated Reference value for ID 6 Removed Section 7 3 Pinouts Updated references in Section 11 Documentation and online support Doc ID 14651 Rev 5 39 40 www BDTIC com ST AN2752 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
14. EREIN IN CONNECTION WITH THEIR PRO COPYRIGHT 200 STMicroelectronics center h2 Includes include stm8_lib h include mono lcd h stp interrupt vector c v onfiguration Ei g Include Files define LEDS PORT GPIOH T B mono kh define LED1 PIN GPIO PIN 3 G3 brary i define LED2 PIN GPIO_PIN_2 stm8 conf h define LED3 PIN GPIO PIN 1 Sich define LED4 PIN GPIO PIN D External Dependencies gt El modst h Private function prototypes lii El ST T To Build f Tools FindinFiles1 FindinFies2 A Debug Console For Help press F1 Ln amp Col 19 MODIFIED READ CAP 30 40 Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Setting up the STM8 development environment 10 2 2 Online help An online help manual is available inside the firmware installation directory see Figure 20 to help the user understand the structure of the STM8 firmware library Figure 20 STM6 firmware library online help manual amp HTML Help gm s gt 0 A amp e Hide Locate Back Forward Stop Refresh Home Pint Options Contents Ind Search Favorit n E ides Search Favorites Main Page Modules Data Structures Files Directories E STM Firmware Library cS Modules E decia STM8 Firmware Library and Examples E Data Fields E File List E Dien On line Help Manual E Globals STMicroelectronics ky
15. N TX PCA TIM1 CH1 PGICAN X joer PC2 IIM1 CH2 PG2 a PC3 TIM1 CH3 PG3 jigs PC4 TIM1_CH4 PCA G3 PC5 PI_SK PGS eey PC6 PI_MOS PGS e 7 PC7 PI_MI SO PG7 3 PDO TMIM3_CHTIM1_BKINELKC PHO 12 2 PD1 SWM PHI x 1 yg PD2 TIM3_CH1 TIM2_CH3 PH2 eie SWIM connector TU BU HIR Uo E 7g PD4 MM2_CH1 BEF PHAMMI ER H5 Debug L jg PDSIUART3 TX PHSITIMT CH3N 37 go PDG UART3 FK PH6 TIM1 CH2N 535 PD7 TLI TIM1_CH4 PH7 TIM1_CH1N VDD 2 8 57 VDDD 1 PIO f VDD 2 ES VDDIO 2 PH 337 VOD PI2 25 5 VDDA PI3 eer C5 C5 c co zy VS PI4 365 100rF 100rF 100rF 100F 1 4 Un de 1 48 72 VSSO 2 PI7 f MCU Decoupling Capactor alternate function remapping option If the same alternate function is shown twice it indicates an exclusive choice not a duplication of the function ai15471c 1 If pins 22 or 25 are required as GPIO R1 and R2 should be removed 2 Vpp must be within the allowed supply voltage range of the STM8S or STM8A microcontroller ky Doc ID 14651 Rev 5 19 40 www BDTIC com ST STM8 development tools AN2752 8 STM8 development tools Development tools for STM8S and STM8A 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 8 1 Single wire interface module SWIM 8 1 1 SWIM overview In circuit debugging mode or in circuit
16. UM0482 e ST visual develop tutorial included as help files in the ST toolchain e ST visual develop STVD user manual e 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 38 40 Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Revision history 12 Revision history Table 3 Document revision history Date Revision Changes 03 Jun 2008 1 Initial release STMB8S207 208 replaced by STM8S20xxx Figure 10 Reference design on page 19 and Figure 12 LQFP 80 01 Sep 2008 2 pin pinout on page 21 modified to be in line with the pin description of the STM8S20xxx datasheet Figure 7 Reset management on page 14 modified 01 Apr 2009 3 Modified Section 2 2 Main operating voltages on page 8 Table 1 General operating conditions replaced 05 Aug 2011 4 Figure 10 Reference design on page 19 updated the value of the C4 capacitor Added STMBA throughout the document as this revision covers STMBA devices Replaced Root part number 2 with STM8S and STMB8A Updated Section 2 2 Main operating voltages removed Table 1 General operating conditions and added a reference to the STM8S 31 Aug 2011 5 and STMB8
17. atasheet of the crystal manufacturer to select the capacitances For best oscillation stability Cj 4 and Cj normally have the same value Typical values are in the range from below 20 pF up to 40 pF cload 10 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 should be as short as possible Any additional signals especially those that could interfere with the oscillator should be locally separated from the PCB area around the oscillation circuit using suitable shielding 4 Doc ID 14651 Rev 5 13 40 www BDTIC com ST Reset control AN2752 5 5 1 14 40 Reset control Reset management overview The reset cell is a dedicated 5 V bidirectional I O Its output buffer driving capability is fixed to lolyiN 2 mA 0 4 V in the 3 V to 5 5 V range which includes a 40 k pull up Output buffer is reduced to the n channel MOSFET NMOS If a 40 k pull up is accepted this cell does not include an output buffer of 5 V capability The receiver includes a glitch filter whereas the output buffer includes a 20 us delay There are many reset sources including e External reset through the NRST pin e Power on reset POR and brown out reset BOR During power on the POR keeps the device under reset until the supply voltage Vpp and Vppjo reach the voltage level at which the BOR starts to f
18. ave an internal regulator with a nominal target output of 1 8 V Stabilization for the main regulator is achieved by connecting an external capacitor Cgy to the VCAP pin Please refer to the STM8S or STM8A datasheets for more information on the VCAP capacitor characteristics Care should be taken to limit the series inductance to less than 15 nH Figure 2 External capacitor ESR C ESL ra man e Where ESR is the equivalent series resistance Rleak ESL is the equivalent inductance Power on power down reset POR PDR The input supply to the main and low power regulators is monitored by a power on power down reset circuit The monitoring voltage range is 0 7 V to 2 7 V During power on the POR PDR keeps the device under reset until the supply voltages Vpp and Vppio reach their specified working area At power on a defined reset should be maintained below 0 7 V The upper threshold for a reset release is defined in the electrical characteristics section of the product datasheet A hysteresis is implemented POR PDR to ensure clean detection of voltage rise and fall The POR PDR also generates a reset when the supply voltage drops below the Vpor ppr threshold isolated and repetitive events Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Power supply Recommendations All pins need to be properly connected to the power supplies These connections including
19. ct stw project Ey Source Files A mono lcd c Library A main c stm8 it c amp stp interrupt v h Include Files Sq External Dependencie j 8 mods0 h fS Workspace S File Edit view Project Build Debug Debug instrument Tools Window Help lasd uae OMT aec 00 t3 P main c Pf This file contains the firm hor STMicroelectronics Bion V0 04 21 DEC 2007 PRESENT SOFTWARE WHICH IS FOR DING INFORMATION REGARDING b RESULT STMICROELECTROK CT INDIRECT OR CONSEQUENTIAL THE CONTENT OF SUCH SOFTWARE NG INFORMATION CONTAINED HEREI COPYRIGHT 2007 mono lcd c mono lcd h Doc ID 14651 Rev 5 35 40 www BDTIC com ST Setting up the STM8 development environment AN2752 10 3 5 Running the software After entering debug mode the software can be started by the run command in the menu Debug Run see Figure 25 Figure 25 STVD Run the software STMBAF51xx STM SWIM project stw Debug project elf main c file Edit view Project Build Debug Debug instrument Tools Window Help t ERUIT g IE TA o Stop Debugging Workspace TW project stw Go To PC Alt Num in project 16 nCount Source Files EI Chers ER wi mono lcd c hip Reset Ctrl ShiFt F5 ic z ooao ter Xia 1 pt S A Ubrary f Restart i A Di stm8_adc c Continue T D CO q y c stm8 awu c N c i gh stm8 beep i
20. duct datasheet ky Doc ID 14651 Rev 5 17 40 www BDTIC com ST Reference design AN2752 7 7 1 18 40 Reference design Components reference Table 1 Component list ID Component name Reference Quantity Comments Refer to the Pinouts and pin description 1 Microcontroller STM8S and 4 and Package characteristics sections of STM8A the STM8S or STM8A datasheets to choose the right package 2 Push button 1 1 3 Resistor 10 kOhm 1 4 Capacitor 100 nF 5 Ceramic capacitor decoupling capacitor 5 Capacitor 1 uF 1 Decoupling capacitor 6 Capacitor 1 uF 1 Main regulator stabilization 7 Capacitor 20 40 pF 2 Used for crystal 8 Crystal 1 24 MHz 1 9 SWIM connector 4 pins 1 Doc ID 14651 Rev 5 www BDTIC com ST AN2752 Reference design 7 2 Schematics Figure 10 Reference design U1 STM8 Package LOFP80 pin NRST PEO CLKCOO 370 PA1 OSCN PE12C SC G5 PA2 OSDOUT PE2 2C SIA 67 PA3 TIM2 CH3TIM3 CH1 PES TM1 EIN Gc PA4 UART1_RX PEA eai PAS UART1 TX PESEPI NS tzo PA6 UART1_CK PET AN8 5 VCAP PEG AN9 ES PBO AINO TIM1 CH1N PFO AIN10 SEA ae PB1 AINT TIM1 CH2N PFIUVRE 53P R 9 1 PB2 AIN2 TIM1 CH3N PF2IVRE 554 PB3 AIN3 TIM1 ETR PFS AINTI 55 PB4 AIN4 I2C_SCL PFA AINT2 15 T PB5 AIN5 I2C_ A PFS AINT3 15 PB6 AING PFO AINTA 17 PB7 AN7 PF7 AIN15 H PCO ADC ETR PGO CA
21. evaluation board znnrnfimrs ZEUG STM8 128 EVAL ws il m Follow up Step by step additional peripherals of STM8S and STMB8A devices can be run following on from the initial debug session described above Many features of STM8S and STMB8A devices 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 Doc ID 14651 Rev 5 37 40 www BDTIC com ST Documentation and online support AN2752 11 Documentation and online support Documentation resources related to tool usage includes Application e STMB8S datasheets STM8S207xx STM8S208xx STM8S105xx STM8S103K3 STM8S103F3 STM8S103F2 STM8S903K3 STM8S903F3 STM8S003K3 STM8S003F3 e STMB8A datasheets STM8AF52xx STM8AF6269 8x Ax STM8AF51xx STM8AF6169 7x 8x 9x Ax STM8AF622x 4x STM8AF6266 68 STM8AF612x 4x STM8AF6166 68 e How to program STM8S and STMBA Flash program memory and data EEPROM PMO051 e STMS8S and STMB8A microcontroller families reference manual RM0016 e STM8 CPU programming manual PM0044 Tools e STM8 firmware library and release note detailed descriptions of the library are included as help files e STice advanced emulation system for ST microcontrollers data briefing e STice user manual e Cosmic C compiler user manual e STM8 128 EVAL evaluation board user manual
22. ging STVD provides an integrated simulator software and supports a complete range of hardware tools including the low cost RLink in circuit debugger programmer and the high end STice emulator To program applications to an STM8S or STMBA device the STVD also provides an interface for reading from the microcontroller memories writing to them and verifying them This interface is based on the ST visual programmer STVP and supports all the target devices and programming tools supported by STVP The free ST toolset for STM8 is available from STMicroelectronics homepage see www st com Compiler STM8S and STMBA 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 use of a C compiler is 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 Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 STMB software toolchain 9 3 Firmware library The STM8 firmware library is a complete set of source code examples for each STM8 peripheral It is written in strict ANSI C and it is fully MISRA C 2004 compliant see Figure 17 All examples are delivered with workspace and project definition files for STVD and Cosmic C compiler which enables the user
23. ics e HW debug interface Rlink from Raisonance e STMS evaluation board from STMicroelectronics Installing the tools All software tools are delivered with a setup wizard which guides the user through the installation process It is recommended to install the tools in the following order 1 C compiler 2 ST toolset 3 STM8 firmware library The Rlink does not need any dedicated software installation in the STM8 development environment because the necessary drivers are delivered with the ST toolset These R link drivers must be launched separately as follows Start Programs STtoolset Setup Install Rlink driver Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Setting up the STM8 development environment 10 2 Using the tools Once the tools installation is complete the ST visual develop STVD integrated development environment can be launched The user then has the choice to generate either a new workspace with a new project or to open an existing workspace If using the STVD for the first time it is recommended to open an existing project from the STM8 firmware library The STM8 firmware library includes several examples for each peripheral plus one workspace containing a project which is already configured for the dot matrix display of the STM8 evaluation board It is located in the firmware subdirectory Project Cosmic see Figure 18 Figure 18 STVD open example workspace 1 ST7 Visual Develop B
24. ile Edit View Project Build Debug Debug instrument Tools Window Help jes suja LII etum msg a figs No Workspace Open Workspace Look in 3 15TMB8 Firmware Library Project Cosmic 4 EX Esl E Debug E Workspace Release project stw File name project stw Open Files of type Project Workspace stw Cancel EnC MODIFIED READ CAP NUM SCRL OVA NETTE GERE 7 Isi S T gt Build Tools Find in Files 1 FindinFiles 2 Debug A Console For Help press FT Doc ID 14651 Rev 5 29 40 www BDTIC com ST Setting up the STM8 development environment AN2752 10 2 1 Project editing All project source files are visible and can be edited see Figure 19 Figure 19 STVD MCU edit mode 2 ST Visual Develop project stw main c Eile Edit View Project Build Debug Debuginstrument Tools Window Help asi aS d SM oeaan Tel deo T7 project stw project Source Files E mono_led c Eig library E stm8 adc c L stm8 awu c TYITAEXTATTETERETATATATAY TAA Y HY Y A Y Y D DR GT 3c 3 3 03 0 03 0 0 0 6 8 8 8 n v n Bfile main c Bbrief This file contain Q oUn5oNH YORK Y Y Ya e n OFTWARE WHICH IS FOR GUIDANCE OV NG INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM T R LT MI ELECTRONI HALL NOT BE HELD LIABLE FOR ANY DIRECT INDIRECT OR JUENTIAL D s FROM THE CONTENT OF H FTWARE AND OR THE U CODING INFORMATION AINED H
25. k noisy low level sensitive and digital with a single point for gathering all ground returns Loops must be avoided or have a minimum surface The power supply should be implemented close to the ground line to minimize the surface of the supply loop This is due to the fact that the supply loop acts as an antenna and is therefore the main emitter and receiver of EMI All component free surfaces of the PCB must be filled with additional grounding to create a kind of shield especially when using single layer PCBs Decoupling The standard decoupler for the external power is a 100 pF pool capacitor Supplementary 100 nF capacitors must be placed as close as possible to the Vss Vpp pins of the micro in order to reduce the area of the current loop As a general rule decoupling all sensitive or noisy signals improves electromagnetic com patibility EMC performances There are 2 types of decouplers e Capacitors close to components Inductive characteristics which apply to all capacitors beyond a certain frequency must be taken into account If possible parallel capacitors with decreasing values 0 1 0 01 uF should be used e 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 Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Recommendations 6 5 Other signa
26. lection Select the Target you want to use for debug session Swim Alink Target Port Selection Select the connection port for usb usb the Target selected above Add Remove Show the selected target notification at start of debugging session Doc ID 14651 Rev 5 33 40 www BDTIC com ST Setting up the STM8 development environment AN2752 10 3 3 Caution 34 40 Connecting the hardware The Rlink tool can be connected to the PC by a standard USB connection It is also powered by the USB interface On the controller side the connection to the STM8 evaluation board is made by the SWIM interface cable The STM8 evaluation board is powered by an external 5 V supply see Figure 23 Figure 23 Connecting the debug instrument to the STM8 evaluation board Rlink USB connection 2 STM8 128 EVAL 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 Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Setting up the STM8 development environment 10 3 4 4 Starting the debug session Debug mode can be entered by the command Debug Start Debugging see Figure 24 Figure 24 STVD Starting the debug session 1 ST Visual Develop project stw main c Workspace ies proje
27. lication board STice supports the SWIM protocol making it possible to in circuit program and debug the microcontroller using only one general purpose I O In both the emulation and the in circuit programming debugging configuration STice is driven by the ST visual develop STVD or ST visual programmer STVP integrated development environment running on the host PC This provides total control of advanced application building debugging and programming features from a single easy to use interface Doc ID 14651 Rev 5 23 40 www BDTIC com ST STM8 development tools AN2752 Figure 15 In circuit programming and debugging Y ICD ICP flat cable connects STice to microcontroller via ICD ICP connector on application board SWIM connector linked to microcontroller NN ST microcontroller on AN application board X 24 40 Doc ID 14651 Rev 5 q www BDTIC com ST AN2752 STMB software toolchain 9 In order to write compile and run the first software on an STM8S or STMBA device the following STMS software toolchain components of the software toolchain are required see Figure 16 e Integrated development environment e Compiler e Firmware library optional used to ease the start up Figure 16 STM8 software toolchain lex visual Develop SE ll Eile Edit view Project Build Debug Debuginstrument Tools Window Help je as alala aa ee gt eeean F sm Workspace ax B E cosmic Se
28. ls When designing an application the following areas should be closely studied to improve EMC performances e Noisy signals clock e Sensitive signals high impedance In addition to e Signals for which a temporary disturbance permanently affects operation of the application for example interrupts and handshaking strobe signals but not LED commands A surrounding Vss trace for such signals increases EMC performances as does a shorter length or absence of noisy and sensitive traces crosstalk effect For digital signals the best possible electrical margin must be reached for the 2 logical states Slow Schmitt triggers are recommended for eliminating parasitic states 6 6 Unused l Os and features Microcontrollers are designed for a variety of applications where often a particular application does not use 100 of the microcontroller resources To increase EMC performance unused clocks counters or I Os should not be left free for example I Os should be set to 0 or 1 pull up or pull down to the unused I O pins and unused functions should be frozen or disabled Alternatively unused I Os can be programmed as push pull low in order to keep them at a defined level but not to use external components 6 7 User options STM8S and STMB8A devices have user option features that can be used for remapping or enabling disabling an automatic reset or low speed watchdog For more details please refer to the pro
29. pads tracks and vias should have the lowest possible impedance This is typically achieved with thick track widths and preferably dedicated power supply planes in multi layer printed circuit boards PCBs In addition each power supply pair should be decoupled with filtering ceramic capacitors C at 100 nF with one chemical C 1 2 uF in parallel on the STM8S or STMB8A device The ceramic capacitors should be placed as close as possible to the appropriate pins 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 such a Vpp Vss pair Figure 3 Typical layout of Vpp Vss pair Via to Vpp Via to Vss STM8 Doc ID 14651 Rev 5 9 40 www BDTIC com ST Analog to digital converter ADC AN2752 3 3 1 3 2 10 40 Analog to digital converter ADC Analog power The ADC unit has an independent analog supply reference voltage isolated on input pin VppA Which allows the ADC to accept a very clean voltage source This analog voltage supply range is the same as the digital voltage supply range on pin Vpp An isolated analog supply ground connection on pin VssA provides further ADC supply isolation Together the analog supply voltage and analog supply ground connection offer a separate external analog reference voltage input for the ADC unit on the Vper pin This gives better accuracy
30. r C and an internal resistor ladder R STM8S and STMB8A devices have two kinds of internal clock a high speed internal clock HSI running at 16 MHz and a low speed internal clock LSI running at 128 kHz After reset the CPU starts with the internal RC HSI clock signal divided by 8 i e 2 MHz External clock STM8S and STMB8A devices can connect to an external crystal or an external oscillator When no external clock is used OSCIN and OSCOUT can be used as general purpose IOs Figure 6 describes the external clock connections Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Clock management Figure 6 Clock sources Hardware configuration STM8 OSC OSCour A o 9 o s I O available E g External source i Frequency 32 kHz 24 MHz Comparator hysteresis 0 1 Vpp Caution Without prescaler a duty cycle of maximum 45 55 6 must be respected STM8 OSCN OSCour Q1 IL d Cu C2 4 Me Load capacitors E Frequency range 1 24 MHz Wake up time 2 ms 9 24 MHz Oscillation mode Preferred fundamental Output duty cycle Max 55 45 6 l O s Standard I O pins multiplexed with OSC and OSCoyt Cload 10 20 pF Maximum crystal power 100 pW Crystal ceramic resonators The values of the load capacitors C 4 and C are heavily dependent on the crystal type and frequency The user can refer to the d
31. rogramming and debugging sels 23 9 STM8 software toolchain 0000 cece eee eee 25 9 1 Integrated development environment 000 0 eee eee eee 26 82 COMPIE cxsracehritce tense Y Ea TEE E RU ES ded pres ie Rs Bees 26 9 3 Firmware library cusa AR REA PRAE TRE PEEIEARE ODE Rd RM RR Kd 27 10 Setting up the STM8 development environment 28 10 1 Installing he tools vasa eR Es PRSE PUERETIOORPEPEREES CUOI modice 28 oM copper soii ia ei a I PP 29 10 2 1 Projectediting lllsseeeseree B 30 10 2 2 Online help e e eR eee RR ERR BEE EE Ye tee OR RE Rd 31 10 3 Running the demonstration software 0 00 32 10 3 1 Compiling the project 0 0 0 ccc 32 10 3 2 Selecting the correct debug instrument 00 20055 33 10 3 8 Connecting the hardware 00 0c cece eee 34 10 3 4 Starting the debug session 002 e eee ee 35 10 3 5 Running the software 0 0 00 eee 36 10 3 6 Eollow Up suse eere u m wate EXE rex Ed d RE E e EE 37 11 Documentation and online support ssss sss 38 12 Revision history eucssces mmo m mi R8 CR sn C D DN EAR 39 Ky Doc ID 14651 Rev 5 3 40 www BDTIC com ST List of tables AN2752 List of tables Table 1 Component listerne 2 2 qu dd ir berto dede TEE RR E Rec RR RUEDA bees 18 Table 2 SWIM connector pins lllieleeseeeesee hr 20 Table 3 Document revision hi
32. s 12 4 2 Internal ClOCK 25 4 4 e244 sens ceases EE REERE ME Ex RE RRES PENES 12 4 3 External CloCk A PPEFFPICD C TITLE 12 5 Reset control 1 ac aos y wdccwck 63a adea dea ad Ra CC ORE E C 14 5 1 Reset management overview asssua anaana 14 6 Recommendations eeeeeeeeeeeeeee 16 6 1 Primed circuit board x uu quer REC ard Re eL e emer d 16 6 2 Component pOSIUOT s 1223 3 prp eR de RU edid deidetadwess 16 6 3 Ground and power supply Vss Vpp sssee nn 16 6 4 bos seco ewes Gee oud eres hoe pe eRe ee MEO eee Tee 16 6 5 Other signals ics seu seared ee Rwod tre in pact erates eee 4 eee 17 66 Unused I Os and features 0 cee eee 17 6 7 User Options DTI 17 7 Reference design aug s wur tides a E 6i eas cnr 08 98 dee e 18 7 1 Components reference 000 cece esee 18 7 2 Schedles dc preii tiea re a a a Rei TS e EEE E 19 8 STM8 development tools llules 20 2 40 Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Contents 8 1 Single wire interface module SWIM lsssslsls eese 20 8 1 1 SWIM overview 0 0 ccc m meh 20 8 1 2 SWIM connector pins 0 000 ee 20 8 1 3 Hardware connection 0 000 cee ete ee 21 8 2 Emulator STIGB ws e re Reg EEG UR xa EUER EE eh aer E bad het E MES 2 8 2 1 STice overview llsssseesesee tee 21 8 2 2 STice in emulation configuration llli 22 8 2 3 In circuit p
33. 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 e All pulses with duration more than 450 ns are recognized as valid pulses e Aftera valid pulse is recognized an internal pulse of at least 30 ns is guaranteed Figure 9 Input characteristics A 27 5 ns 27 5 ns 450 ns l l gt Pad lt 75 ns lt 75 ns lt 75 ns A PY A gt 30 ns Negative train of glitch filtered Reset requested gt Systemireset ky Doc ID 14651 Rev 5 15 40 www BDTIC com ST Recommendations AN2752 6 6 1 6 2 6 3 6 4 16 40 Recommendations Printed circuit board For technical reasons it is best to use a multi layer PCB with a separate layer dedicated to the Vss and another layer to the Vpp supply which results in a good decoupling as well as a good shielding effect For many applications economical requirements prohibit the use of this type of board In this case the most important feature is to ensure a good structure for the Vss and power supply Component position A preliminary layout of the PCB must separate the different circuits according to their electromagnetic interference EMI contribution in order to reduce cross coupling on the PCB i e noisy high current circuits low voltage circuits and digital components Ground and power supply Vss Vpp The Vss should be distributed individually to every bloc
34. ss jo 3 3 V 0 3 V to 5 V 0 5 V which are used to power only the I O s On 32 pin packages only one pair is bonded Note For Vppid Vssio Next to Vpp Vss it is recommended to connect these two pairs together and to use only one decoupling capacitance The purpose is to ensure good noise immunity by reducing the connection length between both supplies and also between Vpp Vpp o and the capacitor e One pair of pads VppA VssA 3 3 V 0 3 V to 5 V 0 5 V dedicated to analog functions Refer to Section 3 Analog to digital converter ADC on page 10 for more details Figure 1 Power supply wa SSA VoaP Vpp VDDiot l Main Low power E Z S Vss Vspio1 regulator Logic gt To Vppi02 V lOs SSIO2 l Vopio Vssio g OSCIN p Vooo Vssio L l XTAL VV OSCOUT lt gt Star connected I ai15330 Note The capacitors must be connected as close as possible to the device supplies especially Vpp 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 Vas ky Doc ID 14651 Rev 5 7 40 www BDTIC com ST Power supply AN2752 2 2 2 3 8 40 Main operating voltages STM8S and STMBA devices are processed in 0 13 um technology The STM8S and STM8A core and I O peripherals need different power supplies In fact STM8S and STMB8A devices h
35. story icisrasissrrrirsikoadi erritar i trenata rr 39 4 40 Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 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 Power supply render eter depth debe ha Pase uel n d xen Eae RUE Gun Pana ea a os 7 External CapacitOr x msnm a Redde Case ote pee G E Ege X Eus ee FRE RU Rn 8 Typical layout of Vpp Vss Pair IRI III 9 Analog input interface 2 liess RR n 10 System clock distribution internal clock 0006 cece eee 12 Clock sources ssseeseesee eae 13 Reset management sisleeseeeeeleeele eee 14 Output characteristics u anaua eae 15 Input characteristics coss ls ls usce bk x mE RUE d a Re d Ry ede 15 Reference design 000 c eee eens 19 Debug system block diagram 20 tenes 20 Hardware connection 0 cee teeta 21 Connection description 0 0c rn 21 STice in emulation configuration 0 00 c ete 23 In circuit programming and debugging sanassa saaa eee eee 24 STM8B software toolchain 00 00 25 STM8 firmware library examples 00 000 cee teas 27 STVD open example workspace 0000 eae 29
36. unction Independent watchdog reset IWDG Window watchdog reset WWDG Software reset The application software can trigger reset SWIM reset An external device connected to the SWIM interface can request the SWIM block to generate a microcontroller reset Illegal opcode reset If a code to be executed does not correspond to any opcode or prebyte value a reset is generated e Electromagnetic susceptibility EMS reset Generated if critical registers are corrupted or badly loaded Figure 7 Reset management STM8 Simplified functional I O reset schematic lt EET y Filter System reset External reset Illegal op code reset Pulse generator m IWDG WWDG seftware reset min 20 us lt SWIM reset EMS reset Delay POR BOR reset Doc ID 14651 Rev 5 ky www BDTIC com ST AN2752 Reset control Output characteristics e A valid pulse on the pin is guaranteed with a 20 ns pulse duration on the internal output buffer e After a valid pulse is recognized a pulse on the pin of at least 20 us is guaranteed starting from the falling edge of A Figure 8 Output characteristics A 220 ns gt A A P 20 us pulse stretch min gt Pad Reset requested Input characteristics e Allpulses with a duration less than 75 ns are filtered e Alltrain burst
37. ure proper and accurate sampling the following equation must be satisfied Equation 2 3 Rew Rex X Csamp Cext lt 35 x Tg where e Rsw 30 kOhm Rext is the total external resistance on the path of Viy Csamp 3 pF Ts 0 5 us for 2 MHz input CLK Equation 2 is specific for Rgxr and Cgxr when designing an analog input interface for the ADC Please refer to the STM8S or STM8A datasheets and or their corresponding reference manual RM0016 for more details Doc ID 14651 Rev 5 11 40 www BDTIC com ST Clock management AN2752 4 4 1 4 2 4 3 Note 12 40 Clock management Clock management overview STMS8S and STMBA devices offer a flexible way of selecting the core and peripheral clocks ADC memory digital peripherals The devices have internal and external clock source inputs and one output clock CCO Figure 5 System clock distribution internal clock IOSON l 1 to 24 MHz CCO pin crystal and external clock m Clock unit o w External clock l m joe E OSCour gt i 16 MHz 128 kHz i WDG AWU p Prescaler gt internal RC Timer Internal clock Clock distribution For more details please refer to the section on clock management in the datasheet Internal clock The RC oscillator has an internal capacito

Download Pdf Manuals

image

Related Search

Related Contents

zur Leseprobe BANXTER-Club III  Trekstor DataStation t.uch 400GB  Oct  Samsung WA60H4200SW 頂揭式 洗衣機 6kg 白色 User Manual  MODE D`EMPLOI - KARMA ITALIANA Srl  Unified Brands HYPERSTEAM HY-5G User's Manual  Fiche Pratique : Organiser sa veille pour gérer sa e    取扱説明書  

Copyright © All rights reserved.
Failed to retrieve file