-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: bluetooth: Add support for hci 3wire
Add support 3wire hci uart. (cherry picked from commit b50e1d5) Original-Signed-off-by: Lingao Meng <menglingao@xiaomi.com> GitOrigin-RevId: b50e1d5 Change-Id: I920aba32cae497f5cab188e362277c9be448b838 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5588623 Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com> Reviewed-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Tristan Honscheid <honscheid@google.com> Tested-by: Tristan Honscheid <honscheid@google.com>
- Loading branch information
Showing
23 changed files
with
1,406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(hci_uart_3wire) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
.. _bluetooth-hci-uart-3wire-sample: | ||
|
||
Bluetooth: HCI UART 3WIRE | ||
######################### | ||
|
||
Overview | ||
********* | ||
|
||
Expose the Zephyr Bluetooth controller support over UART to another device/CPU | ||
using the H:5 HCI transport protocol. | ||
|
||
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) disabled | ||
|
||
Building and Running | ||
******************** | ||
|
||
This sample can be found under :zephyr_file:`samples/bluetooth/hci_uart_3wire` in the | ||
Zephyr tree, and it 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. 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 nRF52840 Development Kit: | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/bluetooth/hci_uart_3wire | ||
:board: nrf52840dk/nrf52840 | ||
:goals: build flash | ||
|
||
.. _bluetooth-hci-uart-3wire-qemu-posix: | ||
|
||
Using the controller with QEMU or native_sim | ||
============================================ | ||
|
||
In order to use the HCI UART H:5 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 hciattach -n /dev/ttyACM0 3wire 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. | ||
|
||
.. note:: | ||
If using the BBC micro:bit you will need to modify the baudrate argument | ||
from ``1000000`` to ``115200``. | ||
|
||
.. 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-3wire-bluez: | ||
|
||
Using the controller with BlueZ | ||
=============================== | ||
|
||
In order to use the HCI UART H:5 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 hciattach -n /dev/ttyACM0 3wire 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. | ||
|
||
.. note:: | ||
If using the BBC micro:bit you will need to modify the baudrate argument | ||
from ``1000000`` to ``115200``. | ||
|
||
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 otherwise 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_3wire -- -DEXTRA_CONF_FILE='debug.conf' | ||
Then attach RTT as described here: :ref:`Using Segger J-Link <Using Segger J-Link>` | ||
|
||
Support for the Direction Finding | ||
================================= | ||
|
||
The sample can be built with the support for the BLE Direction Finding. | ||
To enable this feature build this sample for specific board variants that provide | ||
required hardware configuration for the Radio. | ||
|
||
.. code-block:: console | ||
west build samples/bluetooth/hci_uart_3wire -b nrf52833dk/nrf52833@df -- -DCONFIG_BT_CTLR_DF=y | ||
You can use following targets: | ||
|
||
* ``nrf5340dk/nrf5340/cpunet@df`` | ||
* ``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_3wire/boards/nrf52840dongle_nrf52840.conf` and :zephyr_file:`samples/bluetooth/hci_uart_3wire/boards/nrf52840dongle_nrf52840.overlay`. | ||
|
||
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 H5 | ||
driver instead of the built-in controller: | ||
|
||
.. code-block:: kconfig | ||
CONFIG_BT_HCI=y | ||
CONFIG_BT_CTLR=n | ||
CONFIG_BT_H5=y | ||
Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: | ||
|
||
.. code-block:: dts | ||
/ { | ||
chosen { | ||
zephyr,console = &uart0; | ||
zephyr,shell-uart = &uart0; | ||
zephyr,bt-uart = &uart1; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uart"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CONFIG_MAIN_STACK_SIZE=512 | ||
CONFIG_IDLE_STACK_SIZE=256 | ||
CONFIG_ISR_STACK_SIZE=512 | ||
CONFIG_BT_MAX_CONN=10 | ||
# Revert values set in prj.conf, set them to their Kconfig default value | ||
CONFIG_BT_BUF_CMD_TX_SIZE=65 | ||
CONFIG_BT_BUF_ACL_RX_SIZE=69 | ||
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=43 |
7 changes: 7 additions & 0 deletions
7
samples/bluetooth/hci_uart_3wire/boards/bbc_microbit_v2.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uart"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; |
11 changes: 11 additions & 0 deletions
11
samples/bluetooth/hci_uart_3wire/boards/nrf52833dk_nrf52833.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2022 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uarte"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; |
32 changes: 32 additions & 0 deletions
32
samples/bluetooth/hci_uart_3wire/boards/nrf52833dk_nrf52833_df.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2022 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uarte"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; | ||
|
||
&radio { | ||
status = "okay"; | ||
/* This is an example number of antennas that may be available | ||
* on antenna matrix board. | ||
*/ | ||
dfe-antenna-num = <10>; | ||
/* This is an example switch pattern that will be used to set an | ||
* antenna for Tx PDU (period before start of Tx CTE). | ||
*/ | ||
dfe-pdu-antenna = <0x0>; | ||
|
||
/* These are example GPIO pin numbers that are provided to | ||
* Radio peripheral. The pins will be acquired by Radio to | ||
* drive antenna switching when AoD is enabled. | ||
*/ | ||
dfegpio0-gpios = <&gpio0 3 0>; | ||
dfegpio1-gpios = <&gpio0 4 0>; | ||
dfegpio2-gpios = <&gpio0 28 0>; | ||
dfegpio3-gpios = <&gpio0 29 0>; | ||
}; |
7 changes: 7 additions & 0 deletions
7
samples/bluetooth/hci_uart_3wire/boards/nrf52840dk_nrf52840.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uart"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; |
4 changes: 4 additions & 0 deletions
4
samples/bluetooth/hci_uart_3wire/boards/nrf52840dongle_nrf52840.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CONFIG_USB_DEVICE_STACK=y | ||
CONFIG_USB_DEVICE_PRODUCT="Zephyr HCI UART 3Wire sample" | ||
CONFIG_USB_CDC_ACM=y | ||
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n |
7 changes: 7 additions & 0 deletions
7
samples/bluetooth/hci_uart_3wire/boards/nrf52_blenano2.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uart"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; |
7 changes: 7 additions & 0 deletions
7
samples/bluetooth/hci_uart_3wire/boards/nrf52dk_nrf52832.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uart"; | ||
current-speed = <115200>; | ||
status = "okay"; | ||
}; |
7 changes: 7 additions & 0 deletions
7
samples/bluetooth/hci_uart_3wire/boards/nrf5340dk_nrf5340_cpuapp.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uarte"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; |
7 changes: 7 additions & 0 deletions
7
samples/bluetooth/hci_uart_3wire/boards/nrf5340dk_nrf5340_cpunet.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uarte"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; |
32 changes: 32 additions & 0 deletions
32
samples/bluetooth/hci_uart_3wire/boards/nrf5340dk_nrf5340_cpunet_df.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2022 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uarte"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; | ||
|
||
&radio { | ||
status = "okay"; | ||
/* This is an example number of antennas that may be available | ||
* on antenna matrix board. | ||
*/ | ||
dfe-antenna-num = <10>; | ||
/* This is an example switch pattern that will be used to set an | ||
* antenna for Tx PDU (period before start of Tx CTE). | ||
*/ | ||
dfe-pdu-antenna = <0x0>; | ||
|
||
/* These are example GPIO pin numbers that are provided to | ||
* Radio peripheral. The pins will be acquired by Radio to | ||
* drive antenna switching when AoD is enabled. | ||
*/ | ||
dfegpio0-gpios = <&gpio0 4 0>; | ||
dfegpio1-gpios = <&gpio0 5 0>; | ||
dfegpio2-gpios = <&gpio0 6 0>; | ||
dfegpio3-gpios = <&gpio0 7 0>; | ||
}; |
7 changes: 7 additions & 0 deletions
7
samples/bluetooth/hci_uart_3wire/boards/nrf5340pdk_nrf5340_cpuapp.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
&uart0 { | ||
compatible = "nordic,nrf-uarte"; | ||
current-speed = <1000000>; | ||
status = "okay"; | ||
}; |
4 changes: 4 additions & 0 deletions
4
samples/bluetooth/hci_uart_3wire/boards/nrf9160dk_nrf52840.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Override prj.conf defaults | ||
CONFIG_CONSOLE=y | ||
CONFIG_STDOUT_CONSOLE=y | ||
CONFIG_UART_CONSOLE=y |
19 changes: 19 additions & 0 deletions
19
samples/bluetooth/hci_uart_3wire/boards/nrf9160dk_nrf52840.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2021 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <nrf9160dk_nrf52840_reset_on_if5.dtsi> | ||
|
||
#include <nrf9160dk_uart1_on_if0_3.dtsi> | ||
|
||
&uart1 { | ||
current-speed = <1000000>; | ||
}; | ||
|
||
/ { | ||
chosen { | ||
zephyr,bt-c2h-uart=&uart1; | ||
}; | ||
}; |
8 changes: 8 additions & 0 deletions
8
samples/bluetooth/hci_uart_3wire/boards/nrf9160dk_nrf52840_0_14_0.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (c) 2021 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Use the reset line that is available starting from v0.14.0 of the DK. */ | ||
#include <nrf9160dk_nrf52840_reset_on_if9.dtsi> |
Oops, something went wrong.