AN1015
Application note
Software techniques for improving 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 disturbances need to be considered as early as possible in the
design phase. EMC-oriented software increases the security and the reliability of your
application. EMC-hardened software is inexpensive to implement, 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 categories 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 condition 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).
June 2014
DocID5833 Rev 2
1/19
www.st.com
Contents
AN1015
Contents
1
2
Related documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Preventive techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1
2.2
2.3
2.4
2.5
Using the watchdog and time control techniques . . . . . . . . . . . . . . . . . . . . 6
Securing the unused program memory area . . . . . . . . . . . . . . . . . . . . . . . 8
Input filtering and comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Management of unused interrupt vectors . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Removing illegal and critical bytes from your code . . . . . . . . . . . . . . . . . . 9
2.5.1
2.5.2
Critical Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
IIlegal Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.6
2.7
2.8
Averaging the A/D converter results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Register reprogramming and regular checking . . . . . . . . . . . . . . . . . . . . 10
Redundant data storage and exchange . . . . . . . . . . . . . . . . . . . . . . . . . . .11
3
Auto-recovery techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1
3.2
3.3
3.4
Saving your context in RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Using the watchdog for local control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Using the reset flags to identify the reset source . . . . . . . . . . . . . . . . . . . 14
Saving data into non-volatile memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4
5
Which results can be achieved? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2/19
DocID5833 Rev 2
AN1015
List of tables
List of tables
Table 1.
Table 2.
Table 3.
Summary of preventive techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Summary of auto-recovery techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
DocID5833 Rev 2
3/19
3
List of figures
AN1015
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Classic examples of bad watchdog usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Example of correct watchdog usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Example of auto-recovery software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Local control by the watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Identify reset sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4/19
DocID5833 Rev 2
AN1015
Related documents
1
Related documents
AN3181 “Guidelines for obtaining IEC 60335 Class B certification in an STM8
application”
AN3307 “Guidelines for obtaining IEC 60335 Class B certification for any STM32
application”
AN4435 “Guidelines for obtaining UL/CSA/IEC 60335 Class B certification in any
STM32 application”
DocID5833 Rev 2
5/19
18