Skip to content

Commit

Permalink
sample: Add HCI interface to DTM
Browse files Browse the repository at this point in the history
Add HCI interface to Direct Test Mode sample.

Jira: NCSDK-22490

Signed-off-by: Dominik Chat <dominik.chat@nordicsemi.no>
  • Loading branch information
dchat-nordic committed Oct 12, 2023
1 parent 8dfeca6 commit e311b16
Show file tree
Hide file tree
Showing 28 changed files with 2,223 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ Bluetooth samples

* :ref:`direct_test_mode` sample:

* Added support for the nRF52840 DK.
* Added:

* Support for the nRF52840 DK.
* Experimental support for the HCI interface.

* Updated:

Expand Down
9 changes: 9 additions & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ if (CONFIG_NCS_SAMPLE_REMOTE_SHELL_CHILD_IMAGE)
)
endif()

if (CONFIG_NCS_SAMPLE_DTM_REMOTE_HCI_CHILD_IMAGE)
add_child_image(
NAME "remote_hci"
SOURCE_DIR "${ZEPHYR_NRF_MODULE_DIR}/samples/bluetooth/direct_test_mode/remote_hci"
DOMAIN "CPUAPP"
BOARD ${CONFIG_DOMAIN_CPUAPP_BOARD}
)
endif()

if (CONFIG_NCS_INCLUDE_RPMSG_CHILD_IMAGE OR CONFIG_NCS_SAMPLE_EMPTY_NET_CORE_CHILD_IMAGE)

if (CONFIG_NCS_SAMPLE_EMPTY_NET_CORE_CHILD_IMAGE)
Expand Down
8 changes: 8 additions & 0 deletions samples/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ config NCS_SAMPLE_REMOTE_SHELL_CHILD_IMAGE
Add remote_shell as a child image (application core).
Used by samples that run on the network core only.

config NCS_SAMPLE_DTM_REMOTE_HCI_CHILD_IMAGE
bool "Add remote_hci child image for DTM"
depends on SOC_NRF5340_CPUNET
select PARTITION_MANAGER_ENABLED
help
Add remote_hci as a child image (application core).
Used by the DTM sample to pass HCI commands from
application core UART peripheral.

if NCS_INCLUDE_RPMSG_CHILD_IMAGE

Expand Down
20 changes: 19 additions & 1 deletion samples/bluetooth/direct_test_mode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,30 @@ if(CONFIG_DTM_USB)
set(remote_shell_CONF_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/prj_usb.conf)
endif()

if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet")
if(NOT "${EXTRA_CONF_FILE}" STREQUAL "overlay-hci-nrf53.conf")
set(EXTRA_DTC_OVERLAY_FILE "${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell_nrf53.overlay")
endif()
endif()

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(NONE)

target_include_directories(app PRIVATE ./src)

target_sources_ifdef(CONFIG_DTM_TRANSPORT_TWOWIRE app PRIVATE src/transport/dtm_uart_twowire.c)
target_sources_ifdef(CONFIG_DTM_TRANSPORT_TWOWIRE app PRIVATE
src/transport/dtm_uart_twowire.c
src/transport/dtm_uart_wait.c
)

target_sources_ifdef(CONFIG_DTM_TRANSPORT_HCI app PRIVATE src/transport/dtm_hci.c)

if(CONFIG_NCS_SAMPLE_DTM_REMOTE_HCI_CHILD_IMAGE)
target_sources(app PRIVATE src/transport/hci_uart_remote.c)
target_include_directories(app PRIVATE ./rpc)
else()
target_sources_ifdef(CONFIG_DTM_TRANSPORT_HCI app PRIVATE src/transport/hci_uart.c)
endif()

# NORDIC SDK APP START
target_sources(app PRIVATE
Expand Down
40 changes: 38 additions & 2 deletions samples/bluetooth/direct_test_mode/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ config ANOMALY_172_TIMER_IRQ_PRIORITY

config DTM_USB
bool "DTM over USB CDC ACM class"
depends on SOC_NRF5340_CPUNET
depends on SOC_NRF5340_CPUNET && DTM_TRANSPORT_TWOWIRE
select EXPERIMENTAL
help
Use USB instead of UART as the DTM interface. For nRF5340 the USB from application core
Expand All @@ -54,14 +54,50 @@ config DTM_TRANSPORT_TWOWIRE
help
Use the Two Wire transport interface as the DTM transport layer.

config DTM_TRANSPORT_HCI
bool "DTM over HCI UART [EXPERIMENTAL]"
depends on SERIAL
depends on NET_BUF
select EXPERIMENTAL
help
Use the HCI UART transport interface as the DTM transport layer.

endchoice # DTM_TRANSPORT

if DTM_TRANSPORT_HCI

config DTM_HCI_QUEUE_COUNT
int "Count of HCI RX/TX queues"
default 16
help
Maximum depth of the HCI RX/TX queues.

config DTM_HCI_QUEUE_SIZE
int "Size of HCI RX/TX queue buffer"
default 1024
help
Maximum size of the HCI RX/TX queue element.

config DTM_HCI_TX_THREAD_STACK_SIZE
int "Stack size of TX thread"
default 2048
help
Stack size of the TX thread.

config DTM_HCI_TX_THREAD_PRIORITY
int "TX thread priority"
default 7
help
Priority of the TX thread.

endif # DTM_TRANSPORT_HCI

config DTM_POWER_CONTROL_AUTOMATIC
bool "Automatic power control"
depends on FEM
default y
help
Set the SoC output power and the front-end module gain to achieve the Tx output power
Set the SoC output power and the front-end module gain to achieve the TX output power
requested by user. If the exact value cannot be achieved, power is set to the closest
possible value. If this option is disabled, user can set the SoC output power and the
front-end module gain with the separate vendor specific commands.
Expand Down
29 changes: 25 additions & 4 deletions samples/bluetooth/direct_test_mode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ The DTM sample includes two parts:

You can find the source code of both parts in :file:`samples/bluetooth/direct_test_mode/src`.

The DTM sample contains a driver for a 2-wire UART interface.
The driver maps two-octet commands and events to the DTM library, as specified by the Bluetooth Low Energy DTM specification.
This sample contains a driver for a 2-wire UART interface and an experimental HCI UART interface.
Unless otherwise stated, all following commands and references describe the 2-wire interface.
The 2-wire driver maps two-octet commands and events to the DTM library, as specified by the Bluetooth Low Energy DTM specification.
The HCI driver accepts HCI commands in H4 format and implements a minimal set of HCI commands usually sufficient to run DTM testing.

.. figure:: /images/bt_dtm_dut.svg
:alt: nRF5 with DTM as a DUT
Expand All @@ -60,8 +62,9 @@ The implementation is self-contained and requires no Bluetooth Low Energy protoc
The MPU is initialized in the standard way.
The DTM library function :c:func:`dtm_init` configures all interrupts, timers, and the radio.

The :file:`main.c` file may be extended with other interface implementations, such as an HCI interface, USB, or another interface required by the Upper Tester.
This sample may be extended with other interface implementations, such as an HCI interface, USB, or another interface required by the Upper Tester.
The extension should be done by adding an appropriate interface implementation in the :file:`transport` directory.
The transports must conform to the interface specified in the :file:`transport/dtm_transport.h` file.

The interface to the Lower Tester uses the antenna connector of the chosen development kit.
While in principle an aerial connection might be used, conformance tests cover the reading of the transmission power delivered by the DUT.
Expand Down Expand Up @@ -316,9 +319,12 @@ The DTM-to-Serial adaptation layer

The :file:`dtm_uart_twowire.c` file is an implementation of the UART interface specified in the `Bluetooth Core Specification`_, Volume 6, Part F, Chapter 3.

The :file:`dtm_hci.c` and :file:`hci_uart.c` files are an implementation of the HCI UART interface specified in the `Bluetooth Core Specification`_, Volume 4, Part A (the flow control can be configured by an overlay file).

The default selection of UART pins is defined in :file:`zephyr/boards/arm/board_name/board_name.dts`.
You can change the defaults using the symbols ``tx-pin`` and ``rx-pin`` in the DTS overlay file of the child image at the project level.
The overlay files for the :ref:`nrf5340_remote_shell` child image are located in the :file:`child_image/remote_shell` directory.
The HCI interface allows for a custom ``remote_hci`` image to be used with |nRF5340DKnoref|.

.. note::
On the nRF5340 development kit, the physical UART interface of the application core is used for communication with the tester device.
Expand Down Expand Up @@ -362,6 +368,21 @@ Building and running
The Remote IPC shell sample is built and programmed automatically by default.
If you want to program your custom solution for the application core, unset the :kconfig:option:`CONFIG_NCS_SAMPLE_REMOTE_SHELL_CHILD_IMAGE` Kconfig option.

Experimental HCI interface
==========================

To build the sample with an HCI interface, use the following command:

.. code-block:: console
west build samples/bluetooth/direct_test_mode -b board_name -- --DEXTRA_CONF_FILE=overlay-hci.conf
On the |nRF5340DKnoref| the sample with HCI interface can also be built with the `remote_hci` image using the following command:

.. code-block:: console
west build samples/bluetooth/direct_test_mode -b board_name -- --DEXTRA_CONF_FILE=overlay-hci-nrf53.conf
USB CDC ACM transport variant
=============================

Expand Down Expand Up @@ -455,7 +476,7 @@ The Bluetooth Low Energy DTM UART interface standard specifies the following con
.. note::
The default bit rate of the DTM UART driver is 19200 bps, which is supported by most certified testers.

You must send all commands as two-byte HEX numbers.
When using a 2-wire interface, you must send all commands as two-byte HEX numbers.
The responses must have the same format.

Connect with RealTerm (Windows)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/ {
chosen {
ncs,dtm-uart = &uart0;
};
};

&uart0 {
status = "okay";
compatible = "nordic,nrf-ipc-uart";
ipc = <&ipc0>;
ept-name = "remote shell";
current-speed = <19200>;
};
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

&radio {
status = "okay";
Expand Down
19 changes: 19 additions & 0 deletions samples/bluetooth/direct_test_mode/conf/remote_shell_nrf53.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/ {
chosen {
ncs,dtm-uart = &uart0;
};
};

&uart0 {
status = "okay";
compatible = "nordic,nrf-ipc-uart";
ipc = <&ipc0>;
ept-name = "remote shell";
current-speed = <19200>;
};
15 changes: 15 additions & 0 deletions samples/bluetooth/direct_test_mode/overlay-hci-nrf53.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

CONFIG_NCS_SAMPLE_REMOTE_SHELL_CHILD_IMAGE=n
CONFIG_IPC_UART=n

CONFIG_NCS_SAMPLE_DTM_REMOTE_HCI_CHILD_IMAGE=y
CONFIG_NRF_RPC=y
CONFIG_NRF_RPC_CBOR=y

CONFIG_DTM_TRANSPORT_HCI=y
CONFIG_NET_BUF=y
9 changes: 9 additions & 0 deletions samples/bluetooth/direct_test_mode/overlay-hci.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

CONFIG_DTM_TRANSPORT_HCI=y
CONFIG_NET_BUF=y
CONFIG_UART_ASYNC_API=y
20 changes: 20 additions & 0 deletions samples/bluetooth/direct_test_mode/remote_hci/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(remote_hci)

target_include_directories(app PRIVATE ./../rpc)
target_include_directories(app PRIVATE ./../src/transport)

# NORDIC SDK APP START
target_sources(app PRIVATE
src/main.c
../src/transport/hci_uart.c
)
# NORDIC SDK APP END
53 changes: 53 additions & 0 deletions samples/bluetooth/direct_test_mode/remote_hci/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

mainmenu "Nordic Remote HCI DTM"

config DTM_REMOTE_HCI_CHILD
bool
default y

config DTM_PUT_THREAD_STACK_SIZE
int "dtm_put thread stack size"
default 2048
help
Stack size of the dtm_put thread.

config DTM_PUT_THREAD_PRIORITY
int "dtm_put thread priority"
default 7
help
Priority of the dtm_put thread.

config REMOTE_HCI_QUEUE_COUNT
int "Count of HCI RX/TX queues"
default 16
help
Maximum depth of the HCI RX/TX queues.

config REMOTE_HCI_QUEUE_SIZE
int "Size of HCI RX/TX queue buffer"
default 1024
help
Maximum size of the HCI RX/TX queue element.

config REMOTE_HCI_TX_THREAD_STACK_SIZE
int "Stack size of TX thread"
default 2048
help
Stack size of the TX thread.

config REMOTE_HCI_TX_THREAD_PRIORITY
int "TX thread priority"
default 7
help
Priority of the TX thread.

module = DTM_REMOTE_HCI
module-str = "DTM_remote_hci"
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

source "Kconfig.zephyr"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/ {
chosen {
ncs,dtm-uart = &uart0;
};
};

&uart0 {
status = "okay";
current-speed = <115200>;
};

&gpio_fwd {
dfe-radio {
gpios = <&gpio0 4 0>,
<&gpio0 5 0>,
<&gpio0 6 0>,
<&gpio0 7 0>;
};
};
26 changes: 26 additions & 0 deletions samples/bluetooth/direct_test_mode/remote_hci/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_ASSERT=y
CONFIG_ASSERT_NO_COND_INFO=y
CONFIG_ASSERT_NO_MSG_INFO=y

CONFIG_HW_STACK_PROTECTION=y

CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_LOG=y
CONFIG_LOG_PRINTK=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_UART_ASYNC_API=y

CONFIG_NRF_RPC=y
CONFIG_NRF_RPC_CBOR=y
CONFIG_IDLE_STACK_SIZE=2048

CONFIG_NET_BUF=y

CONFIG_BOARD_ENABLE_CPUNET=y
Loading

0 comments on commit e311b16

Please sign in to comment.