Skip to content

Commit cc348c5

Browse files
nordic-seglnordic-piks
authored andcommitted
tests: drivers: watchdog: Add test for UICR.WDTSTART feature
On nrf54h20 Ironside can configure and start cpuapp watchodg. Add test which checks that: - Ironside started a watchdog, - cpuapp can feed the watchdog, - cpuapp can reconfigure the watchdog, - cpuapp can stop the watchdog. Signed-off-by: Sebastian Głąb <[email protected]>
1 parent db1b2f7 commit cc348c5

File tree

6 files changed

+193
-0
lines changed

6 files changed

+193
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(uicr_wdtstart)
11+
12+
target_include_directories(app PRIVATE ../common/)
13+
target_sources(app PRIVATE ../common/hw_info_helper.c)
14+
15+
target_sources(app PRIVATE src/main.c)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/* It must match with CONFIG_GEN_UICR_WDTSTART_INSTANCE_WDTx in sysbuild/uicr.conf */
8+
&wdt011 {
9+
status = "okay";
10+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_HWINFO=y
2+
CONFIG_WATCHDOG=y
3+
4+
CONFIG_LOG=y
5+
CONFIG_LOG_MODE_MINIMAL=y
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA.
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/drivers/hwinfo.h>
9+
#include <zephyr/drivers/watchdog.h>
10+
#include "hw_info_helper.h"
11+
12+
#include <zephyr/logging/log.h>
13+
LOG_MODULE_REGISTER(uicr_wdtstart, LOG_LEVEL_INF);
14+
15+
static const struct device *const wdt_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(wdt011));
16+
static int wdt_channel_id = -1;
17+
18+
19+
/* First call of configure_watchdog will:
20+
* - report that wdt_disable() returned -EFAULT (-14)
21+
* This is because driver is not aware that WDT was configured and started.
22+
* - NOT change WDT configuration
23+
* This is because WDT can be configured only when it is stopped.
24+
*/
25+
static void configure_watchdog(void)
26+
{
27+
int32_t ret;
28+
struct wdt_timeout_cfg m_cfg_wdt0;
29+
/* After reconfiguration, watchdog window will be
30+
* larger than the one set by the Ironside.
31+
*/
32+
uint32_t watchdog_window = 5000U;
33+
34+
if (!device_is_ready(wdt_dev)) {
35+
LOG_ERR("WDT device %s is not ready", wdt_dev->name);
36+
return;
37+
}
38+
39+
ret = wdt_disable(wdt_dev);
40+
LOG_INF("wdt_disable() returned %d", ret);
41+
42+
m_cfg_wdt0.callback = NULL;
43+
m_cfg_wdt0.flags = WDT_FLAG_RESET_SOC;
44+
m_cfg_wdt0.window.max = watchdog_window;
45+
m_cfg_wdt0.window.min = 0U;
46+
wdt_channel_id = wdt_install_timeout(wdt_dev, &m_cfg_wdt0);
47+
if (wdt_channel_id < 0) {
48+
LOG_ERR("wdt_install_timeout() returned %d", wdt_channel_id);
49+
return;
50+
}
51+
52+
ret = wdt_setup(wdt_dev, WDT_OPT_PAUSE_HALTED_BY_DBG);
53+
if (ret < 0) {
54+
LOG_ERR("wdt_setup() returned %d", ret);
55+
return;
56+
}
57+
58+
LOG_INF("Watchdog configured with window of %u milliseconds", watchdog_window);
59+
print_bar();
60+
}
61+
62+
int main(void)
63+
{
64+
int ret;
65+
uint32_t reset_cause = 0;
66+
67+
LOG_INF("UICR.WDTSTART test on %s", CONFIG_BOARD_TARGET);
68+
print_bar();
69+
70+
/* Test relies on RESET_PIN to correctly start. */
71+
get_current_reset_cause(&reset_cause);
72+
73+
/* Report unexpected reset type. */
74+
if (reset_cause & ~(RESET_PIN | RESET_WATCHDOG)) {
75+
LOG_INF("Unexpected reset cause was found!");
76+
print_bar();
77+
}
78+
79+
/* Check if reset was due to pin reset. */
80+
if (reset_cause & RESET_PIN) {
81+
LOG_INF("RESET_PIN detected");
82+
print_bar();
83+
clear_reset_cause();
84+
85+
LOG_INF("Watchdog shall fire in ~2 seconds");
86+
k_sleep(K_FOREVER);
87+
}
88+
89+
/* Check if reset was due to watchdog reset. */
90+
if (reset_cause & RESET_WATCHDOG) {
91+
LOG_INF("RESET_WATCHDOG detected");
92+
print_bar();
93+
clear_reset_cause();
94+
95+
/* configure_watchdog() is intentionally called twice.
96+
* - First call will "align" WDT driver state to HW configuration.
97+
* This will enable WDT feeding but will NOT reconfigure WDT.
98+
* - Second call will actually apply new WDT configuration.
99+
*/
100+
configure_watchdog();
101+
configure_watchdog();
102+
LOG_INF("WATCHDOG was reconfigured");
103+
104+
for (int count = 1; count < 4; count++) {
105+
/* Sleep longer than watchdog window set by the Ironside.
106+
* But less than the window set during watchdog reconfiguration.
107+
*/
108+
k_msleep(3000);
109+
110+
ret = wdt_feed(wdt_dev, wdt_channel_id);
111+
if (ret != 0) {
112+
LOG_ERR("wdt_feed() returned %d", ret);
113+
} else {
114+
LOG_INF("%u: Watchdog was feed", count);
115+
}
116+
}
117+
print_bar();
118+
}
119+
120+
ret = wdt_disable(wdt_dev);
121+
if (ret == 0) {
122+
LOG_INF("WATCHDOG was disabled");
123+
} else {
124+
LOG_INF("FAIL: wdt_disable() returned %d", ret);
125+
}
126+
127+
print_bar();
128+
LOG_INF("Test is completed");
129+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
# Allow Ironside to configure and start WDT
5+
CONFIG_GEN_UICR_WDTSTART=y
6+
7+
# Select WDT011 on cpuapp
8+
CONFIG_GEN_UICR_WDTSTART_INSTANCE_WDT1=y
9+
10+
# Set WDT window to 2 sec ([CRV + 1] / 32768)
11+
CONFIG_GEN_UICR_WDTSTART_CRV=65535
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
common:
2+
tags:
3+
- drivers
4+
- ci_tests_drivers_watchdog
5+
sysbuild: true
6+
harness: console
7+
harness_config:
8+
type: multi_line
9+
regex:
10+
- "UICR.WDTSTART test on nrf54h20dk"
11+
- "RESET_PIN detected"
12+
- "Watchdog shall fire in"
13+
- "RESET_WATCHDOG detected"
14+
- "WATCHDOG was reconfigured"
15+
- "3: Watchdog was feed"
16+
- "WATCHDOG was disabled"
17+
18+
tests:
19+
drivers.watchdog.uicr_wdtstart:
20+
platform_allow:
21+
- nrf54h20dk/nrf54h20/cpuapp
22+
integration_platforms:
23+
- nrf54h20dk/nrf54h20/cpuapp

0 commit comments

Comments
 (0)