From b0d7a3082ce2226e6ce3d3151c5c3a583606c290 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Wed, 27 Nov 2024 15:56:32 +0100 Subject: [PATCH] [nrf fromlist] soc: nordic: poweroff: add retention management RAM retention is disabled for all RAM blocks before entering System OFF to achieve lowest power consumption. RAM retention can still be enabled using retained_mem driver. Upstream PR #: 82262 Signed-off-by: Nikodem Kastelik --- soc/nordic/common/poweroff.c | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/soc/nordic/common/poweroff.c b/soc/nordic/common/poweroff.c index b3210da697d..99a2bcfb3d6 100644 --- a/soc/nordic/common/poweroff.c +++ b/soc/nordic/common/poweroff.c @@ -5,6 +5,7 @@ #include #include +#include #if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) #include @@ -17,8 +18,45 @@ #include #endif +#if defined(CONFIG_HAS_NORDIC_RAM_CTRL) +#include +#endif + void z_sys_poweroff(void) { +#if defined(CONFIG_HAS_NORDIC_RAM_CTRL) + uint8_t *ram_start; + size_t ram_size; + +#if defined(NRF_MEMORY_RAM_BASE) + ram_start = (uint8_t *)NRF_MEMORY_RAM_BASE; +#else + ram_start = (uint8_t *)NRF_MEMORY_RAM0_BASE; +#endif + + ram_size = 0; +#if defined(NRF_MEMORY_RAM_SIZE) + ram_size += NRF_MEMORY_RAM_SIZE; +#endif +#if defined(NRF_MEMORY_RAM0_SIZE) + ram_size += NRF_MEMORY_RAM0_SIZE; +#endif +#if defined(NRF_MEMORY_RAM1_SIZE) + ram_size += NRF_MEMORY_RAM1_SIZE; +#endif +#if defined(NRF_MEMORY_RAM2_SIZE) + ram_size += NRF_MEMORY_RAM2_SIZE; +#endif + + /* Disable retention for all memory blocks */ + nrfx_ram_ctrl_retention_enable_set(ram_start, ram_size, false); +#endif + +#if defined(CONFIG_RETAINED_MEM_NRF_RAM_CTRL) + /* Restore retention for retained_mem driver regions defined in devicetree */ + (void)z_nrf_retained_mem_retention_apply(); +#endif + #if defined(CONFIG_SOC_SERIES_NRF54LX) nrfx_reset_reason_clear(UINT32_MAX); #endif