Skip to content

Commit b50e1d5

Browse files
LingaoMcarlescufi
authored andcommitted
samples: bluetooth: Add support for hci 3wire
Add support 3wire hci uart. Signed-off-by: Lingao Meng <[email protected]>
1 parent adfa334 commit b50e1d5

23 files changed

+1406
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(hci_uart_3wire)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
.. _bluetooth-hci-uart-3wire-sample:
2+
3+
Bluetooth: HCI UART 3WIRE
4+
#########################
5+
6+
Overview
7+
*********
8+
9+
Expose the Zephyr Bluetooth controller support over UART to another device/CPU
10+
using the H:5 HCI transport protocol.
11+
12+
Requirements
13+
************
14+
15+
* A board with BLE support
16+
17+
Default UART settings
18+
*********************
19+
20+
By default the controller builds use the following settings:
21+
22+
* Baudrate: 1Mbit/s
23+
* 8 bits, no parity, 1 stop bit
24+
* Hardware Flow Control (RTS/CTS) disabled
25+
26+
Building and Running
27+
********************
28+
29+
This sample can be found under :zephyr_file:`samples/bluetooth/hci_uart_3wire` in the
30+
Zephyr tree, and it is built as a standard Zephyr application.
31+
32+
Using the controller with emulators and BlueZ
33+
*********************************************
34+
35+
The instructions below show how to use a Nordic nRF5x device as a Zephyr BLE
36+
controller and expose it to Linux's BlueZ. This can be very useful for testing
37+
the Zephyr Link Layer with the BlueZ Host. The Zephyr BLE controller can also
38+
provide a modern BLE 5.0 controller to a Linux-based machine for native
39+
BLE support or QEMU-based development.
40+
41+
First, make sure you have a recent BlueZ version installed by following the
42+
instructions in the :ref:`bluetooth_bluez` section.
43+
44+
Now build and flash the sample for the Nordic nRF5x board of your choice.
45+
All of the Nordic Development Kits come with a Segger IC that provides a
46+
debugger interface and a CDC ACM serial port bridge. More information can be
47+
found in :ref:`nordic_segger`.
48+
49+
For example, to build for the nRF52840 Development Kit:
50+
51+
.. zephyr-app-commands::
52+
:zephyr-app: samples/bluetooth/hci_uart_3wire
53+
:board: nrf52840dk/nrf52840
54+
:goals: build flash
55+
56+
.. _bluetooth-hci-uart-3wire-qemu-posix:
57+
58+
Using the controller with QEMU or native_sim
59+
============================================
60+
61+
In order to use the HCI UART H:5 controller with QEMU or :ref:`native_sim <native_sim>` you will
62+
need to attach it to the Linux Host first. To do so simply build the sample and
63+
connect the UART to the Linux machine, and then attach it with this command:
64+
65+
.. code-block:: console
66+
67+
sudo hciattach -n /dev/ttyACM0 3wire 1000000
68+
69+
.. note::
70+
Depending on the serial port you are using you will need to modify the
71+
``/dev/ttyACM0`` string to point to the serial device your controller is
72+
connected to.
73+
74+
.. note::
75+
If using the BBC micro:bit you will need to modify the baudrate argument
76+
from ``1000000`` to ``115200``.
77+
78+
.. note::
79+
The ``-R`` flag passed to ``btattach`` instructs the kernel to avoid
80+
interacting with the controller and instead just be aware of it in order
81+
to proxy it to QEMU later.
82+
83+
If you are running :file:`btmon` you should see a brief log showing how the
84+
Linux kernel identifies the attached controller.
85+
86+
Once the controller is attached follow the instructions in the
87+
:ref:`bluetooth_qemu_native` section to use QEMU with it.
88+
89+
.. _bluetooth-hci-uart-3wire-bluez:
90+
91+
Using the controller with BlueZ
92+
===============================
93+
94+
In order to use the HCI UART H:5 controller with BlueZ you will need to attach it
95+
to the Linux Host first. To do so simply build the sample and connect the
96+
UART to the Linux machine, and then attach it with this command:
97+
98+
.. code-block:: console
99+
100+
sudo hciattach -n /dev/ttyACM0 3wire 1000000
101+
102+
.. note::
103+
Depending on the serial port you are using you will need to modify the
104+
``/dev/ttyACM0`` string to point to the serial device your controller is
105+
connected to.
106+
107+
.. note::
108+
If using the BBC micro:bit you will need to modify the baudrate argument
109+
from ``1000000`` to ``115200``.
110+
111+
If you are running :file:`btmon` you should see a comprehensive log showing how
112+
BlueZ loads and initializes the attached controller.
113+
114+
Once the controller is attached follow the instructions in the
115+
:ref:`bluetooth_ctlr_bluez` section to use BlueZ with it.
116+
117+
Debugging the controller
118+
========================
119+
120+
The sample can be debugged using RTT since the UART is otherwise used by this
121+
application. To enable debug over RTT the debug configuration file can be used.
122+
123+
.. code-block:: console
124+
125+
west build samples/bluetooth/hci_uart_3wire -- -DEXTRA_CONF_FILE='debug.conf'
126+
127+
Then attach RTT as described here: :ref:`Using Segger J-Link <Using Segger J-Link>`
128+
129+
Support for the Direction Finding
130+
=================================
131+
132+
The sample can be built with the support for the BLE Direction Finding.
133+
To enable this feature build this sample for specific board variants that provide
134+
required hardware configuration for the Radio.
135+
136+
.. code-block:: console
137+
138+
west build samples/bluetooth/hci_uart_3wire -b nrf52833dk/nrf52833@df -- -DCONFIG_BT_CTLR_DF=y
139+
140+
You can use following targets:
141+
142+
* ``nrf5340dk/nrf5340/cpunet@df``
143+
* ``nrf52833dk/nrf52833@df``
144+
145+
Check the :ref:`bluetooth_direction_finding_connectionless_rx` and the :ref:`bluetooth_direction_finding_connectionless_tx` for more details.
146+
147+
Using a USB CDC ACM UART
148+
========================
149+
150+
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`.
151+
152+
Using the controller with the Zephyr host
153+
=========================================
154+
155+
This describes how to hook up a board running this sample to a board running
156+
an application that uses the Zephyr host.
157+
158+
On the controller side, the `zephyr,bt-c2h-uart` DTS property (in the `chosen`
159+
block) is used to select which uart device to use. For example if we want to
160+
keep the console logs, we can keep console on uart0 and the HCI on uart1 like
161+
so:
162+
163+
.. code-block:: dts
164+
165+
/ {
166+
chosen {
167+
zephyr,console = &uart0;
168+
zephyr,shell-uart = &uart0;
169+
zephyr,bt-c2h-uart = &uart1;
170+
};
171+
};
172+
173+
On the host application, some config options need to be used to select the H5
174+
driver instead of the built-in controller:
175+
176+
.. code-block:: kconfig
177+
178+
CONFIG_BT_HCI=y
179+
CONFIG_BT_CTLR=n
180+
CONFIG_BT_H5=y
181+
182+
Similarly, the `zephyr,bt-uart` DTS property selects which uart to use:
183+
184+
.. code-block:: dts
185+
186+
/ {
187+
chosen {
188+
zephyr,console = &uart0;
189+
zephyr,shell-uart = &uart0;
190+
zephyr,bt-uart = &uart1;
191+
};
192+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
2+
3+
&uart0 {
4+
compatible = "nordic,nrf-uart";
5+
current-speed = <1000000>;
6+
status = "okay";
7+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CONFIG_MAIN_STACK_SIZE=512
2+
CONFIG_IDLE_STACK_SIZE=256
3+
CONFIG_ISR_STACK_SIZE=512
4+
CONFIG_BT_MAX_CONN=10
5+
# Revert values set in prj.conf, set them to their Kconfig default value
6+
CONFIG_BT_BUF_CMD_TX_SIZE=65
7+
CONFIG_BT_BUF_ACL_RX_SIZE=69
8+
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=43
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
2+
3+
&uart0 {
4+
compatible = "nordic,nrf-uart";
5+
current-speed = <1000000>;
6+
status = "okay";
7+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&uart0 {
8+
compatible = "nordic,nrf-uarte";
9+
current-speed = <1000000>;
10+
status = "okay";
11+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&uart0 {
8+
compatible = "nordic,nrf-uarte";
9+
current-speed = <1000000>;
10+
status = "okay";
11+
};
12+
13+
&radio {
14+
status = "okay";
15+
/* This is an example number of antennas that may be available
16+
* on antenna matrix board.
17+
*/
18+
dfe-antenna-num = <10>;
19+
/* This is an example switch pattern that will be used to set an
20+
* antenna for Tx PDU (period before start of Tx CTE).
21+
*/
22+
dfe-pdu-antenna = <0x0>;
23+
24+
/* These are example GPIO pin numbers that are provided to
25+
* Radio peripheral. The pins will be acquired by Radio to
26+
* drive antenna switching when AoD is enabled.
27+
*/
28+
dfegpio0-gpios = <&gpio0 3 0>;
29+
dfegpio1-gpios = <&gpio0 4 0>;
30+
dfegpio2-gpios = <&gpio0 28 0>;
31+
dfegpio3-gpios = <&gpio0 29 0>;
32+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
2+
3+
&uart0 {
4+
compatible = "nordic,nrf-uart";
5+
current-speed = <1000000>;
6+
status = "okay";
7+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_USB_DEVICE_STACK=y
2+
CONFIG_USB_DEVICE_PRODUCT="Zephyr HCI UART 3Wire sample"
3+
CONFIG_USB_CDC_ACM=y
4+
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
2+
3+
&uart0 {
4+
compatible = "nordic,nrf-uart";
5+
current-speed = <1000000>;
6+
status = "okay";
7+
};

0 commit comments

Comments
 (0)