![]() |
|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
november 2012 doc id 17286 rev 2 1/31 AN3181 application note guidelines for obtaining iec 60335 class b certification in an stm8 application introduction the role of safety has become very important for electronics applications. the level of safety requirements for components used in electronic designs is steadily increasing. the manufacturers of electronic devices include many new technical solutions in the design of new components. software techniques for improving safety are continuously being developed. the current safety recommendations and requirements are specified at worldwide level by recognized international standards bodies such as iec (international electrotechnical commission) and come under the compliance, verification and certification process of testing houses and authorities like vde (a ssociation for electrical, electronic and information technologies). the certification process is closely associated with electromagnetic compatibility (emc) tests when the robustness of the system against noise emission and noise sensitivity is tested for compliance with international standards. the main purpose of this applic ation note and its associated so ftware is to facilitate and accelerate user software development and certification processes for appliances which are subject to these requirements and certifications and are based on some of the st 8-bit family of microcontrollers. three packages certified by vde are provided for: mainstream stm8s and automotive stm8a high, medium and low density devices, ultra-low power medium-density stm8l and stm8al devices ultra-low power low density stm8l, stm8al and stm8tl touch-sensing devices. due to limited memory capacity of most of 8-bit devices all these packages are optimized and independent from other firmware libraries published by st. proper headers stm8xxx.h and stm8xxx_type.h from st standard peripheral libraries are included only to keep consistency of names of registers, bit masks and constants defined there. optimized code reduces program memory overhead and increases the code execution speed. all certified packages use similar principles de scribed by this document, with focus on main differences. while using hardware and firmware (see appendix a: stm8 class b firmware package variations ) compatibility between st families, these packages can also be adapted for some other st 8-bit microcontrollers not yet certified. ta bl e 1 lists the microcontrollers concerned by this application note. table 1. applicable products type product category microcontrollers stm8xxxx www.st.com
contents AN3181 2/31 doc id 17286 rev 2 contents 1 package variation overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 compliance with iec and vde standards . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1 generic tests included in the st firmware library . . . . . . . . . . . . . . . . . . . . 8 2.2 application specific tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2.1 adc/dac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.2.2 i/os . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.2.3 interrupts and external communication . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.2.4 timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.2.5 external addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3 class b software package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1 basic software principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1.1 fail safe mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1.2 class b variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1.3 class b flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.2 package organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2.1 projects and workspaces included in the package . . . . . . . . . . . . . . . . 13 3.2.2 tool specific integration of the library . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2.3 application demonstration example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.3 package configuring and debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.3.1 configuration control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.3.2 verbose diagnostic mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.3.3 debugging the package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4 class b solution structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.1 integrating software into user application . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.2 detailed description of startup self tests . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.2.1 watchdog startup self test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.2.2 cpu startup self test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 4.2.3 flash complete checksum self test . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 4.2.4 full ram march c-/x self test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4.2.5 clock startup self test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4.3 periodic run mode self tests initialization . . . . . . . . . . . . . . . . . . . . . . . . . 22 AN3181 contents doc id 17286 rev 2 3/31 4.4 detailed description of periodic run mode se lf tests . . . . . . . . . . . . . . . . . 23 4.4.1 run time self tests structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4.4.2 cpu light run mode self test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.4.3 stack boundaries run mode test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.4.4 clock run mode self test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.4.5 partial flash crc run mode self test . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.4.6 watchdog service in run mode test . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.4.7 partial ram run mode self test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 appendix a stm8 class b firmware package variations . . . . . . . . . . . . . . . . . . 29 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 list of figures AN3181 4/31 doc id 17286 rev 2 list of figures figure 1. example of ram memory configuration for stm8s20x . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 2. control flow four steps check routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 figure 3. diagnostic led timing signal principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 figure 4. integration of startup and periodic run mode self tests into application . . . . . . . . . . . . . . . 17 figure 5. startup self tests structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 figure 6. watchdogs startup self test structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 figure 7. cpu startup self test structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 figure 8. flash startup self test structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 figure 9. ram startup self test structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 figure 10. clock startup self test subroutine structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 figure 11. periodic run mode self test initialization structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 3 figure 12. periodic run mode self test and time base interrupt service structure . . . . . . . . . . . . . . . . 24 figure 13. cpu light run mode self test structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 figure 14. stack overflow run mode test structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 figure 15. clock run mode self test structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 figure 16. clock run mode self test principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 figure 17. partial flash crc run mode self test structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 figure 18. partial ram run mode self test structure) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 figure 19. fault coupling principle used at partial ram run mode self test . . . . . . . . . . . . . . . . . . . . . 28 AN3181 package variation overview doc id 17286 rev 2 5/31 1 package variation overview available configurations of stm8s/a package support the following devices in the families: stm8s high-density performance line devices with 32-128 kbytes flash memory (like stm8s20x) stm8s medium- and low-density access line devices with 4-32 kbytes flash memory (like stm8s105x, stm8s103x) stm8s high-, medium- and low-density value line devices with 4-64 kbytes flash memory (like stm8s007x , stm8s005x, stm8s003x) stm8s low-density application specific de vices with 8 kbytes flash memory (like stm8s903x) stm8a high-density can line devices with 32-128 kbytes flash memory (like stm8af5xxx) stm8a high and medium density standard line devices with 8-128 kbytes flash memory (like (stm8af6xxx) available configurations of medium-density stm8l/al package support the following devices in the ultra-low power families: stm8l medium density standard devices with 4-64 kbytes flash memory (like stm8l15xx) stm8l medium-density value line devices with 4-64 kbytes flash memory (like stm8l05xx) stm8al medium-density devices with up to 32 kbytes flash memory (like stm8al31xx, stm8al3lxx) available configurations of low-density stm8l/al/tl package support the following devices in the ultra-low power families: stm8l low density standard devices with up to 8 kbytes flash memory (like stm8l10xx) stm8al low density devices with up to 8 kbytes flash memory (like stm8al30xx) stm8tl low density devices with up to 16 kbytes flash memory and touch sensing interface (like stm8tl53xxx) all these firmware packages are available for free download from the st web. three projects have been prepared and tested for each package under following environment and toolchains: 1. iar embedded workbench? for stm8 ide (ewstm8?) with iar c-compiler? version 1.30 2. st visual develop (stvd) version 4.3.0 with cosmic stm8 c-compiler 32 k version 4.3.6 3. st visual develop (stvd) version 4.3.0 with raisonance stm8/st7 c-compiler version 2.38 package variation overview AN3181 6/31 doc id 17286 rev 2 for more electromagnetic compatibility (emc ) information please re fer to the following related application notes: an1015 application note, software techniques for improving microcontroller emc performance an1709 application note, emc design guide an2860 application note, emc guidelines for stm8s AN3181 compliance with iec and vde standards doc id 17286 rev 2 7/31 2 compliance with iec and vde standards the iec (international electrotechnical comm ission) is a non-profit and non-governmental authority recognized worldwide for preparing and publishing international standards for a vast range of electrical, electronic and re lated technologies. iec standards are focused mainly on safety and performance, the enviro nment, electrical energy efficiency and its renewable capabilities. the iec cooperates clos ely with iso (international organization for standardization) and itu (international telecommunication union). their standards define not only the recommendations for hardware, but also for software solutions. standards are divided into a number of safety classes depending on the purpose of the application. the other bodies that are recognized world wide in the field of electronic standard organizations are vde in germany, iet in th e united kingdom and the ieee in the united states. the vde association also includes a testing and certification institute which is a pioneer of software safety inspection. this is a registered national certification body (ncb) for germany. the main purpose of this testing house is to offer standards compliance and quality testing services to manufacturers of electrical appliances. one of the pivotal iec standards is the iec 60335-1 norm, which covers safety and security of household electronic appliances dest ined for domestic and similar environment. appliances incorporating electronic circuits are subject to component failure tests. the basic principle is that the appliance must remain safe in the case of any component failure. the microcontroller is an electronic component just like any other from this point of view. if safety relies on an electronic component, it must remain safe after two consecutive faults. this means the appliance must stay safe with one hardware failure and with the microcontroller not operating (under reset or not operating properly). if the safety depends on software, the software is taken into account with the second applied failure. the conditions required for software are defined precisely in annex q of the iec 60335-1 norm. three classes of appliances are defined here: class a : safety does not rely on software class b : software prevents unsafe operation class c : software is intended to prevent special hazards this application note and the associated st software package covers the group b specification. appliances under group c need some other special requirements such as dual microcontroller operation, which is outside the scope of this document. class b compliance aspects for microcontrollers are related both to hardware and software. a list of microcontroller parts under complianc e is evaluated at iec 60335-1 annex t which refers to iec 60730 annex h. this list can be divided into two groups - micro-specific and application-specif ic items. (see table 2: mcu components to be tested for class b compliance ). while application-specific parts rely on customer application structure and must be defined and developed by users (communication, i/o control, interrupts, analog inputs and outputs), micro-specific parts are related purely to the micro structure and can be made generic (core self-diagnostic, volatile and non-volatile memory integrity checking, clock system tests). this group of micro-specific tests is the focus of the st solution based on powerful hardware features of stm8 mcu such as dual independent watchdogs or clock sources. it is important to note that there are seve ral other peer recognized bodies concerning electronic safety standards besides iec, such as vde in germany, iet in the united kingdom and the ieee in the un ited states. in addition, an in creasing number of product compliance with iec and vde standards AN3181 8/31 doc id 17286 rev 2 safety standards are being harmonized to international safety standards. for example, the ul 60335-1, the dsa 60335-1 and the en 60335-1 are all documents which are based on the iec 60335-1. vde also includes a testing and certification institute which is a pioneer of software safety inspection. this is a registered national certification body (ncb) for germany. the main purpose of this testing house is to offer standards compliance and quality testing services for electrical appliance manufacturers. the stm8 fw in this package has been vde certified. 2.1 generic tests included in the st firmware library stm8 firmware library packages include the following microcontroller specific software modules, which have also been certified by vde: cpu registers test clock monitoring ram functional check flash checksum integrity check watchdog self-test stack overflow monitoring an overview of the methods used for these mcu-specific tests is given in ta b l e 3 and they are described in more detail in the following chapters. the last two items from the list above are not explicitly asked for by the norm, but they improve overall fault coverage. table 2. mcu components to be tested for class b compliance group components to be tested micro specific cpu registers cpu program counter clock fixed and variable memory spaces internal addressing internal data path application specific interrupt handling external communication and addressing (if any) timing i/o periphery adc and dac analog multiplexer AN3181 compliance with iec and vde standards doc id 17286 rev 2 9/31 the user can include a part or all of these vde certified software modules into his project. if the modules stay unchanged and are integrated in accordance with the guidelines provided in this application note, development time and costs to have end-application certification would be significantly reduced. 2.2 application specific tests the user should be aware that the following are also required for class b certification but are not included in the st firmware library: analog: adc/dac & multiplexer i/os interrupts and external communication timing external addressing table 3. overview of methods used in micro-specific tests provided with this application note components to be verified method used cpu registers functional test a, x and y registers, flags and stack pointer is done at startup. in the run time flags are not tested. stack pointer is tested for overflow and underflow. if any error is found, the software jumps directly to the fail safe routine. program counters two different watchdogs driven by two independent clock sources can reset the device when the program co unter is lost. the window watchdog (driven by main oscillator) performs time slot monitoring (1) while the independent one (driven by low speed internal rc oscillator) is impossible to disable once enabled. both watchdogs must be serviced at regular intervals. program control flow is monitored by specific software method, additionally. (see section 3.1.3 ). 1. window wdg feature is not available at stm8l10x devices. addressing and data path this is tested indirectly by ram func tional and flash integrity tests, stack overflow (a specific pattern is writ ten at a low boundary of stack space and checked for corruption at regular intervals) and underflow (a second pattern is written at a high boundary if it is not at the ram end). clock two independent internal frequencies are used for the dedicated timer clock and they are verified by reciprocal comparison. one frequency is fed into the dedicated timer while the other gates it. non-volatile memory a 16-bit crc software checksum test of the entire memory is done at startup and a partial memory test is repeated at runtime (block by block). variable memory space march c- (march x optionally) full memory test is done at startup. partial memory test is repeated at run time (block by block). word protection with double inverse redundancy (inverse values stored in non-adjacent memory space) is used for safety critical class b variables. class a variable space, stack and unused space are not tested at run time. compliance with iec and vde standards AN3181 10/31 doc id 17286 rev 2 2.2.1 adc/dac analog components depend on device?s app lication and peripheral c apabilities. used pins should be checked at correct intervals. free analog pins can be used for checking user analog reference points. internal references should be checked, too. 2.2.2 i/os class b tests must detect any malfunction on digital i/os. this could be covered by plausibility checks together with some other application parts (e.g. change in an analog signal from temperature sensor when heating/cooling digital control is switched on/off). 2.2.3 interrupts and ex ternal communication application interrupts occurrence and external communications can be checked by different methods. one of them could be a control using a set of incremental counters where every interrupt or communication event increments a specific counter. the values in the counters are then verified at given time intervals by cross-checking against some other independent time base. 2.2.4 timing timing could be verified by ensuring that the application routines execution times are correct and that there are no unexpected delays. a cross-check with a different time base could be done. timing control is strictly dependent on the application. 2.2.5 external addressing external addressing is not used with stm8 microcontrollers. AN3181 class b software package doc id 17286 rev 2 11/31 3 class b software package this section highlights the basi c common principles used in st software solution. the workspace organization under different tools is described together with its configuration and debugging capabilities. 3.1 basic software principles the basic software methods and common principles used for all the tests included in the st firmware library are described in detail at this section. 3.1.1 fail safe mode failsafe() routine is called (defined in stm8x_stl_startup.c file) at any fail detection. the program stays in a never ending loop waiting for wdg reset. except for some debugging features, the routine is almost empty. when editing this routine, the user must remember to include procedures necessary to keep the application in a safe state. if the user wants to recognize the error raised, the debug or verbose mode described in section 3.3: package configuring and debugging can be used. in debug mode the independent wdg is refreshed inside the never ending loop to prevent resetting the microcontroller when a failure occurs. 3.1.2 class b variables class b variables are dedicated variables defined by the user as critical to the application. they are always stored as a pair of complementary values in two separate ram areas. both normal and redundant values are always placed into non-adjacent memory locations. partial transparent ram march c- or march x test is performed permanently on these two regions through the system interrupt routines in run mode. the integrity of the pair is compared before the value is used. if any value stored is corrupted, failsafe() routine is called. an example of ram configuration is shown in figure 1 . the user can adapt the ram space allocation according to applic ation needs and with respect to device hardware capability. figure 1. example of ram memory configuration for stm8s20x : e r o 0 a g e # l a s s " v a r i a b l e s r e d u n d a n t c o m p l e m e n t a r y v a l u e s # l a s s " v a r i a b l e s n o r m a l v a l u e s # l a s s ! v a r i a b l e s 3 p e c i f i c p a t t e r n i s s t o r e d h e r e t o d e t e c t s t a c k o v e r f l o w u n d e r f l o w 3 t a c k x x x x x x x & |