2017-04-05 03:06:31 +08:00
|
|
|
.. _bluetooth-hci-uart-sample:
|
|
|
|
|
2017-01-20 09:42:36 +08:00
|
|
|
Bluetooth: HCI UART
|
|
|
|
####################
|
|
|
|
|
|
|
|
Overview
|
|
|
|
*********
|
|
|
|
|
2018-03-21 21:39:15 +08:00
|
|
|
Expose the Zephyr Bluetooth controller support over UART to another device/CPU
|
|
|
|
using the H:4 HCI transport protocol (requires HW flow control from the UART).
|
2017-01-20 09:42:36 +08:00
|
|
|
|
|
|
|
Requirements
|
|
|
|
************
|
|
|
|
|
|
|
|
* A board with BLE support
|
|
|
|
|
2018-03-21 21:39:15 +08:00
|
|
|
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
|
|
|
|
|
2017-01-20 09:42:36 +08:00
|
|
|
Building and Running
|
|
|
|
********************
|
2018-03-21 21:39:15 +08:00
|
|
|
|
2019-03-09 06:21:37 +08:00
|
|
|
This sample can be found under :zephyr_file:`samples/bluetooth/hci_uart` in the
|
2018-03-21 21:39:15 +08:00
|
|
|
Zephyr tree, and it is built as a standard Zephyr application.
|
|
|
|
|
2019-03-07 22:59:20 +08:00
|
|
|
Using the controller with emulators and BlueZ
|
|
|
|
*********************************************
|
2018-03-21 21:39:15 +08:00
|
|
|
|
|
|
|
The instructions below show how to use a Nordic nRF5x device as a Zephyr BLE
|
|
|
|
controller and expose it to Linux's BlueZ. This can be very useful for testing
|
|
|
|
the Zephyr Link Layer with the BlueZ Host. The Zephyr BLE controller can also
|
|
|
|
provide a modern BLE 5.0 controller to a Linux-based machine for native
|
|
|
|
BLE support or QEMU-based development.
|
|
|
|
|
|
|
|
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
|
|
|
|
:board: nrf52_pca10040
|
|
|
|
:goals: build flash
|
|
|
|
|
2019-03-07 22:59:20 +08:00
|
|
|
.. _bluetooth-hci-uart-qemu-posix:
|
2018-04-04 01:11:09 +08:00
|
|
|
|
2019-03-07 22:59:20 +08:00
|
|
|
Using the controller with QEMU and Native POSIX
|
|
|
|
===============================================
|
2018-03-21 21:39:15 +08:00
|
|
|
|
2019-03-07 22:59:20 +08:00
|
|
|
In order to use the HCI UART controller with QEMU or Native POSIX 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:
|
2018-03-21 21:39:15 +08:00
|
|
|
|
|
|
|
.. 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.
|
|
|
|
|
2018-10-24 18:55:40 +08:00
|
|
|
.. note::
|
|
|
|
If using the BBC micro:bit you will need to modify the baudrate argument
|
|
|
|
from ``1000000`` to ``115200``.
|
|
|
|
|
2018-03-21 21:39:15 +08:00
|
|
|
.. 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
|
2019-03-07 22:59:20 +08:00
|
|
|
:ref:`bluetooth_qemu_posix` section to use QEMU with it.
|
2018-03-21 21:39:15 +08:00
|
|
|
|
2018-04-04 01:11:09 +08:00
|
|
|
.. _bluetooth-hci-uart-bluez:
|
|
|
|
|
2018-03-21 21:39:15 +08:00
|
|
|
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.
|
|
|
|
|
2018-10-24 18:55:40 +08:00
|
|
|
.. note::
|
|
|
|
If using the BBC micro:bit you will need to modify the baudrate argument
|
|
|
|
from ``1000000`` to ``115200``.
|
|
|
|
|
2018-03-21 21:39:15 +08:00
|
|
|
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.
|
2017-01-20 09:42:36 +08:00
|
|
|
|