Watchdog and fault handler

Hi,

I’m looking for ways to recover a device that is in an incorrect state due to a bug in code, one of the methods I’m trying is to use a buffer overflow and crash the system, then the watchdog would bring the system back running.

But I when I manage to crash the system I see the error messages and the system never resets from the watchdog, I think it is because the message says ‘system will halt after rebooting’.
Is there a way to override this behavior?, that is, the system doesn’t halt.

Hello Fabián,

The example below worked on my mbed LPC1768 as supposed to:

#include "mbed.h"

DigitalOut      led(LED1);
Watchdog&       watchdog = Watchdog::get_instance();
volatile int    i = 0;
volatile int    buf[5];

int main()
{
    printf("Starting...\r\n");
    watchdog.start(20000);  // timeout set to 20 s

    while (true) {
        watchdog.kick();
        buf[i++] = i;
        led = !led;
        printf("blink\r\n");
        ThisThread::sleep_for(500);
    }
}

It produced the following output on the connected serial terminal:

Starting...
blink
blink
blink
blink
blink
blink
blink
blink
blink

++ MbedOS Fault Handler ++

FaultType: HardFault

Context:
R0: 0
R1: A
R2: A
R3: 8
R4: 0
R5: 0
R6: 0
R7: 0
R8: 0
R9: 0
R10: 0
R11: 0
R12: 2515
SP   : 10002538
LR   : 5F7
PC   : 4BC
xPSR : 21000000
PSP  : 10002518
MSP  : 10007FA0
CPUID: 412FC230
HFSR : 40000000
MMFSR: 82
BFSR : 0
UFSR : 0
DFSR : 8
AFSR : 0
MMFAR: A
Mode : Thread
Priv : Privileged
Stack: PSP

-- MbedOS Fault Handler --



++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0x4BC
Error Value: 0x100014A0
Current Thread: main Id: 0x10000CE4 Entry: 0x223B StackSize: 0x1000 StackMem: 0x10001550 SP: 0x10002538 
For more info, visit: https://mbed.com/s/error?error=0x80FF013D&tgt=LPC1768
-- MbedOS Error Info --
Starting...
blink
blink
blink
blink
blink
...

Best regards, Zoltan

1 Like

Thanks

sometimes it works as expected sometimes not. Maybe when it doesn’t work as expected the memory is too corrupted?