Are there any examples implementing a watchdog on the nRF?
Watchdog on nRF?
cchoi22915 I’ll try to do a live session on this. It’s straight forward though, especially on the nRF52/91
/*
* Copyright (c) 2021 Circuit Dojo LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <drivers/watchdog.h>
#include <watchdog.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(app_watchdog);
static const struct device *wdt = DEVICE_DT_GET(DT_NODELABEL(wdt0));
static int wdt_channel_id;
int app_watchdog_setup()
{
int err;
if (!device_is_ready(wdt) || wdt == NULL)
{
LOG_WRN("Watchdog not ready");
return -EIO;
}
struct wdt_timeout_cfg wdt_config = {
/* Reset SoC when watchdog timer expires. */
.flags = WDT_FLAG_RESET_SOC,
/* Expire watchdog after max window */
.window.min = 0U,
.window.max = WDT_MAX_WINDOW};
wdt_channel_id = wdt_install_timeout(wdt, &wdt_config);
if (wdt_channel_id < 0)
{
LOG_ERR("Watchdog install error.");
return wdt_channel_id;
}
err = wdt_setup(wdt, WDT_OPT_PAUSE_HALTED_BY_DBG);
if (err)
{
LOG_ERR("Watchdog setup error");
return err;
}
return 0;
}
void app_watchdog_feed()
{
wdt_feed(wdt, wdt_channel_id);
}
First you set it up and then you feed it on whatever interval. That WDT_MAX_WINDOW sets the timeout in milliseconds. Make sure that wdt0
in your device overlay is set to status = "okay";
Awesome, thanks jaredwolff !!
Oh and if you didn’t figure it out already make sure you set your .conf
file to enable:
# Watchdog
CONFIG_WATCHDOG=y
Ah yes, I set the following parameters in the .conf file:
CONFIG_WATCHDOG=y
CONFIG_WDT_LOG_LEVEL_DBG=y
CONFIG_WDT_DISABLE_AT_BOOT=n
Thanks!
Hi jaredwolff
I’m trying to get the WDT running on our custom NRF52840 PCB, Did get the C code to compile but I need the watchdog.h file. Where can I get this or am I missing something
THanks
- Edited
/*
* Copyright (c) 2021 Circuit Dojo LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _APP_WATCHDOG_H
#define _APP_WATCHDOG_H
#define WDT_MAX_WINDOW 10000U
int app_watchdog_setup();
void app_watchdog_feed();
#endif
@mvdeventer here you go!