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

Cannot get watchdog to run on nrf9160

Dear All,

I am fairly new to the nrf9160 and the Zephyr Os.

I am trying to write a simple example code for watchdog. All I want to do is to reset my board if I don't feed it for 2 seconds. I am using trying to use the ncs\zephyr\tests\drivers\watchdog test code as the base for my own code. What I have written so far is this:

#include <zephyr.h>
#include <misc/printk.h>
#include <uart.h>
#include <gpio.h>
#include <watchdog.h>



static struct device *led1;

static struct device *wdt;

static struct wdt_timeout_cfg m_cfg_wdt0;


static void wdt_int_cb(struct device *wdt_dev, int channel_id)
{
	printk("Here\n");
}

void main(void)
{
        led1 = device_get_binding(LED_PORT1);
	/* Set LED pin as output */
	    gpio_pin_configure(led1, LED1, GPIO_DIR_OUT);
        gpio_pin_write(led1, LED1, 1);


        wdt = device_get_binding("DT_WDT_0_NAME");
        m_cfg_wdt0.flags = WDT_FLAG_RESET_SOC;
	    m_cfg_wdt0.callback = wdt_int_cb;
	    m_cfg_wdt0.window.max = 2000U;
        
        if (wdt_install_timeout(wdt, &m_cfg_wdt0) < 0) {
              printk("Error installing watchdog");
        }

        if (wdt_setup(wdt, 0) < 0) {
              printk("Error setting up watchdog");
        }

	printk("Watchdog sample code start!\n");
	while (1) {
		k_cpu_idle();
	}
}

Furthermore my prj.conf looks like this:

CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_GPIO=y
CONFIG_WATCHDOG=y
CONFIG_BOOT_BANNER=n

But this code won't run

Parents
  • Hi Giannis,

    If you are new to nRF9160 and NCS I would highly recommend that you go through this tutorial.


    The watchdog is a hardware peripheral that is directly connected to the internal reset signals. If the timer expires without the application writing a magic word into the register, it will perform a reset, regardless of the state of the CPU. (Even if you're in a hardfault).

    The watchdog has the ability to give an interrupt to the application some 32k CLK cycles before resetting the system, provided that the application is not blocked by a higher interrupt (if in HardFault or busFault, you will be blocked).

    The modem runs completely separate from the application, so the watchdog in the application space shouldn't be disrupted by the modem.

    The WDT can be configured to run during sleep, or halt when the debugger is connected, as per the CONFIG register:

     

    Regarding a WDT sample, you need to first add WDT to the 'Secure Partition Manager', as shown in this post.

    After that, you should be able to run the watchdog in non-secure mode. You can find a sample in "../ncs/zephyr/samples/drivers/watchdog" on how to run and configure it.


Reply
  • Hi Giannis,

    If you are new to nRF9160 and NCS I would highly recommend that you go through this tutorial.


    The watchdog is a hardware peripheral that is directly connected to the internal reset signals. If the timer expires without the application writing a magic word into the register, it will perform a reset, regardless of the state of the CPU. (Even if you're in a hardfault).

    The watchdog has the ability to give an interrupt to the application some 32k CLK cycles before resetting the system, provided that the application is not blocked by a higher interrupt (if in HardFault or busFault, you will be blocked).

    The modem runs completely separate from the application, so the watchdog in the application space shouldn't be disrupted by the modem.

    The WDT can be configured to run during sleep, or halt when the debugger is connected, as per the CONFIG register:

     

    Regarding a WDT sample, you need to first add WDT to the 'Secure Partition Manager', as shown in this post.

    After that, you should be able to run the watchdog in non-secure mode. You can find a sample in "../ncs/zephyr/samples/drivers/watchdog" on how to run and configure it.


Children
Related