From 60da8d53038f543536bf658b7c73dddf2b8029ab Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 7 Aug 2023 17:53:40 +0200 Subject: [PATCH] samples: boards: stm32: power_mgmt: standby_shutdown: use sys_poweroff Use the sys_poweroff() API to power off the board, also adjust messages accordingly. Signed-off-by: Gerard Marull-Paretas --- .../stm32/power_mgmt/standby_shutdown/prj.conf | 1 + .../stm32/power_mgmt/standby_shutdown/sample.yaml | 2 +- .../stm32/power_mgmt/standby_shutdown/src/main.c | 15 ++++++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/samples/boards/stm32/power_mgmt/standby_shutdown/prj.conf b/samples/boards/stm32/power_mgmt/standby_shutdown/prj.conf index 738c014c57a..885312c4353 100644 --- a/samples/boards/stm32/power_mgmt/standby_shutdown/prj.conf +++ b/samples/boards/stm32/power_mgmt/standby_shutdown/prj.conf @@ -2,3 +2,4 @@ CONFIG_PM=y CONFIG_PM_DEVICE=n CONFIG_PM_DEVICE_RUNTIME=n CONFIG_HWINFO=y +CONFIG_POWEROFF=y diff --git a/samples/boards/stm32/power_mgmt/standby_shutdown/sample.yaml b/samples/boards/stm32/power_mgmt/standby_shutdown/sample.yaml index 32b0f106f69..da4e37d74a9 100644 --- a/samples/boards/stm32/power_mgmt/standby_shutdown/sample.yaml +++ b/samples/boards/stm32/power_mgmt/standby_shutdown/sample.yaml @@ -15,7 +15,7 @@ tests: - "Reset cause: Reset pin" - "Device ready: .*" - "Press and hold the user button:" - - "when LED2 is OFF to enter to Shutdown Mode" + - "when LED2 is OFF to power off" - "when LED2 is ON to enter to Standby Mode" filter: dt_compat_enabled("zephyr,power-state") and dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and dt_compat_enabled("st,stm32-lptim") diff --git a/samples/boards/stm32/power_mgmt/standby_shutdown/src/main.c b/samples/boards/stm32/power_mgmt/standby_shutdown/src/main.c index a5419e2f18e..6610f01f955 100644 --- a/samples/boards/stm32/power_mgmt/standby_shutdown/src/main.c +++ b/samples/boards/stm32/power_mgmt/standby_shutdown/src/main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #if !defined(CONFIG_SOC_SERIES_STM32L4X) @@ -59,7 +60,7 @@ void button_pressed(const struct device *dev, struct gpio_callback *cb, k_sem_give(&button_sem); } -void thread_shutdown_standby_mode(void) +void thread_poweroff_standby_mode(void) { k_sem_init(&button_sem, 0, 1); k_sem_take(&button_sem, K_FOREVER); @@ -67,13 +68,13 @@ void thread_shutdown_standby_mode(void) printk("User button pressed\n"); config_wakeup_features(); if (led_is_on == false) { - printk("Shutdown Mode requested\n"); - printk("Release the user button to exit from Shutdown Mode\n\n"); + printk("Powering off\n"); + printk("Release the user button to wake-up\n\n"); #ifdef CONFIG_LOG k_msleep(2000); #endif /* CONFIG_LOG */ - pm_state_force(0u, &(struct pm_state_info) {PM_STATE_SOFT_OFF, 0, 0}); - /* stay in Shutdown mode until wakeup line activated */ + sys_poweroff(); + /* powered off until wakeup line activated */ } else { printk("Standby Mode requested\n"); printk("Release the user button to exit from Standby Mode\n\n"); @@ -85,7 +86,7 @@ void thread_shutdown_standby_mode(void) } } -K_THREAD_DEFINE(thread_shutdown_standby_mode_id, STACKSIZE, thread_shutdown_standby_mode, +K_THREAD_DEFINE(thread_poweroff_standby_mode_id, STACKSIZE, thread_poweroff_standby_mode, NULL, NULL, NULL, PRIORITY, 0, 0); int main(void) @@ -138,7 +139,7 @@ int main(void) printk("Device ready: %s\n\n\n", CONFIG_BOARD); printk("Press and hold the user button:\n"); - printk(" when LED2 is OFF to enter to Shutdown Mode\n"); + printk(" when LED2 is OFF to power off\n"); printk(" when LED2 is ON to enter to Standby Mode\n\n"); led_is_on = true;