Commit c08edf7a authored by Bartlomiej Buczek's avatar Bartlomiej Buczek Committed by Benjamin Cabé
Browse files

samples: boards: nrf: system_off: Print reset reason.

Add printing reset reason at the beginning of the sample. Makes it easier
to determine if sample correctly wakes up from LP mode.

Signed-off-by: default avatarBartlomiej Buczek <bartlomiej.buczek@nordicsemi.no>
parent 394c7853
Loading
Loading
Loading
Loading
+1 −0
Changes for samples/boards/nordic/system_off/prj.conf: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@ CONFIG_PM_DEVICE=y
CONFIG_GPIO=y
CONFIG_CRC=y
CONFIG_POWEROFF=y
CONFIG_HWINFO=y
+2 −0
Changes for samples/boards/nordic/system_off/sample.yaml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ tests:
        - "Retained data not supported"
        - "Entering system off; wait 2 seconds to restart"
        - "system off demo"
        - "Wakeup from System OFF by GRTC."
        - "Retained data not supported"
        - "Entering system off; wait 2 seconds to restart"
  sample.boards.nrf.system_off.retained_mem.grtc_wakeup:
@@ -97,6 +98,7 @@ tests:
        - "Off count: 1"
        - "Active Ticks:"
        - "Entering system off; wait 2 seconds to restart"
        - "Wakeup from System OFF by GRTC."
  sample.boards.nrf.system_off.lpcomp_wakeup:
    extra_args: DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_comparator.overlay"
    platform_allow:
+17 −0
Changes for samples/boards/nordic/system_off/src/main.c: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@

#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/hwinfo.h>
#include <zephyr/drivers/comparator.h>
#include <zephyr/kernel.h>
#include <zephyr/pm/device.h>
@@ -28,6 +29,20 @@ 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(void)
{
	uint32_t reset_cause;

	hwinfo_get_reset_cause(&reset_cause);
	if (reset_cause & RESET_DEBUG) {
		printf("Reset by debugger.\n");
	} else if (reset_cause & RESET_CLOCK) {
		printf("Wakeup from System OFF by GRTC.\n");
	} else  {
		printf("Other wake up cause 0x%08X.\n", reset_cause);
	}
}

int main(void)
{
	int rc;
@@ -39,6 +54,7 @@ int main(void)
	}

	printf("\n%s system off demo\n", CONFIG_BOARD);
	print_reset_cause();

	if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {
		bool retained_ok = retained_validate();
@@ -98,6 +114,7 @@ int main(void)
		retained_update();
	}

	hwinfo_clear_reset_cause();
	sys_poweroff();

	return 0;