From a11848fc32d88b48e5b43b59a79990f05b81d9dd Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 17 Aug 2022 14:03:04 +0200 Subject: [PATCH] samples: boards: stm32: serial_wakeup: fix device usage issues Device ready check was wrong (< 0 ?!), so fix it. Also drop static qualifier for the device variable (not needed) and initialize at definition time. Signed-off-by: Gerard Marull-Paretas --- .../stm32/power_mgmt/serial_wakeup/src/main.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/samples/boards/stm32/power_mgmt/serial_wakeup/src/main.c b/samples/boards/stm32/power_mgmt/serial_wakeup/src/main.c index 8ba5aefed72..8d749c338c7 100644 --- a/samples/boards/stm32/power_mgmt/serial_wakeup/src/main.c +++ b/samples/boards/stm32/power_mgmt/serial_wakeup/src/main.c @@ -11,19 +11,16 @@ #include #include -#define DEV_NAME DT_CHOSEN(zephyr_console) - void main(void) { - static const struct device *dev; + const struct device *const dev = + DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); - dev = DEVICE_DT_GET(DEV_NAME); - if (dev < 0) { - printk("Failed to get device"); + if (!device_is_ready(dev)) { + printk("Console device not ready"); + return; } - printk("Device ready\n"); - #if CONFIG_PM_DEVICE /* In PM_DEVICE modes, enable device as a wakeup source will prevent * system to switch it off (clock off, set pins to sleep configuration, ...)