Skip to content

Commit c3c53ef

Browse files
[nrf fromtree] samples: boards: nrf: system_off: Add sample with system clock disabled
Extend the system off samples by adding an option to disable the system clock. When the system clock is disabled additional power savings can be observed. After using the `sys_clock_disable()` function, the GRTC is turned off making system time-related features unavailable. Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no> (cherry picked from commit 127ba8d)
1 parent 31fadc8 commit c3c53ef

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

samples/boards/nordic/system_off/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ config LPCOMP_WAKEUP_ENABLE
2323
help
2424
Enable system off wakeup from analog comparator.
2525

26+
config SYS_CLOCK_DISABLE
27+
bool "Power down system clock before system off"
28+
help
29+
System clock and GRTC will be switched off during system off.
30+
2631
source "Kconfig.zephyr"

samples/boards/nordic/system_off/sample.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,44 @@ tests:
4747
- "Off count: 0"
4848
- "Active Ticks:"
4949
- "Entering system off; press sw0 to restart"
50+
sample.boards.nrf.system_off.grtc_off:
51+
platform_allow:
52+
- nrf54l15dk/nrf54l05/cpuapp
53+
- nrf54l15dk/nrf54l10/cpuapp
54+
- nrf54l15dk/nrf54l15/cpuapp
55+
- nrf54lm20dk/nrf54lm20a/cpuapp
56+
extra_configs:
57+
- CONFIG_SYS_CLOCK_DISABLE=y
58+
harness: console
59+
harness_config:
60+
type: multi_line
61+
ordered: true
62+
regex:
63+
- "system off demo"
64+
- "Retained data not supported"
65+
- "System clock will be disabled"
66+
- "Entering system off; press sw0 to restart"
67+
sample.boards.nrf.system_off.retained_mem.grtc_off:
68+
platform_allow:
69+
- nrf54l15dk/nrf54l05/cpuapp
70+
- nrf54l15dk/nrf54l10/cpuapp
71+
- nrf54l15dk/nrf54l15/cpuapp
72+
- nrf54lm20dk/nrf54lm20a/cpuapp
73+
extra_configs:
74+
- CONFIG_APP_USE_RETAINED_MEM=y
75+
- CONFIG_SYS_CLOCK_DISABLE=y
76+
harness: console
77+
harness_config:
78+
type: multi_line
79+
ordered: true
80+
regex:
81+
- "system off demo"
82+
- "Retained data: valid"
83+
- "Boot count: 1"
84+
- "Off count: 0"
85+
- "Active Ticks:"
86+
- "System clock will be disabled"
87+
- "Entering system off; press sw0 to restart"
5088
sample.boards.nrf.system_off.grtc_wakeup:
5189
platform_allow:
5290
- nrf54l15dk/nrf54l05/cpuapp

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <zephyr/pm/device.h>
1818
#include <zephyr/sys/poweroff.h>
1919
#include <zephyr/sys/util.h>
20+
#include <zephyr/drivers/timer/system_timer.h>
2021

2122
#define NON_WAKEUP_RESET_REASON (RESET_PIN | RESET_SOFTWARE | RESET_POR | RESET_DEBUG)
2223

@@ -97,11 +98,15 @@ int main(void)
9798
printf("Retained data not supported\n");
9899
}
99100

101+
#if defined(CONFIG_SYS_CLOCK_DISABLE)
102+
printf("System clock will be disabled\n");
103+
#endif
100104
#if defined(CONFIG_GRTC_WAKEUP_ENABLE)
101105
int err = z_nrf_grtc_wakeup_prepare(DEEP_SLEEP_TIME_S * USEC_PER_SEC);
102106

103107
if (err < 0) {
104108
printk("Unable to prepare GRTC as a wake up source (err = %d).\n", err);
109+
return 0;
105110
} else {
106111
printk("Entering system off; wait %u seconds to restart\n", DEEP_SLEEP_TIME_S);
107112
}
@@ -141,6 +146,9 @@ int main(void)
141146
}
142147

143148
hwinfo_clear_reset_cause();
149+
#if defined(CONFIG_SYS_CLOCK_DISABLE)
150+
sys_clock_disable();
151+
#endif
144152
sys_poweroff();
145153

146154
return 0;

0 commit comments

Comments
 (0)