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
1.2
1.3
Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Application principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2
Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1
STM8S peripheral configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.1
2.1.2
2.1.3
2.1.4
2.1.5
2.1.6
2.1.7
2.1.8
2.1.9
WWDG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Clock security system (CSS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
IWDG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
CLK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
GPIOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
EXTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Data EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
RST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
CCO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2
2.3
Exclusion of the Standard STM8S standard firmware library . . . . . . . . . 10
Application software flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.1
2.3.2
2.3.3
2.3.4
2.3.5
Main loop flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Interrupt function flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
State machine flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Reset handling function flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Saving SystemState in data EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . 16
3
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2/19
Doc ID 17860 Rev 1
List of figures
AN3265
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
WWDG software monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Main loop flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
State_Machine() function flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Reset handling routine flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Creating a segment in Zero Page with STVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4/19
Doc ID 17860 Rev 1