soc: arm: st_stm32: l4: add support for sys_poweroff
Convert SOFT_OFF handler to sys_poweroff hook. Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
parent
11242691cd
commit
643383b060
|
@ -8,3 +8,5 @@ zephyr_sources(
|
|||
zephyr_sources_ifdef(CONFIG_PM
|
||||
power.c
|
||||
)
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_POWEROFF poweroff.c)
|
||||
|
|
|
@ -15,5 +15,6 @@ config SOC_SERIES_STM32L4X
|
|||
select CPU_HAS_ARM_MPU
|
||||
select HAS_SWO
|
||||
select HAS_PM
|
||||
select HAS_POWEROFF
|
||||
help
|
||||
Enable support for STM32L4 MCU series
|
||||
|
|
|
@ -27,19 +27,6 @@ LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);
|
|||
#define RCC_STOP_WAKEUPCLOCK_SELECTED LL_RCC_STOP_WAKEUPCLOCK_HSI
|
||||
#endif
|
||||
|
||||
void enter_ultra_low_power_mode(void)
|
||||
{
|
||||
/* Configure CPU core */
|
||||
/* Enable CPU deep sleep mode */
|
||||
LL_LPM_EnableDeepSleep();
|
||||
LL_DBGMCU_DisableDBGStandbyMode();
|
||||
/* Enter ultra_low-power mode */
|
||||
|
||||
for (;;) {
|
||||
k_cpu_idle();
|
||||
}
|
||||
}
|
||||
|
||||
void set_mode_stop(uint8_t substate_id)
|
||||
{
|
||||
/* ensure the proper wake-up system clock */
|
||||
|
@ -67,20 +54,6 @@ void set_mode_stop(uint8_t substate_id)
|
|||
}
|
||||
}
|
||||
|
||||
void set_mode_standby(void)
|
||||
{
|
||||
/* Select standby mode */
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
|
||||
enter_ultra_low_power_mode();
|
||||
}
|
||||
|
||||
void set_mode_shutdown(void)
|
||||
{
|
||||
/* Select shutdown mode */
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
|
||||
enter_ultra_low_power_mode();
|
||||
}
|
||||
|
||||
/* Invoke Low Power/System Off specific Tasks */
|
||||
void pm_state_set(enum pm_state state, uint8_t substate_id)
|
||||
{
|
||||
|
@ -93,10 +66,10 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
|
|||
k_cpu_idle();
|
||||
break;
|
||||
case PM_STATE_STANDBY:
|
||||
set_mode_standby();
|
||||
break;
|
||||
case PM_STATE_SOFT_OFF:
|
||||
set_mode_shutdown();
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
|
||||
LL_LPM_EnableDeepSleep();
|
||||
LL_DBGMCU_DisableDBGStandbyMode();
|
||||
k_cpu_idle();
|
||||
break;
|
||||
default:
|
||||
LOG_DBG("Unsupported power state %u", state);
|
||||
|
@ -129,9 +102,6 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
|
|||
break;
|
||||
case PM_STATE_STANDBY:
|
||||
__fallthrough;
|
||||
case PM_STATE_SOFT_OFF:
|
||||
/* We should not get there */
|
||||
__fallthrough;
|
||||
case PM_STATE_SUSPEND_TO_RAM:
|
||||
__fallthrough;
|
||||
case PM_STATE_SUSPEND_TO_DISK:
|
||||
|
|
23
soc/arm/st_stm32/stm32l4/poweroff.c
Normal file
23
soc/arm/st_stm32/stm32l4/poweroff.c
Normal 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>
|
||||
#include <stm32_ll_system.h>
|
||||
|
||||
void z_sys_poweroff(void)
|
||||
{
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
|
||||
LL_LPM_EnableDeepSleep();
|
||||
LL_DBGMCU_DisableDBGStandbyMode();
|
||||
|
||||
k_cpu_idle();
|
||||
|
||||
CODE_UNREACHABLE;
|
||||
}
|
Loading…
Reference in a new issue