This application note shows how to detect stack overflow by using the ST9 timer/watchdog.
This document describes a method to protect real-time applications running on ST9 microcontrollers from stack overflow errors. It details how to utilize the Timer/Watchdog peripheral to automatically generate a system reset if the application stack overwrites reserved memory locations containing specific watchdog restart values.
The note provides the theoretical principle behind the detection, including the required byte sequence (AAh, 55h) to restart the watchdog. It also includes specific software code examples for initializing the system stack in both the Register File and RAM space, as well as instructions for programming and restarting the Timer/Watchdog to ensure continuous monitoring.
| Timer/Watchdog counter width | 16-bit down counter |
|---|---|
| Prescaler width | 8-bit prescaler |
| Time period range | 333 ns to 5.59 s |
| Maximum internal clock frequency | 12 MHz |
| Watchdog restart sequence | AAh, 55h |
The byte sequence AAh, 55h must be written into the Timer Watchdog register Low.
The data is destroyed, and a system reset is generated on the next Timer Watchdog End Of Count.
The system stack may be located in the Register File or in data memory space.