Skip to content

Commit ae05388

Browse files
nordic-babukartben
authored andcommitted
samples: boards: nordic: system_off: Add comparator wakeup
Extend sytem_off sample to use analog comparator as wake up source. Signed-off-by: Bartlomiej Buczek <[email protected]>
1 parent 4cd33ba commit ae05388

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

samples/boards/nordic/system_off/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@ config APP_USE_RETAINED_MEM
2121

2222
endchoice
2323

24+
config GPIO_WAKEUP_ENABLE
25+
bool "Use button to wake up device from system off"
26+
default y
27+
help
28+
Enable system off wakeup from pressing sw0 button.
29+
2430
config GRTC_WAKEUP_ENABLE
2531
bool "Use GRTC to wake up device from system off"
2632
help
27-
Switch wake up source from pressing sw0 button to GRTC
33+
Enable system off wakeup from GRTC.
34+
35+
config LPCOMP_WAKEUP_ENABLE
36+
bool "Use COMP to wake up device from system off"
37+
help
38+
Enable system off wakeup from analog comparator.
2839

2940
source "Kconfig.zephyr"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
&comp {
2+
compatible = "nordic,nrf-lpcomp";
3+
psel = "AIN4";
4+
refsel = "VDD_4_8";
5+
status = "okay";
6+
};

samples/boards/nordic/system_off/sample.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ tests:
6767
- nrf54l20pdk/nrf54l20/cpuapp
6868
extra_configs:
6969
- CONFIG_GRTC_WAKEUP_ENABLE=y
70+
- CONFIG_GPIO_WAKEUP_ENABLE=n
7071
harness: console
7172
harness_config:
7273
type: multi_line
@@ -89,6 +90,7 @@ tests:
8990
extra_configs:
9091
- CONFIG_APP_USE_RETAINED_MEM=y
9192
- CONFIG_GRTC_WAKEUP_ENABLE=y
93+
- CONFIG_GPIO_WAKEUP_ENABLE=n
9294
- CONFIG_RETAINED_MEM=y
9395
harness: console
9496
harness_config:
@@ -107,3 +109,55 @@ tests:
107109
- "Off count: 1"
108110
- "Active Ticks:"
109111
- "Entering system off; wait 2 seconds to restart"
112+
sample.boards.nrf.system_off.lpcomp_wakeup:
113+
extra_args: DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_comparator.overlay"
114+
platform_allow:
115+
- nrf54l15dk/nrf54l15/cpuapp
116+
extra_configs:
117+
- CONFIG_LPCOMP_WAKEUP_ENABLE=y
118+
- CONFIG_GPIO_WAKEUP_ENABLE=n
119+
- CONFIG_COMPARATOR=y
120+
harness: console
121+
harness_config:
122+
type: multi_line
123+
ordered: true
124+
regex:
125+
- "system off demo"
126+
- "Retained data not supported"
127+
- "Entering system off; change signal level at comparator input to restart"
128+
- "system off demo"
129+
- "Retained data not supported"
130+
- "Entering system off; change signal level at comparator input to restart"
131+
- "system off demo"
132+
- "Retained data not supported"
133+
- "Entering system off; change signal level at comparator input to restart"
134+
sample.boards.nrf.system_off.retained_mem.lpcomp_wakeup:
135+
extra_args:
136+
- "DTC_OVERLAY_FILE=
137+
boards/nrf54l15dk_nrf54l15_cpuapp_comparator.overlay;
138+
boards/nrf54l15dk_nrf54l15_cpuapp_retained_mem.overlay"
139+
platform_allow:
140+
- nrf54l15dk/nrf54l15/cpuapp
141+
extra_configs:
142+
- CONFIG_APP_USE_RETAINED_MEM=y
143+
- CONFIG_GPIO_WAKEUP_ENABLE=n
144+
- CONFIG_LPCOMP_WAKEUP_ENABLE=y
145+
- CONFIG_RETAINED_MEM=y
146+
- CONFIG_COMPARATOR=y
147+
harness: console
148+
harness_config:
149+
type: multi_line
150+
ordered: true
151+
regex:
152+
- "system off demo"
153+
- "Retained data: INVALID"
154+
- "Boot count: 1"
155+
- "Off count: 0"
156+
- "Active Ticks:"
157+
- "Entering system off; change signal level at comparator input to restart"
158+
- "system off demo"
159+
- "Retained data: valid"
160+
- "Boot count: 2"
161+
- "Off count: 1"
162+
- "Active Ticks:"
163+
- "Entering system off; change signal level at comparator input to restart"

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <zephyr/device.h>
1313
#include <zephyr/drivers/gpio.h>
14+
#include <zephyr/drivers/comparator.h>
1415
#include <zephyr/kernel.h>
1516
#include <zephyr/pm/device.h>
1617
#include <zephyr/sys/poweroff.h>
@@ -19,9 +20,13 @@
1920
#if defined(CONFIG_GRTC_WAKEUP_ENABLE)
2021
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
2122
#define DEEP_SLEEP_TIME_S 2
22-
#else
23+
#endif
24+
#if defined(CONFIG_GPIO_WAKEUP_ENABLE)
2325
static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
2426
#endif
27+
#if defined(CONFIG_LPCOMP_WAKEUP_ENABLE)
28+
static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp));
29+
#endif
2530

2631
int main(void)
2732
{
@@ -58,7 +63,8 @@ int main(void)
5863
} else {
5964
printk("Entering system off; wait %u seconds to restart\n", DEEP_SLEEP_TIME_S);
6065
}
61-
#else
66+
#endif
67+
#if defined(CONFIG_GPIO_WAKEUP_ENABLE)
6268
/* configure sw0 as input, interrupt as level active to allow wake-up */
6369
rc = gpio_pin_configure_dt(&sw0, GPIO_INPUT);
6470
if (rc < 0) {
@@ -74,6 +80,11 @@ int main(void)
7480

7581
printf("Entering system off; press sw0 to restart\n");
7682
#endif
83+
#if defined(CONFIG_LPCOMP_WAKEUP_ENABLE)
84+
comparator_set_trigger(comp_dev, COMPARATOR_TRIGGER_BOTH_EDGES);
85+
comparator_trigger_is_pending(comp_dev);
86+
printf("Entering system off; change signal level at comparator input to restart\n");
87+
#endif
7788

7889
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
7990
if (rc < 0) {

0 commit comments

Comments
 (0)