Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/retained_mem/Kconfig.nrf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ config RETAINED_MEM_NRF_RAM_CTRL
bool "nRF RAM retention driver"
default y
depends on DT_HAS_ZEPHYR_RETAINED_RAM_ENABLED && RETAINED_MEM_ZEPHYR_RAM && POWEROFF
depends on SOC_FAMILY_NORDIC_NRF
depends on HAS_NORDIC_RAM_CTRL
help
Enable driver for Nordic RAM retention.
5 changes: 2 additions & 3 deletions drivers/retained_mem/retained_mem_nrf_ram_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <zephyr/devicetree.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/retained_mem/nrf_retained_mem.h>

#include <helpers/nrfx_ram_ctrl.h>

Expand All @@ -22,7 +23,7 @@ static const struct ret_mem_region ret_mem_regions[] = {
DT_FOREACH_STATUS_OKAY(zephyr_retained_ram, _BUILD_MEM_REGION)
};

static int retained_mem_nrf_init(void)
int z_nrf_retained_mem_retention_apply(void)
{
const struct ret_mem_region *rmr;

Expand All @@ -33,5 +34,3 @@ static int retained_mem_nrf_init(void)

return 0;
}

SYS_INIT(retained_mem_nrf_init, PRE_KERNEL_1, 0);
36 changes: 36 additions & 0 deletions include/zephyr/drivers/retained_mem/nrf_retained_mem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_DRIVERS_RETAINED_MEM_NRF_RETAINED_MEM_H
#define ZEPHYR_INCLUDE_DRIVERS_RETAINED_MEM_NRF_RETAINED_MEM_H

#ifdef __cplusplus
extern "C" {
#endif

#include <zephyr/drivers/retained_mem.h>

#if defined(CONFIG_RETAINED_MEM_NRF_RAM_CTRL) || defined(__DOXYGEN__)
/** @brief Apply memory retention settings.
*
* Memory retention settings to apply are derived from devicetree configuration.
*
* @retval 0 if the retention settings were applied successfully.
* @retval -ENOTSUP if retention configuration is not present in devicetree.
*/
int z_nrf_retained_mem_retention_apply(void);
#else
static inline int z_nrf_retained_mem_retention_apply(void)
{
return -ENOTSUP;
}
#endif

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_INCLUDE_DRIVERS_RETAINED_MEM_NRF_RETAINED_MEM_H */
2 changes: 1 addition & 1 deletion modules/hal_nordic/nrfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF92X ${MDK_DIR}/system_nrf92.c

zephyr_library_sources(nrfx_glue.c)
zephyr_library_sources(${HELPERS_DIR}/nrfx_flag32_allocator.c)
zephyr_library_sources_ifdef(CONFIG_RETAINED_MEM_NRF_RAM_CTRL ${HELPERS_DIR}/nrfx_ram_ctrl.c)
zephyr_library_sources_ifdef(CONFIG_HAS_NORDIC_RAM_CTRL ${HELPERS_DIR}/nrfx_ram_ctrl.c)
zephyr_library_sources_ifdef(CONFIG_NRFX_GPPI ${HELPERS_DIR}/nrfx_gppi_dppi.c)
zephyr_library_sources_ifdef(CONFIG_NRFX_PPI ${HELPERS_DIR}/nrfx_gppi_ppi.c)

Expand Down
2 changes: 1 addition & 1 deletion samples/boards/nordic/system_off/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(nrf_system_off)

target_sources(app PRIVATE src/main.c)
if (CONFIG_APP_USE_NRF_RETENTION OR CONFIG_APP_USE_RETAINED_MEM)
if (CONFIG_APP_USE_RETAINED_MEM)
target_sources(app PRIVATE src/retained.c)
endif()
16 changes: 1 addition & 15 deletions samples/boards/nordic/system_off/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,9 @@

mainmenu "Nordic SYSTEM_OFF demo"

choice
prompt "Use retention"
optional

config APP_USE_NRF_RETENTION
bool "Use state retention in system off using nRF POWER"
depends on SOC_COMPATIBLE_NRF52X && CRC
help
On some Nordic chips this application supports retaining
memory while in system off using POWER peripheral.
Select this to enable the feature.

config APP_USE_RETAINED_MEM
bool "Use state retention in system off using retained_mem driver"
depends on RETAINED_MEM

endchoice
select RETAINED_MEM

config GRTC_WAKEUP_ENABLE
bool "Use GRTC to wake up device from system off"
Expand Down
8 changes: 4 additions & 4 deletions samples/boards/nordic/system_off/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ deep sleep on Nordic platforms.
RAM Retention
=============

This sample can also can demonstrate RAM retention. By selecting
``CONFIG_APP_USE_NRF_RETENTION=y`` or ``CONFIG_APP_USE_RETAINED_MEM=y``
state related to number of boots, number of times system off was entered,
and total uptime since initial power-on are retained in a checksummed data structure.
This sample can also demonstrate RAM retention.
By selecting ``CONFIG_APP_USE_RETAINED_MEM=y`` state related to number of boots,
number of times system off was entered, and total uptime since initial power-on
are retained in a checksummed data structure.
RAM is configured to keep the containing section powered while in system-off mode.

Requirements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/ {
sram0@2003f000 {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x2003f000 DT_SIZE_K(4)>;
zephyr,memory-region = "RetainedMem";
status = "okay";

retainedmem0: retainedmem {
compatible = "zephyr,retained-ram";
status = "okay";
};
};

aliases {
retainedmemdevice = &retainedmem0;
};
};

&sram0 {
/* Shrink SRAM size to avoid overlap with retained memory region */
reg = <0x20000000 DT_SIZE_K(252)>;
};
22 changes: 22 additions & 0 deletions samples/boards/nordic/system_off/boards/nrf52dk_nrf52832.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/ {
sram0@20007000 {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x20007000 DT_SIZE_K(4)>;
zephyr,memory-region = "RetainedMem";
status = "okay";

retainedmem0: retainedmem {
compatible = "zephyr,retained-ram";
status = "okay";
};
};

aliases {
retainedmemdevice = &retainedmem0;
};
};

&sram0 {
/* Shrink SRAM size to avoid overlap with retained memory region */
reg = <0x20000000 DT_SIZE_K(28)>;
};
27 changes: 7 additions & 20 deletions samples/boards/nordic/system_off/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,17 @@ tests:
- "system off demo"
- "Retained data not supported"
- "Entering system off; press sw0 to restart"
sample.boards.nrf.system_off.nrf_retained:
sample.boards.nrf.system_off.retained_mem:
integration_platforms:
- nrf52840dk/nrf52840
platform_allow:
- nrf52840dk/nrf52840
- nrf52dk/nrf52832
extra_configs:
- CONFIG_APP_USE_NRF_RETENTION=y
harness: console
harness_config:
type: multi_line
ordered: true
regex:
- "system off demo"
- "Retained data: INVALID"
- "Boot count: 1"
- "Off count: 0"
- "Active Ticks:"
- "Entering system off; press sw0 to restart"
sample.boards.nrf.system_off.retained_mem:
extra_args: DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_retained_mem.overlay"
platform_allow:
- nrf54l15dk/nrf54l15/cpuapp
- nrf54l15dk/nrf54l10/cpuapp
- nrf54l15dk/nrf54l05/cpuapp
extra_configs:
- CONFIG_APP_USE_RETAINED_MEM=y
- CONFIG_RETAINED_MEM=y
harness: console
harness_config:
type: multi_line
Expand All @@ -62,6 +47,8 @@ tests:
sample.boards.nrf.system_off.grtc_wakeup:
platform_allow:
- nrf54l15dk/nrf54l15/cpuapp
- nrf54l15dk/nrf54l10/cpuapp
- nrf54l15dk/nrf54l05/cpuapp
extra_configs:
- CONFIG_GRTC_WAKEUP_ENABLE=y
harness: console
Expand All @@ -79,13 +66,13 @@ tests:
- "Retained data not supported"
- "Entering system off; wait 2 seconds to restart"
sample.boards.nrf.system_off.retained_mem.grtc_wakeup:
extra_args: DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_retained_mem.overlay"
platform_allow:
- nrf54l15dk/nrf54l15/cpuapp
- nrf54l15dk/nrf54l10/cpuapp
- nrf54l15dk/nrf54l05/cpuapp
extra_configs:
- CONFIG_APP_USE_RETAINED_MEM=y
- CONFIG_GRTC_WAKEUP_ENABLE=y
- CONFIG_RETAINED_MEM=y
harness: console
harness_config:
type: multi_line
Expand Down
4 changes: 2 additions & 2 deletions samples/boards/nordic/system_off/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(void)

printf("\n%s system off demo\n", CONFIG_BOARD);

if (IS_ENABLED(CONFIG_APP_USE_NRF_RETENTION) || IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {
if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {
bool retained_ok = retained_validate();

/* Increment for this boot attempt and update. */
Expand Down Expand Up @@ -81,7 +81,7 @@ int main(void)
return 0;
}

if (IS_ENABLED(CONFIG_APP_USE_NRF_RETENTION) || IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {
if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {
/* Update the retained state */
retained.off_count += 1;
retained_update();
Expand Down
Loading
Loading