From d700943d298515c2b414d57ee1c2457bbd71e388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ju=C5=99ena?= Date: Tue, 1 Apr 2025 22:20:24 +0200 Subject: [PATCH] soc: st: stm32: Add poweroff to F4 family MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows F4 MCUs to enter standby mode which behave similar to the poweroff mode. Signed-off-by: Tomáš Juřena --- soc/st/stm32/stm32f4x/CMakeLists.txt | 1 + soc/st/stm32/stm32f4x/Kconfig | 1 + soc/st/stm32/stm32f4x/poweroff.c | 29 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 soc/st/stm32/stm32f4x/poweroff.c diff --git a/soc/st/stm32/stm32f4x/CMakeLists.txt b/soc/st/stm32/stm32f4x/CMakeLists.txt index ea800d26565..b2b70aedeea 100644 --- a/soc/st/stm32/stm32f4x/CMakeLists.txt +++ b/soc/st/stm32/stm32f4x/CMakeLists.txt @@ -12,3 +12,4 @@ set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/li zephyr_sources_ifdef(CONFIG_PM power.c ) +zephyr_sources_ifdef(CONFIG_POWEROFF poweroff.c) diff --git a/soc/st/stm32/stm32f4x/Kconfig b/soc/st/stm32/stm32f4x/Kconfig index 2d8681f3da3..a738978109c 100644 --- a/soc/st/stm32/stm32f4x/Kconfig +++ b/soc/st/stm32/stm32f4x/Kconfig @@ -12,4 +12,5 @@ config SOC_SERIES_STM32F4X select CPU_HAS_ARM_MPU select HAS_SWO select HAS_PM + select HAS_POWEROFF select SOC_EARLY_INIT_HOOK diff --git a/soc/st/stm32/stm32f4x/poweroff.c b/soc/st/stm32/stm32f4x/poweroff.c new file mode 100644 index 00000000000..28099224184 --- /dev/null +++ b/soc/st/stm32/stm32f4x/poweroff.c @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * Copyright (c) 2024 STMicroelectronics + * Copyright (c) 2025 Tomas Jurena + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include +#include + +void z_sys_poweroff(void) +{ +#ifdef CONFIG_STM32_WKUP_PINS + LL_PWR_ClearFlag_WU(); +#endif /* CONFIG_STM32_WKUP_PINS */ + + LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY); + LL_LPM_EnableDeepSleep(); + + k_cpu_idle(); + + CODE_UNREACHABLE; +}