zephyr/samples/bluetooth/hci_uart_async
Ivan Iushkov 0b71206054 bluetooth: samples: Add missing option to hci_uart_async sample
hci_uart_async/debug.mixin.conf is used to enable RTT logging
for hci_uart_async sample. RTT can be used to avoid conflict
between different serial interfaces because the sample uses
UART as an interface for HCI communication.
RTT_CONSOLE option enabled in the debug.mixin.conf depends on
CONFIG_USE_SEGGER_RTT so enabling CONFIG_USE_SEGGER_RTT by
default makes it easier to build the project with RTT enabled

Signed-off-by: Ivan Iushkov <ivan.iushkov@nordicsemi.no>
2024-06-18 11:05:50 +02:00
..
boards boards: nrf52_bsim: Add support for using UART as HCI 2024-06-11 19:42:49 -04:00
src Bluetooth: samples: hci_uart_async: Remove bt_recv() dependency 2024-06-11 19:42:49 -04:00
app.overlay
CMakeLists.txt
debug.mixin.conf bluetooth: samples: Add missing option to hci_uart_async sample 2024-06-18 11:05:50 +02:00
prj.conf
README.rst Bluetooth: doc: Update documentation for the new HCI API 2024-06-11 19:42:49 -04:00
sample.yaml hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00

.. _bluetooth-hci-uart-async-sample:

Bluetooth: HCI UART based on ASYNC UART
#######################################

Expose a Zephyr Bluetooth Controller over a standard Bluetooth HCI UART interface.

This sample performs the same basic function as the HCI UART sample, but it uses the UART_ASYNC_API
instead of UART_INTERRUPT_DRIVEN API. Not all boards implement both UART APIs, so the board support
of the HCI UART sample may be different.

Requirements
************

* A board with BLE support

Default UART settings
*********************

By default the controller builds use the following settings:

* Baudrate: 1Mbit/s
* 8 bits, no parity, 1 stop bit
* Hardware Flow Control (RTS/CTS) enabled

Building and Running
********************

This sample can be found under :zephyr_file:`samples/bluetooth/hci_uart_async`
in the Zephyr tree and is built as a standard Zephyr application.

Using the controller with emulators and BlueZ
*********************************************

The instructions below show how to use a Nordic nRF5x device as a Zephyr BLE
controller and expose it to Linux's BlueZ.

First, make sure you have a recent BlueZ version installed by following the
instructions in the :ref:`bluetooth_bluez` section.

Now build and flash the sample for the Nordic nRF5x board of your choice.
All of the Nordic Development Kits come with a Segger IC that provides a
debugger interface and a CDC ACM serial port bridge. More information can be
found in :ref:`nordic_segger`.

For example, to build for the nRF52832 Development Kit:

.. zephyr-app-commands::
   :zephyr-app: samples/bluetooth/hci_uart_async
   :board: nrf52dk/nrf52832
   :goals: build flash

.. _bluetooth-hci-uart-async-qemu-posix:

Using the controller with QEMU or native_sim
============================================

In order to use the HCI UART controller with QEMU or :ref:`native_sim <native_sim>` you will need
to attach it to the Linux Host first. To do so simply build the sample and
connect the UART to the Linux machine, and then attach it with this command:

.. code-block:: console

   sudo btattach -B /dev/ttyACM0 -S 1000000 -R

.. note::
   Depending on the serial port you are using you will need to modify the
   ``/dev/ttyACM0`` string to point to the serial device your controller is
   connected to.

.. note::
   The ``-R`` flag passed to ``btattach`` instructs the kernel to avoid
   interacting with the controller and instead just be aware of it in order
   to proxy it to QEMU later.

If you are running :file:`btmon` you should see a brief log showing how the
Linux kernel identifies the attached controller.

Once the controller is attached follow the instructions in the
:ref:`bluetooth_qemu_native` section to use QEMU with it.

.. _bluetooth-hci-uart-async-bluez:

Using the controller with BlueZ
===============================

In order to use the HCI UART controller with BlueZ you will need to attach it
to the Linux Host first. To do so simply build the sample and connect the
UART to the Linux machine, and then attach it with this command:

.. code-block:: console

   sudo btattach -B /dev/ttyACM0 -S 1000000

.. note::
   Depending on the serial port you are using you will need to modify the
   ``/dev/ttyACM0`` string to point to the serial device your controller is
   connected to.

If you are running :file:`btmon` you should see a comprehensive log showing how
BlueZ loads and initializes the attached controller.

Once the controller is attached follow the instructions in the
:ref:`bluetooth_ctlr_bluez` section to use BlueZ with it.

Debugging the controller
========================

The sample can be debugged using RTT since the UART is reserved used by this
application. To enable debug over RTT the debug configuration file can be used.

.. code-block:: console

   west build samples/bluetooth/hci_uart_async -- -DEXTRA_CONFIG='debug.mixin.conf'

Then attach RTT as described here: :ref:`Using Segger J-Link <Using Segger J-Link>`

Using the controller with the Zephyr host
=========================================

This describes how to hook up a board running this sample to a board running
an application that uses the Zephyr host.

On the controller side, the `zephyr,bt-c2h-uart` DTS property (in the `chosen`
block) is used to select which uart device to use. For example if we want to
keep the console logs, we can keep console on uart0 and the HCI on uart1 like
so:

.. code-block:: dts

   / {
      chosen {
         zephyr,console = &uart0;
         zephyr,shell-uart = &uart0;
         zephyr,bt-c2h-uart = &uart1;
      };
   };

On the host application, some config options need to be used to select the H4
driver instead of the built-in controller:

.. code-block:: kconfig

   CONFIG_BT_HCI=y
   CONFIG_BT_CTLR=n

Similarly, the `zephyr,bt-hci` DTS property selects which HCI instance to use.
The UART needs to have as its child node a HCI UART node:

.. code-block:: dts

   / {
      chosen {
         zephyr,console = &uart0;
         zephyr,shell-uart = &uart0;
         zephyr,bt-hci = &bt_hci_uart;
      };
   };

   &uart1 {
      status = "okay";
      bt_hci_uart: bt_hci_uart {
         compatible = "zephyr,bt-hci-uart";
         status = "okay";
      };
   };