Skip to content

Commit

Permalink
samples: nfc: system_off: Optimize power consumption
Browse files Browse the repository at this point in the history
Reduced power usage by disabling RAM retention and
enabling PM_DEVICE_RUNTIME.

Ref: NCSDK-30609

Signed-off-by: Marcin Jelinski <[email protected]>
  • Loading branch information
maje-emb authored and rlubos committed Dec 3, 2024
1 parent 5d6a59c commit 9d8fa22
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
8 changes: 8 additions & 0 deletions samples/nfc/system_off/boards/nrf54l15dk_nrf54l15_cpuapp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

&uart20 {
zephyr,pm-device-runtime-auto;
};
1 change: 0 additions & 1 deletion samples/nfc/system_off/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ CONFIG_NFC_NDEF_MSG=y
CONFIG_NFC_NDEF_RECORD=y
CONFIG_NFC_NDEF_TEXT_RECORD=y
CONFIG_POWEROFF=y
CONFIG_PM_DEVICE=y
32 changes: 20 additions & 12 deletions samples/nfc/system_off/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include <nfc/ndef/text_rec.h>

#include <dk_buttons_and_leds.h>

#ifdef CONFIG_SOC_NRF54L15_CPUAPP
#include <hal/nrf_memconf.h>
#endif

#define SYSTEM_OFF_DELAY_S 3

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

const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));

/**
* @brief Function that receives events from NFC.
*/
Expand Down Expand Up @@ -138,12 +138,26 @@ static void system_off(struct k_work *work)

dk_set_led_off(SYSTEM_ON_LED);

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

if (rc < 0) {
printk("Could not suspend console (%d)\n", rc);
if (dev) {
do {
err = pm_device_state_get(dev, &state);
} while ((err == 0) && (state == PM_DEVICE_STATE_ACTIVE));
}
}

#ifdef CONFIG_SOC_NRF54L15_CPUAPP
/* Disable RAM retention in System OFF as it is not utilized by this sample. */
uint32_t ram_sections = 8;

nrf_memconf_ramblock_ret_mask_enable_set(NRF_MEMCONF, 0, BIT_MASK(ram_sections), false);
nrf_memconf_ramblock_ret2_mask_enable_set(NRF_MEMCONF, 0, BIT_MASK(ram_sections), false);
#endif

sys_poweroff();
}

Expand Down Expand Up @@ -194,12 +208,6 @@ static void print_reset_reason(void)

int main(void)
{
/* Check whether the console is enabled and ready */
if (!device_is_ready(cons)) {
printk("%s: device not ready.\n", cons->name);
return 0;
}

/* Configure LED-pins */
if (dk_leds_init() < 0) {
printk("Cannot init LEDs!\n");
Expand Down

0 comments on commit 9d8fa22

Please sign in to comment.