Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a watchdog timeout

I have a watchdog in my microcontroller that if it is not kicked, will reset the processor. My applications runs fine for a while but will eventually reset because the watchdog did not get kicked. If I step through the program it works fine.

What are some ways to debug this?

EDIT: Conclusion: The way I found my bug was the watchdog breadcrumbs.

I am using a PIC that has a high and low ISR vector. The High vector was suppose to handle the LED matrix and the Low vector was to handle the timer tick. But I put both ISR handlers in the high vector. So when I disabled the LED matrix ISR and the timer tick ISR needed service, the processor would be stuck in the low ISR to handle the timer tick, but the timer tick handler was not there.

The breadcrumbs limited my search down to the function that handled the led matrix and specifically disabling the LED matrix interrupt.

like image 661
Robert Avatar asked Mar 19 '09 11:03

Robert


People also ask

What happens when a watchdog timer runs out?

When the watchdog expires, the hardware will immediately reset the system. An interrupt can be enabled which will fire when the watchdog timer is getting close to expiration. In the interrupt handler, the software can decide to “feed” the watchdog to prevent the system from resetting.

How do I test my watchdog timer?

To test the WDT, set WDT_test true, stop kicking the WDT, and wait for the report within a certain time. That's the non-intrusive way to do it. To do a more complete end to end test, just stop kicking the WDT and wait to see whether it eventually performs the remedial action.

How is watchdog timeout calculated?

Watchdog Calculations : Consider a system in watchdog is working on 4 kHz clock. System finishes its work in 450 ms and worst case time to finish work is 500 ms. Let us consider 500 ms as timeout time. 1/4 kHz= 0.25 ms.

How do you stop a watchdog timer?

Stopping the watchdog To stop the watchdog, perform the following steps. Set the CONFIG register's STOPEN field to Enable during watchdog configuration. Write the special value 0x6E524635 to the TSEN register. Invoke the STOP task.


2 Answers

Add an uninitialized global variable that is set to different values throughout the code. Specifically, set it before and after major function calls.

Put a breakpoint at the beginning of main.

When the processor resets the global variable will still have the last value it was set to. Keep adding these "bread crumbs" to narrow down to the problem function.

like image 200
Robert Avatar answered Oct 16 '22 21:10

Robert


Many software watchdogs are automatically disabled when you attach a debugger (to prevent it from restarting while the debugger has the application halted).

That said, here are some basics:

Is this a multithreaded applications? Are you using a RT scheduler? If so, is your watchdog task starved?

Make sure your watchdog task can't be stuck on anything (pending semaphore, waiting for a message, etc). Sometimes, functions can block in ways you might not expect; for example, I have a Linux platform I'm working on right now where I can get printf to block quite easily.

If it's single threaded, a profiler may help you identify timing issues.

If this is a new system, make sure the watchdog works correctly; test simple code that just hits the WD and then sleeps in an infinite loop.

like image 23
Mikeage Avatar answered Oct 16 '22 20:10

Mikeage