How to use WDT with System ON sleep

I'm using the nrf52840, and I'm doing a project where the system needs to sleep for a long time, maybe more than 24 hours.
Following this ticket, How to enter System ON sleep in zephyr to go to sleep I just do this:

void deep_sleep_state() {
    //uint64_t seconds_to_deep_sleep = imachine_config_get_sleep_time();
    uint64_t seconds_to_deep_sleep = 300;
    LOG_INF("Deep Sleep State");
    LOG_INF("Sleeping for: %llu seconds", seconds_to_deep_sleep);

	// Check if necessary
    //k_sleep(K_MSEC(3000));

    bluetooth_disable();
   
    if( set_rtc_alarm(seconds_to_deep_sleep) != 0 ) {
        // TODO: Handle nap error
    }

    int rc;
	const struct device *const console_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
    const struct device *const uart1_dev = DEVICE_DT_GET(DT_NODELABEL(uart1));
    const struct device *const sensor_dev = DEVICE_DT_GET_ANY(st_lis2dh);
    const struct device *const spi3_dev = DEVICE_DT_GET(DT_NODELABEL(spi3));

    rc = pm_device_action_run(console_dev, PM_DEVICE_ACTION_SUSPEND);
    rc = pm_device_action_run(uart1_dev, PM_DEVICE_ACTION_SUSPEND);
    rc = pm_device_action_run(sensor_dev, PM_DEVICE_ACTION_SUSPEND);
    flash_suspend();
    rc = pm_device_action_run(spi3_dev, PM_DEVICE_ACTION_SUSPEND);

    k_sem_reset(&rtc_alarm_sem);
    k_sem_take(&rtc_alarm_sem, K_FOREVER);

    rc = pm_device_action_run(console_dev, PM_DEVICE_ACTION_RESUME);

    LOG_WRN("Wokend up - Rebooting");

	// Check if necessary
    //k_sleep(K_MSEC(5000));

    sys_reboot(SYS_REBOOT_COLD);
}


And everything was working correctly until I programmed the WDT into the project.
int watchdog_init(void)
{
	LOG_INF("Watchdog module init");

	if (!device_is_ready(wdt))
	{
		LOG_ERR("Watchdog device not ready");
		return ERROR;
	}

	struct wdt_timeout_cfg wdt_config = {
		/* Reset SoC when watchdog timer expires. */
		.flags = WDT_FLAG_RESET_SOC,

		/* Expire watchdog after max window */
		.window.min = WDT_MIN_WINDOW,
		.window.max = WDT_MAX_WINDOW,
	};

	// The watchdog pauses its operation during sleep and HALT
	uint8_t options = WDT_OPT_PAUSE_IN_SLEEP | WDT_OPT_PAUSE_HALTED_BY_DBG;

	#if WDT_ALLOW_CALLBACK
		/* Set up watchdog callback. */
		wdt_config.callback = watchdog_internal_callback;
	#endif /* WDT_ALLOW_CALLBACK */

	wdt_channel_id = wdt_install_timeout(wdt, &wdt_config);
	if (wdt_channel_id < 0) {
		LOG_ERR("Watchdog install error");
		return ERROR;
	}

	if (wdt_setup(wdt, options) != SUCCESS) {
		LOG_ERR("Watchdog setup error");
		return ERROR;
	}

	LOG_INF("Watchdog Configuration: SUCCESS");
	return SUCCESS;
}

From what I understood, wdt would not work during sleep, but in my tests here they are working and resetting the system.

Since this isn't working as it should, could you show me how to do it? I didn't find an example like that.

Related