From 6ca3e2742b176a7bdc43269eb0bf65c5a7c8149c Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 30 Oct 2024 16:13:13 +0200 Subject: [PATCH] Bluetooth: Host: Fix monitor UART selection Most boards set zephyr,bt-mon-uart to point at the same device as zephyr,console. It's still useful to have the possibility of having these as two different devices, however it's useful to fall back to the UART console in case a dedicated monitor UART hasn't been specified. This also ensures that the fallback only happens if the console UART isn't enabled, but a DT chosen property exists for it. Additionally, we now get a user friendly error in case the Bluetooth UART monitor feature has been enabled in Kconfig but there isn't a suitable UART available for it in devicetree. Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/monitor.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/subsys/bluetooth/host/monitor.c b/subsys/bluetooth/host/monitor.c index bf434daaf9cfa..a02f115c966a5 100644 --- a/subsys/bluetooth/host/monitor.c +++ b/subsys/bluetooth/host/monitor.c @@ -150,7 +150,15 @@ static void poll_out(char c) } #elif defined(CONFIG_BT_DEBUG_MONITOR_UART) static const struct device *const monitor_dev = +#if DT_HAS_CHOSEN(zephyr_bt_mon_uart) DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_mon_uart)); +#elif !defined(CONFIG_UART_CONSOLE) && DT_HAS_CHOSEN(zephyr_console) + /* Fall back to console UART if it's available */ + DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); +#else + NULL; +#error "BT_DEBUG_MONITOR_UART enabled but no UART specified" +#endif static void poll_out(char c) {