From 202c16008f4bd0b6ad37d3594ed15607ccce3258 Mon Sep 17 00:00:00 2001 From: Romain Pelletant Date: Mon, 27 May 2024 23:22:14 +0200 Subject: [PATCH] soc: stm32c0: add poweroff mode Add poweroff mode support for STM32C0 Fixes #73371 Signed-off-by: Romain Pelletant --- soc/st/stm32/stm32c0x/CMakeLists.txt | 2 ++ soc/st/stm32/stm32c0x/Kconfig | 1 + soc/st/stm32/stm32c0x/poweroff.c | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 soc/st/stm32/stm32c0x/poweroff.c diff --git a/soc/st/stm32/stm32c0x/CMakeLists.txt b/soc/st/stm32/stm32c0x/CMakeLists.txt index eebd281cd96..8065e36bf13 100644 --- a/soc/st/stm32/stm32c0x/CMakeLists.txt +++ b/soc/st/stm32/stm32c0x/CMakeLists.txt @@ -5,6 +5,8 @@ zephyr_sources( soc.c ) +zephyr_sources_ifdef(CONFIG_POWEROFF poweroff.c) + zephyr_include_directories(.) set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") diff --git a/soc/st/stm32/stm32c0x/Kconfig b/soc/st/stm32/stm32c0x/Kconfig index 8d8c1b89d18..d24fdd311d8 100644 --- a/soc/st/stm32/stm32c0x/Kconfig +++ b/soc/st/stm32/stm32c0x/Kconfig @@ -10,3 +10,4 @@ config SOC_SERIES_STM32C0X select CPU_HAS_ARM_MPU select HAS_STM32CUBE select CPU_CORTEX_M_HAS_SYSTICK + select HAS_POWEROFF diff --git a/soc/st/stm32/stm32c0x/poweroff.c b/soc/st/stm32/stm32c0x/poweroff.c new file mode 100644 index 00000000000..c9c4db49e9d --- /dev/null +++ b/soc/st/stm32/stm32c0x/poweroff.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Kickmaker + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include + +void z_sys_poweroff(void) +{ + LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN); + LL_LPM_EnableDeepSleep(); + + k_cpu_idle(); + + CODE_UNREACHABLE; +}