Skip to content

Commit 8b23d1b

Browse files
[nrf fromlist] samples: boards: nordic: system_off fixes
For reasons other than system off, the retained data should be cleared. Upstream PR #: 89044 Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent 246cb42 commit 8b23d1b

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

samples/boards/nordic/system_off/sample.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ tests:
4242
ordered: true
4343
regex:
4444
- "system off demo"
45-
- "Retained data: INVALID"
45+
- "Retained data: valid"
4646
- "Boot count: 1"
4747
- "Off count: 0"
4848
- "Active Ticks:"
@@ -87,7 +87,7 @@ tests:
8787
ordered: true
8888
regex:
8989
- "system off demo"
90-
- "Retained data: INVALID"
90+
- "Retained data: valid"
9191
- "Boot count: 1"
9292
- "Off count: 0"
9393
- "Active Ticks:"
@@ -140,7 +140,7 @@ tests:
140140
ordered: true
141141
regex:
142142
- "system off demo"
143-
- "Retained data: INVALID"
143+
- "Retained data: valid"
144144
- "Boot count: 1"
145145
- "Off count: 0"
146146
- "Active Ticks:"

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <zephyr/sys/poweroff.h>
1919
#include <zephyr/sys/util.h>
2020

21+
#define NON_WAKEUP_RESET_REASON (RESET_PIN | RESET_SOFTWARE | RESET_POR | RESET_DEBUG)
22+
2123
#if defined(CONFIG_GRTC_WAKEUP_ENABLE)
2224
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
2325
#define DEEP_SLEEP_TIME_S 2
@@ -29,15 +31,14 @@ static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
2931
static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp));
3032
#endif
3133

32-
void print_reset_cause(void)
34+
void print_reset_cause(uint32_t reset_cause)
3335
{
34-
uint32_t reset_cause;
35-
36-
hwinfo_get_reset_cause(&reset_cause);
3736
if (reset_cause & RESET_DEBUG) {
3837
printf("Reset by debugger.\n");
3938
} else if (reset_cause & RESET_CLOCK) {
4039
printf("Wakeup from System OFF by GRTC.\n");
40+
} else if (reset_cause & RESET_LOW_POWER_WAKE) {
41+
printf("Wakeup from System OFF by GPIO.\n");
4142
} else {
4243
printf("Other wake up cause 0x%08X.\n", reset_cause);
4344
}
@@ -46,6 +47,7 @@ void print_reset_cause(void)
4647
int main(void)
4748
{
4849
int rc;
50+
uint32_t reset_cause;
4951
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
5052

5153
if (!device_is_ready(cons)) {
@@ -54,11 +56,19 @@ int main(void)
5456
}
5557

5658
printf("\n%s system off demo\n", CONFIG_BOARD);
57-
print_reset_cause();
59+
hwinfo_get_reset_cause(&reset_cause);
60+
print_reset_cause(reset_cause);
5861

5962
if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {
6063
bool retained_ok = retained_validate();
6164

65+
if (reset_cause & NON_WAKEUP_RESET_REASON) {
66+
retained.boots = 0;
67+
retained.off_count = 0;
68+
retained.uptime_sum = 0;
69+
retained.uptime_latest = 0;
70+
retained_ok = true;
71+
}
6272
/* Increment for this boot attempt and update. */
6373
retained.boots += 1;
6474
retained_update();

0 commit comments

Comments
 (0)