diff --git a/drivers/hwinfo/hwinfo_nrf.c b/drivers/hwinfo/hwinfo_nrf.c index f5a6ed38a20..3d3314ddf58 100644 --- a/drivers/hwinfo/hwinfo_nrf.c +++ b/drivers/hwinfo/hwinfo_nrf.c @@ -207,6 +207,15 @@ int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported) | RESET_SOFTWARE | RESET_CPU_LOCKUP | RESET_LOW_POWER_WAKE +#if NRFX_RESET_REASON_HAS_VBUS + | RESET_POR +#endif +#if NRFX_RESET_REASON_HAS_GRTC + | RESET_CLOCK +#endif +#if defined(NRFX_RESET_REASON_TAMPC_MASK) || defined(NRFX_RESET_REASON_SECTAMPER_MASK) + | RESET_SECURITY +#endif | RESET_DEBUG); return 0; diff --git a/samples/boards/nordic/system_off/src/main.c b/samples/boards/nordic/system_off/src/main.c index d119eff87da..b4c2eeb2b1b 100644 --- a/samples/boards/nordic/system_off/src/main.c +++ b/samples/boards/nordic/system_off/src/main.c @@ -31,8 +31,17 @@ static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios); static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp)); #endif -void print_reset_cause(uint32_t reset_cause) +int print_reset_cause(uint32_t reset_cause) { + int32_t ret; + uint32_t supported; + + ret = hwinfo_get_supported_reset_cause((uint32_t *) &supported); + + if (ret || !(reset_cause & supported)) { + return -ENOTSUP; + } + if (reset_cause & RESET_DEBUG) { printf("Reset by debugger.\n"); } else if (reset_cause & RESET_CLOCK) { @@ -42,6 +51,8 @@ void print_reset_cause(uint32_t reset_cause) } else { printf("Other wake up cause 0x%08X.\n", reset_cause); } + + return 0; } int main(void) @@ -57,7 +68,12 @@ int main(void) printf("\n%s system off demo\n", CONFIG_BOARD); hwinfo_get_reset_cause(&reset_cause); - print_reset_cause(reset_cause); + rc = print_reset_cause(reset_cause); + + if (rc < 0) { + printf("Reset cause not supported.\n"); + return 0; + } if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) { bool retained_ok = retained_validate();