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 <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-08-17 14:03:04 +02:00 committed by Carles Cufí
commit a11848fc32

View file

@ -11,19 +11,16 @@
#include <zephyr/sys/printk.h>
#include <zephyr/sys/__assert.h>
#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, ...)