Skip to content

Commit 2410511

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 0955031 commit 2410511

File tree

1 file changed

+13
-4
lines changed
  • samples/boards/nordic/system_off/src

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
2929
static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp));
3030
#endif
3131

32-
void print_reset_cause(void)
32+
void print_reset_cause(uint32_t reset_cause)
3333
{
34-
uint32_t reset_cause;
35-
3634
hwinfo_get_reset_cause(&reset_cause);
3735
if (reset_cause & RESET_DEBUG) {
3836
printf("Reset by debugger.\n");
3937
} else if (reset_cause & RESET_CLOCK) {
4038
printf("Wakeup from System OFF by GRTC.\n");
39+
} else if (reset_cause & RESET_LOW_POWER_WAKE) {
40+
printf("Wakeup from System OFF by GPIO.\n");
4141
} else {
4242
printf("Other wake up cause 0x%08X.\n", reset_cause);
4343
}
@@ -46,6 +46,7 @@ void print_reset_cause(void)
4646
int main(void)
4747
{
4848
int rc;
49+
uint32_t reset_cause;
4950
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
5051

5152
if (!device_is_ready(cons)) {
@@ -54,11 +55,19 @@ int main(void)
5455
}
5556

5657
printf("\n%s system off demo\n", CONFIG_BOARD);
57-
print_reset_cause();
58+
hwinfo_get_reset_cause(&reset_cause);
59+
print_reset_cause(reset_cause);
5860

5961
if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {
6062
bool retained_ok = retained_validate();
6163

64+
if (!(reset_cause & (RESET_CLOCK | RESET_LOW_POWER_WAKE))) {
65+
retained.boots = 0;
66+
retained.off_count = 0;
67+
retained.uptime_sum = 0;
68+
retained.uptime_latest = 0;
69+
retained_ok = true;
70+
}
6271
/* Increment for this boot attempt and update. */
6372
retained.boots += 1;
6473
retained_update();

0 commit comments

Comments
 (0)