Skip to content

Commit

Permalink
samples: peripheral_power_profiling: Fix the use of PM_DEVICE
Browse files Browse the repository at this point in the history
Fixed the use of Device Power Management and
enabled Runtime Device Power Management.

Ref: NCSDK-30068

Signed-off-by: Marcin Jelinski <[email protected]>
  • Loading branch information
maje-emb authored and rlubos committed Nov 5, 2024
1 parent e2c83bd commit c7dc2fb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
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,19 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/ {
aliases {
/delete-property/ sw2;
/delete-property/ sw3;
};
};

/delete-node/ &button2;
/delete-node/ &button3;

&uart20 {
zephyr,pm-device-runtime-auto;
};
1 change: 0 additions & 1 deletion samples/bluetooth/peripheral_power_profiling/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y

CONFIG_POWEROFF=y
CONFIG_PM_DEVICE=y

CONFIG_MAIN_STACK_SIZE=2048

Expand Down
19 changes: 9 additions & 10 deletions samples/bluetooth/peripheral_power_profiling/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@

#define NFC_BUFFER_SIZE 1024

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

static struct bt_le_oob oob_local;
static uint8_t tk_local[NFC_NDEF_LE_OOB_REC_TK_LEN];
static uint8_t nfc_buffer[NFC_BUFFER_SIZE];
Expand Down Expand Up @@ -628,10 +626,16 @@ static void system_off(void)

dk_set_led_off(RUN_STATUS_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));
}
}

sys_poweroff();
Expand Down Expand Up @@ -665,11 +669,6 @@ int main(void)

printk("Starting Bluetooth Power Profiling example\n");

if (!device_is_ready(cons)) {
printk("%s: device not ready.\n", cons->name);
return 0;
}

err = dk_buttons_init(button_handler);
if (err) {
printk("Failed to initialize buttons (err %d)\n", err);
Expand Down

0 comments on commit c7dc2fb

Please sign in to comment.