MBED Watchdog callback function before restart

Hi everyone,
I am using LPC1768 with MBED6.11 and using the watchdog API I don’t found a way to call a function before Watchdog bites or restart. I only want to send a message over UART just before restart or check in some way the cause of restart. I hope you can help me.

Best Regards

Hello Tom,

Unfortunately, there is no such watchdog callback available. Nevertheless, the WDTOF (Watchdog time-out flag) can be used to check whether the MCU is starting on a reset by watchdog.

According to the UM10360 - LPC176x/5x User Manual, Chapter 28: LPC176x/5x Watchdog Timer (WDT), page 581:

When the Watchdog is in the reset mode and the counter underflows, the CPU will be
reset, loading the stack pointer and program counter from the vector table as in the case
of external reset. The Watchdog time-out flag (WDTOF) can be examined to determine if
the Watchdog has caused the reset condition. The WDTOF flag must be cleared by
software.

8.4.1 Watchdog Mode register (WDMOD - 0x4000 0000)
The WDMOD register controls the operation of the Watchdog as per the combination of
WDEN and RESET bits. Note that a watchdog feed must be performed before any
changes to the WDMOD register take effect.

Table 524: Watchdog Mode register (WDMOD, address 0x4000 0000) bit description:

---------------------------------------------------------------------------------------------------------------------------------------
Bit  | Symbol   | Description                                                                                | Reset Value
---------------------------------------------------------------------------------------------------------------------------------------
0    | WDEN     | Watchdog enable bit (set-only). When 1, the watchdog timer is running.                     | 0
1    | WDRESET  | Watchdog reset enable bit (set -only). When 1, a watchdog time-out willcause a chip reset. | 0
2    | WDTOF    | Watchdog time-out flag. Set when the watchdog timer times out, cleared bysoftware.         | 0 (Only after POR)
3    | WDINT    | Watchdog interrupt flag (read-only, not clearable by software).                            | 0
31:4 | Reserved | user software should not write ones to reserved bits.                                      | The value read from a NA
...
#define WDTOF 2  // bit 2 in WDMOD register

Watchdog& watchdog = Watchdog::get_instance();
...
int main(void)
{
    if (LPC_WDT->WDMOD & (1 << WDTOF)) {  // Examine WDTOF
        printf("\r\nStarting on reset by watchdog\r\n");
    }
    ...
    watchdog.start(5000);  // clears WDTOF
    ...
}

Thanks for your reply @hudakz, it was useful for me.

Best Regards