samples: boards: nrf: system_off: suspend console

To achieve minimal power consumption, only the console (ie UART) needs
to be suspended. Note that this is a temporary workaround, UART driver
should be using device runtime PM so that this is not needed.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
Gerard Marull-Paretas 2023-09-13 11:19:20 +02:00 committed by Carles Cufí
parent 1f40012c00
commit 2cbc452d1d
2 changed files with 6 additions and 20 deletions

View file

@ -1,4 +1,3 @@
# Required to disable default behavior of deep sleep on timeout
CONFIG_PM_DEVICE=y
CONFIG_GPIO=y
CONFIG_CRC=y

View file

@ -18,9 +18,6 @@
static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
#define BUSY_WAIT_S 2U
#define SLEEP_S 2U
int main(void)
{
int rc;
@ -55,22 +52,6 @@ int main(void)
return 0;
}
printf("Busy-wait %u s\n", BUSY_WAIT_S);
k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);
printf("Busy-wait %u s with UART off\n", BUSY_WAIT_S);
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_RESUME);
printf("Sleep %u s\n", SLEEP_S);
k_sleep(K_SECONDS(SLEEP_S));
printf("Sleep %u s with UART off\n", SLEEP_S);
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
k_sleep(K_SECONDS(SLEEP_S));
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_RESUME);
rc = gpio_pin_interrupt_configure_dt(&sw0, GPIO_INT_LEVEL_ACTIVE);
if (rc < 0) {
printf("Could not configure sw0 GPIO interrupt (%d)\n", rc);
@ -79,6 +60,12 @@ int main(void)
printf("Entering system off; press sw0 to restart\n");
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
if (rc < 0) {
printf("Could not suspend console (%d)\n", rc);
return 0;
}
if (IS_ENABLED(CONFIG_APP_RETENTION)) {
/* Update the retained state */
retained.off_count += 1;