diff --git a/samples/bluetooth/hci_uart/README.rst b/samples/bluetooth/hci_uart/README.rst index 85b1cfa86fe8d..335a812c56a17 100644 --- a/samples/bluetooth/hci_uart/README.rst +++ b/samples/bluetooth/hci_uart/README.rst @@ -143,3 +143,8 @@ You can use following targets: * ``nrf52833dk_nrf52833@df`` Check the :ref:`bluetooth_direction_finding_connectionless_rx` and the :ref:`bluetooth_direction_finding_connectionless_tx` for more details. + +Using a USB CDC ACM UART +======================== + +The sample can be configured to use a USB UART instead. See :zephyr_file:`samples/bluetooth/hci_uart/nrf52840dongle_nrf52840.conf` and :zephyr_file:`samples/bluetooth/hci_uart/nrf52840dongle_nrf52840.overlay`. diff --git a/samples/bluetooth/hci_uart/boards/nrf52840dongle_nrf52840.conf b/samples/bluetooth/hci_uart/boards/nrf52840dongle_nrf52840.conf new file mode 100644 index 0000000000000..b805adbec27f6 --- /dev/null +++ b/samples/bluetooth/hci_uart/boards/nrf52840dongle_nrf52840.conf @@ -0,0 +1,3 @@ +CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_PRODUCT="Zephyr HCI UART sample" +CONFIG_USB_CDC_ACM=y diff --git a/samples/bluetooth/hci_uart/boards/nrf52840dongle_nrf52840.overlay b/samples/bluetooth/hci_uart/boards/nrf52840dongle_nrf52840.overlay new file mode 100644 index 0000000000000..fc41e617a1ea5 --- /dev/null +++ b/samples/bluetooth/hci_uart/boards/nrf52840dongle_nrf52840.overlay @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +&zephyr_udc0 { + cdc_acm_uart0: cdc_acm_uart0 { + compatible = "zephyr,cdc-acm-uart"; + label = "CDC_ACM_0"; + }; +}; + +/ { + chosen { + zephyr,bt-c2h-uart = &cdc_acm_uart0; + }; +}; diff --git a/samples/bluetooth/hci_uart/src/main.c b/samples/bluetooth/hci_uart/src/main.c index a93ab0cf52e9b..6accd9ee49768 100644 --- a/samples/bluetooth/hci_uart/src/main.c +++ b/samples/bluetooth/hci_uart/src/main.c @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -328,6 +330,13 @@ static int hci_uart_init(const struct device *unused) { LOG_DBG(""); + if (IS_ENABLED(CONFIG_USB_CDC_ACM)) { + if (usb_enable(NULL)) { + LOG_ERR("Failed to enable USB"); + return -EINVAL; + } + } + if (!device_is_ready(hci_uart_dev)) { LOG_ERR("HCI UART %s is not ready", hci_uart_dev->name); return -EINVAL;