![]() |
|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
june 2014 docid5833 rev 2 1/19 AN1015 application note software techniques for improvi ng microcontrollers emc performance introduction a major contributor to improved emc performance in microcontroller-based electronics systems is the design of hardened software. problems induced by emc disturba nces need to be considered as early as possible in the design phase. emc-oriented soft ware increases the security and the reliability of your application. emc-hardened soft ware is inexpensive to implem ent, improves the final goods immunity performance and saves hardware and development costs. you should consider emc disturbances to analog or digital data just like any other application parameter. examples of problems induced by emc disturbances: ? microcontroller not responding ? program counter runaway ? execution of unexpected instructions ? bad address pointing ? bad execution of subroutines ? parasitic reset and/or parasitic interrupts ? corruption of ip configuration ? i/o deprogramming examples of consequences of failing software: ? unexpected response of product ? loss of context ? unexpected branch in process ? loss of interrupts ? loss of data integrity ? corrupted reading of input values. this application note deals with two cat egories of software techniques, namely: ? preventive techniques: these can be implemented in existing designs, their purpose is to improve product robustness. ? auto-recovery techniques: when a runaway cond ition is detected, a recovery subroutine is used to take the decision to execute fail -safe routines, optionally sending a warning and then automatically returning back to normal operations (this operation may be absolutely transparent to the user of the application). www.st.com
contents AN1015 2/19 docid5833 rev 2 contents 1 related documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 preventive techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1 using the watchdog and time control techniques . . . . . . . . . . . . . . . . . . . . 6 2.2 securing the unused program memory area . . . . . . . . . . . . . . . . . . . . . . . 8 2.3 input filtering and comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.4 management of unused interrupt vectors . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.5 removing illegal and critical by tes from your code . . . . . . . . . . . . . . . . . . 9 2.5.1 critical bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.5.2 iilegal bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.6 averaging the a/d converter results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.7 register reprogramming and regular checking . . . . . . . . . . . . . . . . . . . . 10 2.8 redundant data storage and exchange . . . . . . . . . . . . . . . . . . . . . . . . . . .11 3 auto-recovery techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.1 saving your context in ram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.2 using the watchdog for local control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.3 using the reset flags to identify the reset source . . . . . . . . . . . . . . . . . . . 14 3.4 saving data into non-volatile memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4 which results can be achieved? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 docid5833 rev 2 3/19 AN1015 list of tables 3 list of tables table 1. summary of preventive techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 table 2. summary of auto-recovery techniqu es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 table 3. document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 list of figures AN1015 4/19 docid5833 rev 2 list of figures figure 1. classic examples of bad watchdog usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 2. example of correct watchdog usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 figure 3. example of auto-recovery software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 figure 4. local control by the watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 figure 5. identify reset sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 docid5833 rev 2 5/19 AN1015 related documents 18 1 related documents ? an3181 ?guidelines for obtaining iec 6033 5 class b certification in an stm8 application? ? an3307 ?guidelines for obtaining iec 6033 5 class b certification for any stm32 application? ? an4435 ?guidelines for obtaining ul/csa/ie c 60335 class b certification in any stm32 application? preventive techniques AN1015 6/19 docid5833 rev 2 2 preventive techniques you can implement preventive techniques in exis ting designs to improve product robustness and immunity against external or internal emc disturbance. 2.1 using the watchdog and time control techniques the watchdog is the most efficient tool availa ble to ensuring that the mcu can recover from software runaway failures. its principle is very simple: it is a timer which generates an mcu reset at the end of count. once the watchdog is started, the only way of preventing the watchdog from resetting the microcontroller is to update the counter periodically in the program. but to make the watchdog work at its full potenti al, you have to insert the enable and refresh instructions in your software at the right place of code execution. figure 1 shows two classic examples of bad watchdog implementation. to do it the right way (see figure 2 ), the following rules sh ould be implemented: ? enable the watchdog as soon as possible after reset, or use the hardware option if available. ? never refresh the watchdog during an interrupt routine or inside any local loop not guarded by timeout at code. it is very important to optimize the period bet ween the two refresh instructions according to the duration of the various routines, including the interrupt routines. the minimum use of the watchdog resets the mc u, this means that the program execution context is lost as well as the application data's integrity. after reset, in addition to enabling the watchdo g, on some mcus you can use the reset flags to distinguish between power on or low voltage reset or watchdog reset (refer to section 3.3: using the reset flags to identify the reset source . for more details). docid5833 rev 2 7/19 AN1015 preventive techniques 18 figure 1. classic examples of bad watchdog usage $ g g u " " " , 1 ) , 1 , 7 ( / 2 2 3 : ' * 1 2 7 ( 1 $ % / ( ' : d w f k g r j h q d e o h g w r r o d w h d i w h u 6 w d u w x s 0 6 9 , 1 7 : ' * ( 1 $ % / ( 6 s x u l r x v 3 & |