Skip to content

Commit 3cba05b

Browse files
maje-embrlubos
authored andcommitted
samples: peripheral_power_profiling: Add console suspend in system_off
Added console suspend before `sys_poweroff` to reduce power usage. Ref: NCSDK-29688 Signed-off-by: Marcin Jelinski <[email protected]>
1 parent e649abe commit 3cba05b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

samples/bluetooth/peripheral_power_profiling/prj.conf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
CONFIG_NCS_SAMPLES_DEFAULTS=y
8-
97
CONFIG_BT=y
108
CONFIG_BT_SMP=y
119
CONFIG_BT_PERIPHERAL=y
@@ -31,5 +29,9 @@ CONFIG_FLASH_PAGE_LAYOUT=y
3129
CONFIG_FLASH_MAP=y
3230

3331
CONFIG_POWEROFF=y
32+
CONFIG_PM_DEVICE=y
3433

3534
CONFIG_MAIN_STACK_SIZE=2048
35+
36+
CONFIG_BT_ASSERT=n
37+
CONFIG_ASSERT_VERBOSE=n

samples/bluetooth/peripheral_power_profiling/src/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <zephyr/kernel.h>
1010
#include <zephyr/sys/poweroff.h>
11+
#include <zephyr/pm/device.h>
1112
#include <zephyr/sys/atomic.h>
1213
#include <zephyr/settings/settings.h>
1314

@@ -57,6 +58,8 @@
5758

5859
#define NFC_BUFFER_SIZE 1024
5960

61+
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
62+
6063
static struct bt_le_oob oob_local;
6164
static uint8_t tk_local[NFC_NDEF_LE_OOB_REC_TK_LEN];
6265
static uint8_t nfc_buffer[NFC_BUFFER_SIZE];
@@ -625,6 +628,12 @@ static void system_off(void)
625628

626629
dk_set_led_off(RUN_STATUS_LED);
627630

631+
int rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
632+
633+
if (rc < 0) {
634+
printk("Could not suspend console (%d)\n", rc);
635+
}
636+
628637
sys_poweroff();
629638
}
630639

@@ -656,6 +665,11 @@ int main(void)
656665

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

668+
if (!device_is_ready(cons)) {
669+
printk("%s: device not ready.\n", cons->name);
670+
return 0;
671+
}
672+
659673
err = dk_buttons_init(button_handler);
660674
if (err) {
661675
printk("Failed to initialize buttons (err %d)\n", err);

0 commit comments

Comments
 (0)