Skip to content

Commit

Permalink
[nrf fromlist] soc: nordic: poweroff: add retention management
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit b0d7a30)
  • Loading branch information
nika-nordic authored and jukkar committed Dec 5, 2024
1 parent ee2e2b8 commit 49e3fe1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions soc/nordic/common/poweroff.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <zephyr/sys/poweroff.h>
#include <zephyr/toolchain.h>
#include <zephyr/drivers/retained_mem/nrf_retained_mem.h>

#if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X)
#include <hal/nrf_power.h>
Expand All @@ -17,8 +18,45 @@
#include <helpers/nrfx_reset_reason.h>
#endif

#if defined(CONFIG_HAS_NORDIC_RAM_CTRL)
#include <helpers/nrfx_ram_ctrl.h>
#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
Expand Down

0 comments on commit 49e3fe1

Please sign in to comment.