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

Implement the sys_poweroff() hook. The hsem locking is not part of the
implementation, it doesn't seem necessary after
https://github.com/zephyrproject-rtos/zephyr/pull/42409 but I may be
wrong. Needs verification.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
Gerard Marull-Paretas 2023-08-07 18:26:41 +02:00 committed by Carles Cufí
commit b97b17a4f5
4 changed files with 34 additions and 17 deletions

View file

@ -11,3 +11,5 @@ zephyr_linker_sources_ifdef(CONFIG_BT_STM32_IPM
zephyr_sources_ifdef(CONFIG_PM
power.c
)
zephyr_sources_ifdef(CONFIG_POWEROFF poweroff.c)

View file

@ -14,5 +14,6 @@ config SOC_SERIES_STM32WBX
select CPU_HAS_ARM_MPU
select HAS_SWO
select HAS_PM
select HAS_POWEROFF
help
Enable support for STM32WB MCU series

View file

@ -58,15 +58,7 @@ static void lpm_hsem_lock(void)
/* Invoke Low Power/System Off specific Tasks */
void pm_state_set(enum pm_state state, uint8_t substate_id)
{
if (state == PM_STATE_SOFT_OFF) {
lpm_hsem_lock();
/* Clear all Wake-Up flags */
LL_PWR_ClearFlag_WU();
LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
} else if (state == PM_STATE_SUSPEND_TO_IDLE) {
if (state == PM_STATE_SUSPEND_TO_IDLE) {
lpm_hsem_lock();
@ -93,18 +85,17 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
return;
}
/* Release RCC semaphore */
z_stm32_hsem_unlock(CFG_HW_RCC_SEMID);
LL_LPM_EnableDeepSleep();
/* enter SLEEP mode : WFE or WFI */
k_cpu_idle();
} else {
LOG_DBG("Unsupported power state %u", state);
return;
}
/* Release RCC semaphore */
z_stm32_hsem_unlock(CFG_HW_RCC_SEMID);
LL_LPM_EnableDeepSleep();
/* enter SLEEP mode : WFE or WFI */
k_cpu_idle();
}
/* Handle SOC specific activity after Low Power Mode Exit */

View file

@ -0,0 +1,23 @@
/*
* 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_ClearFlag_WU();
LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
LL_LPM_EnableDeepSleep();
k_cpu_idle();
CODE_UNREACHABLE;
}