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 <gerard@teslabs.com>
This commit is contained in:
parent
643383b060
commit
60da8d5303
3 changed files with 10 additions and 8 deletions
|
@ -2,3 +2,4 @@ CONFIG_PM=y
|
||||||
CONFIG_PM_DEVICE=n
|
CONFIG_PM_DEVICE=n
|
||||||
CONFIG_PM_DEVICE_RUNTIME=n
|
CONFIG_PM_DEVICE_RUNTIME=n
|
||||||
CONFIG_HWINFO=y
|
CONFIG_HWINFO=y
|
||||||
|
CONFIG_POWEROFF=y
|
||||||
|
|
|
@ -15,7 +15,7 @@ tests:
|
||||||
- "Reset cause: Reset pin"
|
- "Reset cause: Reset pin"
|
||||||
- "Device ready: .*"
|
- "Device ready: .*"
|
||||||
- "Press and hold the user button:"
|
- "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"
|
- "when LED2 is ON to enter to Standby Mode"
|
||||||
filter: dt_compat_enabled("zephyr,power-state") and dt_enabled_alias_with_parent_compat("led0",
|
filter: dt_compat_enabled("zephyr,power-state") and dt_enabled_alias_with_parent_compat("led0",
|
||||||
"gpio-leds") and dt_compat_enabled("st,stm32-lptim")
|
"gpio-leds") and dt_compat_enabled("st,stm32-lptim")
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <zephyr/drivers/gpio.h>
|
#include <zephyr/drivers/gpio.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
#include <zephyr/pm/pm.h>
|
#include <zephyr/pm/pm.h>
|
||||||
|
#include <zephyr/sys/poweroff.h>
|
||||||
#include <stm32_ll_pwr.h>
|
#include <stm32_ll_pwr.h>
|
||||||
|
|
||||||
#if !defined(CONFIG_SOC_SERIES_STM32L4X)
|
#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);
|
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_init(&button_sem, 0, 1);
|
||||||
k_sem_take(&button_sem, K_FOREVER);
|
k_sem_take(&button_sem, K_FOREVER);
|
||||||
|
@ -67,13 +68,13 @@ void thread_shutdown_standby_mode(void)
|
||||||
printk("User button pressed\n");
|
printk("User button pressed\n");
|
||||||
config_wakeup_features();
|
config_wakeup_features();
|
||||||
if (led_is_on == false) {
|
if (led_is_on == false) {
|
||||||
printk("Shutdown Mode requested\n");
|
printk("Powering off\n");
|
||||||
printk("Release the user button to exit from Shutdown Mode\n\n");
|
printk("Release the user button to wake-up\n\n");
|
||||||
#ifdef CONFIG_LOG
|
#ifdef CONFIG_LOG
|
||||||
k_msleep(2000);
|
k_msleep(2000);
|
||||||
#endif /* CONFIG_LOG */
|
#endif /* CONFIG_LOG */
|
||||||
pm_state_force(0u, &(struct pm_state_info) {PM_STATE_SOFT_OFF, 0, 0});
|
sys_poweroff();
|
||||||
/* stay in Shutdown mode until wakeup line activated */
|
/* powered off until wakeup line activated */
|
||||||
} else {
|
} else {
|
||||||
printk("Standby Mode requested\n");
|
printk("Standby Mode requested\n");
|
||||||
printk("Release the user button to exit from Standby Mode\n\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);
|
NULL, NULL, NULL, PRIORITY, 0, 0);
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -138,7 +139,7 @@ int main(void)
|
||||||
printk("Device ready: %s\n\n\n", CONFIG_BOARD);
|
printk("Device ready: %s\n\n\n", CONFIG_BOARD);
|
||||||
|
|
||||||
printk("Press and hold the user button:\n");
|
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");
|
printk(" when LED2 is ON to enter to Standby Mode\n\n");
|
||||||
|
|
||||||
led_is_on = true;
|
led_is_on = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue