AN3265
Application note
Handling hardware and software failures with the STM8S-DISCOVERY
Application overview
This application is based on the STM8S-DISCOVERY. It demonstrates how to use the STM8S window watchdog (WWDG) and independent watchdog (IWDG) in conjunction with the clock security system (CSS) to handle software and hardware failures.
Two external pushbuttons are used to simulate malfunctions while the LEDs monitor the application progress.
Once the STM8S105C6T6 is powered up through an USB cable connected to the host PC, LED LD2 starts blinking meaning that the programming operation has completed successfully.
Reference documents
●STM8S-DISCOVERY evaluation board user manual (UM0817).
●“Developing and debugging your STM8S-DISCOVERY application code” user manual (UM0834).
●STM8S105xx datasheet
●STM8S reference manual (RM0016)
December 2010 |
Doc ID 17860 Rev 1 |
1/19 |
www.st.com
Contents |
AN3265 |
|
|
Contents
1 |
Application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
5 |
|
|
1.1 |
Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
5 |
|
1.2 |
Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
6 |
|
1.3 |
Application principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
6 |
2 |
Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. 9 |
||
|
2.1 |
STM8S peripheral configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
9 |
|
|
|
2.1.1 |
WWDG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. 9 |
|
|
2.1.2 |
Clock security system (CSS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. 9 |
|
|
2.1.3 |
IWDG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
9 |
|
|
2.1.4 |
CLK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
10 |
|
|
2.1.5 |
GPIOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
10 |
|
|
2.1.6 |
EXTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
10 |
|
|
2.1.7 |
Data EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
10 |
|
|
2.1.8 |
RST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
10 |
|
|
2.1.9 |
CCO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
10 |
|
2.2 |
Exclusion of the Standard STM8S standard firmware library . . . . . . . . . |
10 |
|
|
2.3 |
Application software flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
11 |
|
|
|
2.3.1 |
Main loop flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
11 |
|
|
2.3.2 |
Interrupt function flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
12 |
|
|
2.3.3 |
State machine flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
12 |
|
|
2.3.4 |
Reset handling function flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
15 |
|
|
2.3.5 |
Saving SystemState in data EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . |
16 |
3 |
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
18 |
2/19 |
Doc ID 17860 Rev 1 |
AN3265 |
List of tables |
|
|
List of tables
Table 1. List of external components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Table 2. Interrupt routine versus flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Table 3. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Doc ID 17860 Rev 1 |
3/19 |
List of figures |
AN3265 |
|
|
List of figures
Figure 1. Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Figure 2. Application state machine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 3. WWDG software monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 4. Main loop flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 5. State_Machine() function flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Figure 6. Reset handling routine flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Figure 7. Creating a segment in Zero Page with STVD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4/19 |
Doc ID 17860 Rev 1 |
AN3265 |
Application description |
|
|
No on-board resources are required.
Table 1 gives the list of the external components used by the application.
Table 1. |
List of external components |
|
|
Component name |
Value |
Comments |
|
|
|
|
|
LD2, LD3, LD4, LD5 |
- |
Standards LEDs |
|
|
|
|
|
|
R2, R3, R4, R5 |
510 Ω |
Protective resistors |
|
|
|
|
|
C |
100 nF |
Debounce filter |
|
|
|
|
|
Button1 |
- |
Standard pushbutton |
|
|
|
|
|
Button2 |
- |
Standard pushbutton |
|
|
|
|
|
C1 |
470 nF |
Capacitor |
|
|
|
|
Doc ID 17860 Rev 1 |
5/19 |
Application description |
AN3265 |
|
|
Figure 1 shows how to interface the LEDs and the pushbuttons with the STM8SDISCOVERY.
For STM8S-DISCOVERY implementation details, refer to the board schematics provided in the STM8S-DISCOVERY user manual (UM0817).
Button1 requires an RC debounce filter to avoid triggering several interrupts. It consists of a capacitor C and PB0 internal pull-up resistor (about 45 KΩ.). No pull-up resistor is required for Button1 as the internal pull-up of PBO I/O pin is used.
Figure 1. Application schematics
0% % ##/ |
|
/3#)ªª. |
|
343ªªª |
0" |
"UTTON |
|
/3#/54 |
# |
# |
|
0" 0" 0" 0" |
|
|
"UTTONªª |
2 |
2 |
2 |
2 |
,$ ,$ ,$ ,$
AI
Two external pushbuttons are used to simulate malfunctions while the LEDs monitor the application progress.
Button1 can be used in two different ways depending on the application context:
1.To demonstrate the WWDG capability for managing software failures such as application freeze:
When pressing Button1, the application lengthens the delay between two WWDG refresh operations until this delay becomes too long. The WWDG then triggers a reset.
2.To trigger a software reset.
Button2 is used to demonstrate CSS and IWDG recovery capabilities in case of HSE clock failure. Pressing Button2 connects an additional high value capacitor to the OSCIN pin
6/19 |
Doc ID 17860 Rev 1 |