Skip to content

Commit a2171d7

Browse files
nordic-baburlubos
authored andcommitted
[nrf fromlist] samples: boards: nordic: system_off: Add GRTC wakeup
Extend system_off sample to use GRTC timer as a wake up source. Upstream PR: zephyrproject-rtos/zephyr#79095 Signed-off-by: Bartlomiej Buczek <[email protected]>
1 parent 4ac75dc commit a2171d7

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

samples/boards/nordic/system_off/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ config APP_USE_RETAINED_MEM
2121

2222
endchoice
2323

24+
config GRTC_WAKEUP_ENABLE
25+
bool "Use GRTC to wake up device from system off"
26+
default n
27+
help
28+
Switch wake up source from pressing sw0 button to GRTC
29+
2430
source "Kconfig.zephyr"

samples/boards/nordic/system_off/sample.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ tests:
2929
extra_configs:
3030
- CONFIG_APP_USE_RETAINED_MEM=y
3131
- CONFIG_RETAINED_MEM=y
32+
sample.boards.nrf.system_off.grtc_wakeup:
33+
build_only: true
34+
platform_allow:
35+
- nrf54l15dk/nrf54l15/cpuapp
36+
extra_configs:
37+
- CONFIG_GRTC_WAKEUP_ENABLE=y

samples/boards/nordic/system_off/src/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
#include <zephyr/sys/poweroff.h>
1717
#include <zephyr/sys/util.h>
1818

19+
#if IS_ENABLED(CONFIG_GRTC_WAKEUP_ENABLE)
20+
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
21+
#define DEEP_SLEEP_TIME_S 2
22+
#else
1923
static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
24+
#endif
2025

2126
int main(void)
2227
{
@@ -45,6 +50,15 @@ int main(void)
4550
printf("Retained data not supported\n");
4651
}
4752

53+
#if IS_ENABLED(CONFIG_GRTC_WAKEUP_ENABLE)
54+
int err = z_nrf_grtc_wakeup_prepare(DEEP_SLEEP_TIME_S * USEC_PER_SEC);
55+
56+
if (err < 0) {
57+
printk("Unable to prepare GRTC as a wake up source (err = %d).\n", err);
58+
} else {
59+
printk("Entering system off; wait %u seconds to restart\n", DEEP_SLEEP_TIME_S);
60+
}
61+
#else
4862
/* configure sw0 as input, interrupt as level active to allow wake-up */
4963
rc = gpio_pin_configure_dt(&sw0, GPIO_INPUT);
5064
if (rc < 0) {
@@ -59,6 +73,7 @@ int main(void)
5973
}
6074

6175
printf("Entering system off; press sw0 to restart\n");
76+
#endif
6277

6378
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
6479
if (rc < 0) {

0 commit comments

Comments
 (0)