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

Implement the hook for sys_poweroff based on the SOFT_OFF code. Note
that standby mode was a substate of SOFT_OFF, however, it was not
supported judging from defined DT states. It can be added later using
the STANDBY state.

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

View file

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

View file

@ -13,5 +13,6 @@ config SOC_SERIES_STM32WLX
select CPU_HAS_ARM_MPU
select CLOCK_CONTROL_STM32_CUBE if CLOCK_CONTROL
select HAS_PM
select HAS_POWEROFF
help
Enable support for STM32WL MCU series

View file

@ -51,22 +51,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
LL_LPM_EnableDeepSleep();
k_cpu_idle();
break;
case PM_STATE_SOFT_OFF:
LL_PWR_ClearFlag_WU();
switch (substate_id) {
case 0:
LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
break;
case 1:
LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
break;
default:
LOG_DBG("Unsupported power substate-id %u", substate_id);
return;
}
LL_LPM_EnableDeepSleep();
k_cpu_idle();
break;
default:
LOG_DBG("Unsupported power state %u", state);
break;
@ -85,9 +69,6 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
/* need to restore the clock */
stm32_clock_control_init(NULL);
break;
case PM_STATE_SOFT_OFF:
/* Nothing to do. */
break;
default:
LOG_DBG("Unsupported power substate-id %u", state);
break;

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_MODE_SHUTDOWN);
LL_LPM_EnableDeepSleep();
k_cpu_idle();
CODE_UNREACHABLE;
}