samples/bluetooth/hci_uart: Add support for USB CDC UART.

This PR adds support using the USB CDC UART in the hci_uart sample,
including sample configuration for the nRF 52840 dongle.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2022-09-21 11:20:07 +10:00 committed by Carles Cufí
parent a96dfe9ce9
commit e1c134a582
4 changed files with 31 additions and 0 deletions

View file

@ -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`.

View file

@ -0,0 +1,3 @@
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr HCI UART sample"
CONFIG_USB_CDC_ACM=y

View file

@ -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;
};
};

View file

@ -20,6 +20,8 @@
#include <zephyr/init.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/usb/usb_device.h>
#include <zephyr/net/buf.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/l2cap.h>
@ -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;