soc: arm: st_stm32: u5: add support for sys_poweroff

Add support for the sys_poweroff hook, re-using code from the SOFT_OFF
state.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
Gerard Marull-Paretas 2023-08-08 10:54:11 +02:00 committed by Carles Cufí
commit d7a0b4fa93
4 changed files with 24 additions and 13 deletions

View file

@ -8,3 +8,5 @@ zephyr_sources(
zephyr_sources_ifdef(CONFIG_PM
power.c
)
zephyr_sources_ifdef(CONFIG_POWEROFF poweroff.c)

View file

@ -16,5 +16,6 @@ config SOC_SERIES_STM32U5X
select CPU_CORTEX_M_HAS_DWT
select HAS_STM32CUBE
select HAS_PM
select HAS_POWEROFF
help
Enable support for STM32U5 MCU series

View file

@ -54,13 +54,6 @@ void set_mode_standby(uint8_t substate_id)
LL_PWR_SetPowerMode(LL_PWR_STANDBY_MODE);
}
void set_mode_shutdown(uint8_t substate_id)
{
ARG_UNUSED(substate_id);
/* Select shutdown mode */
LL_PWR_SetPowerMode(LL_PWR_SHUTDOWN_MODE);
}
/* Invoke Low Power/System Off specific Tasks */
void pm_state_set(enum pm_state state, uint8_t substate_id)
{
@ -72,9 +65,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
/* To be tested */
set_mode_standby(substate_id);
break;
case PM_STATE_SOFT_OFF:
set_mode_shutdown(substate_id);
break;
default:
LOG_DBG("Unsupported power state %u", state);
return;
@ -102,9 +92,6 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
case PM_STATE_STANDBY:
/* To be tested */
LL_LPM_EnableSleep();
case PM_STATE_SOFT_OFF:
/* We should not get there */
__fallthrough;
case PM_STATE_SUSPEND_TO_RAM:
__fallthrough;
case PM_STATE_SUSPEND_TO_DISK:

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/sys/poweroff.h>
#include <zephyr/toolchain.h>
#include <stm32_ll_cortex.h>
#include <stm32_ll_pwr.h>
void z_sys_poweroff(void)
{
LL_PWR_SetPowerMode(LL_PWR_SHUTDOWN_MODE);
LL_LPM_EnableDeepSleep();
k_cpu_idle();
CODE_UNREACHABLE;
}