Skip to content

Commit 9d8fa22

Browse files
maje-embrlubos
authored andcommitted
samples: nfc: system_off: Optimize power consumption
Reduced power usage by disabling RAM retention and enabling PM_DEVICE_RUNTIME. Ref: NCSDK-30609 Signed-off-by: Marcin Jelinski <[email protected]>
1 parent 5d6a59c commit 9d8fa22

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_PM_DEVICE=y
8+
CONFIG_PM_DEVICE_RUNTIME=y
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&uart20 {
8+
zephyr,pm-device-runtime-auto;
9+
};

samples/nfc/system_off/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ CONFIG_NFC_NDEF_MSG=y
1515
CONFIG_NFC_NDEF_RECORD=y
1616
CONFIG_NFC_NDEF_TEXT_RECORD=y
1717
CONFIG_POWEROFF=y
18-
CONFIG_PM_DEVICE=y

samples/nfc/system_off/src/main.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include <nfc/ndef/text_rec.h>
2121

2222
#include <dk_buttons_and_leds.h>
23-
23+
#ifdef CONFIG_SOC_NRF54L15_CPUAPP
24+
#include <hal/nrf_memconf.h>
25+
#endif
2426

2527
#define SYSTEM_OFF_DELAY_S 3
2628

@@ -34,8 +36,6 @@
3436
/* Delayed work that enters system off. */
3537
static struct k_work_delayable system_off_work;
3638

37-
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
38-
3939
/**
4040
* @brief Function that receives events from NFC.
4141
*/
@@ -138,12 +138,26 @@ static void system_off(struct k_work *work)
138138

139139
dk_set_led_off(SYSTEM_ON_LED);
140140

141-
int rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
141+
if (IS_ENABLED(CONFIG_PM_DEVICE) && IS_ENABLED(CONFIG_SERIAL)) {
142+
static const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
143+
int err;
144+
enum pm_device_state state;
142145

143-
if (rc < 0) {
144-
printk("Could not suspend console (%d)\n", rc);
146+
if (dev) {
147+
do {
148+
err = pm_device_state_get(dev, &state);
149+
} while ((err == 0) && (state == PM_DEVICE_STATE_ACTIVE));
150+
}
145151
}
146152

153+
#ifdef CONFIG_SOC_NRF54L15_CPUAPP
154+
/* Disable RAM retention in System OFF as it is not utilized by this sample. */
155+
uint32_t ram_sections = 8;
156+
157+
nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, BIT_MASK(ram_sections), false);
158+
nrf_memconf_ramblock_ret2_mask_enable_set(NRF_MEMCONF, 0, BIT_MASK(ram_sections), false);
159+
#endif
160+
147161
sys_poweroff();
148162
}
149163

@@ -194,12 +208,6 @@ static void print_reset_reason(void)
194208

195209
int main(void)
196210
{
197-
/* Check whether the console is enabled and ready */
198-
if (!device_is_ready(cons)) {
199-
printk("%s: device not ready.\n", cons->name);
200-
return 0;
201-
}
202-
203211
/* Configure LED-pins */
204212
if (dk_leds_init() < 0) {
205213
printk("Cannot init LEDs!\n");

0 commit comments

Comments
 (0)