This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

watchdog timer

Is there an app-note, tutorial, or example of how to use the watchdog timer to reset the MCU if the application hangs?

Parents Reply Children
  • The attached file does show some of the basics but not much. I took a look at nrf51.h where the data structures are defined and the comments are pretty terse there too. I want to make sure I use this timer correctly in the context of a device that sleeps, wakes on one of a number of interrupt signals, does some processing, and goes back to sleep. Should the processing hang, I'd like the watchdog to interrupt the MCU, for the watchdog handler to log a message and a stack trace to flash, and then do a reset. I would expect that everyone would want to do this for production code and I'm surprised I couldn't find an example or at least more documentation.

    For example, what is the name of the watchdog interrupt handler and what utilities exist to log a stack trace?

  • If you want to use the watchdog interrupt, this is used like any other interrupt, you enable the event to generate an interrupt in the peripheral's INTEN register, and then enable the interrupt in the NVIC.

    As you can see in section 19.1.3 of the reference manual, this will give you 2 32.768 kHz clock cycles to do your logging and stack tracing. On reset, you can use the RESETREAS register to know the cause of the reset.

    The name of all interrupts are most easy to find in the startup file, and as you can see there, the watchdog interrupt handler will by default be WDT_IRQHandler. There are no utilities available to do stack tracing, but you can take a look at the ble_debug_assert_handler() function, which does similar things.

Related