Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: openthread: Enable USB CDC ACM for Spinel #4121

Merged
merged 3 commits into from Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
164 changes: 89 additions & 75 deletions doc/nrf/ug_thread_tools.rst
Expand Up @@ -281,52 +281,51 @@ To install the verified version, replace the ``git checkout full/latest-release`

.. parsed-literal::

git checkout 87c90eedce0c75cb68a1cbc34ff36223400862f1
git checkout bf45115f41ba2b8029eda174be2b93dea73b9261

When installing on macOS, follow the instructions for the manual installation and replace the above command to ensure that the correct version is installed.

.. note::
To use USB transport for communication with a network co-processor (NCP), you must build wpantund with the udev library.
To do so, use the following commands::

sudo apt-get install libudev-dev
./bootstrap
./configure --with-udev
make -j4

.. _ug_thread_tools_wpantund_configuring:

Configuring wpantund
====================

When working with samples that support wpantund, complete the following steps to start the wpantund processes:

1. Open a shell and run the wpantund process.
The required command depends on whether you want to connect to a network co-processor (NCP) node or a radio co-processor (RCP) node.

Replace the following parameters:

* *network_interface_name* - Specifies the name of the network interface, for example, ``leader_if``.
* *ncp_uart_device* - Specifies the location of the device, for example, :file:`/dev/ttyACM0`.
* *baud_rate* - Specifies the baud rate to use.
The Thread samples support baud rate ``1000000``.

Network co-processor (NCP)
When connecting to an NCP node, use the following command:
1. Open a shell and run the wpantund process:

.. parsed-literal::
:class: highlight

wpantund -I *network_interface_name* -s *ncp_uart_device* -b *baud_rate*

For example::
Replace the following parameters:

sudo wpantund -I leader_if -s /dev/ttyACM0 -b 1000000
* *network_interface_name* - Specifies the name of the network interface, for example, ``leader_if``.
* *ncp_uart_device* - Specifies the location of the device, for example:

Radio co-processor (RCP)
ru-fu marked this conversation as resolved.
Show resolved Hide resolved
When connecting to an RCP node, you must use the ``ot-ncp`` tool to establish the connection.
See :ref:`ug_thread_tools_ot_apps` for more information.
Use the following command:
* For UART transport: :file:`/dev/ttyACM0`
* For USB transport - symlink: :file:`/dev/serial/by-id/usb-Nordic_Semiconductor_ASA_Thread_Co-Processor_07AA4C22D2E2C88D-if00`

.. parsed-literal::
:class: highlight
* *baud_rate* - Specifies the baud rate to use.
The Thread samples support baud rate ``1000000``.

wpantund -I *network_interface_name* -s 'system:./output/posix/bin/ot-ncp spinel+hdlc+uart://\ *ncp_uart_device*\ ?uart-baudrate=\ *baud_rate*
For example, for UART transport, enter the following command::

For example::
sudo wpantund -I leader_if -s /dev/ttyACM0 -b 1000000

sudo wpantund -I leader_if -s 'system:./output/posix/bin/ot-ncp spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=1000000'
For example, for USB transport, enter the following command::

sudo wpantund -I leader_if -s /dev/serial/by-id/usb-Nordic_Semiconductor_ASA_Thread_Co-Processor_07AA4C22D2E2C88D-if00 -b 1000000

#. Open another shell and run the wpanctl process by using the following command:

Expand All @@ -343,11 +342,9 @@ Using wpanctl commands
======================

To issue a wpanctl command, run it in the wpanctl shell.
For example, the following command checks the kit state:

.. code-block:: console
For example, the following command checks the kit state::

wpanctl:leader_if> status
wpanctl:leader_if> status

The output will be different depending on the kit and the sample.

Expand Down Expand Up @@ -384,8 +381,12 @@ Configuring Pyspinel
When working with samples that support Pyspinel, complete the following steps to communicate with the device:

1. Open a shell in a Pyspinel root directory.
#. Run Pyspinel to connect to the node.
The required command depends on whether you want to connect to a network co-processor (NCP) node or a radio co-processor (RCP) node.
#. Run Pyspinel to connect to the node:

.. parsed-literal::
:class: highlight

sudo python3 spinel-cli.py -d *debug_level* -u *ncp_uart_device* -b *baud_rate*

Replace the following parameters:

Expand All @@ -394,45 +395,19 @@ When working with samples that support Pyspinel, complete the following steps to
* *baud_rate* - Specifies the baud rate to use.
The Thread samples support baud rate ``1000000``.

Network co-processor (NCP)
When connecting to an NCP node, use the following command:

.. parsed-literal::
:class: highlight

sudo python3 spinel-cli.py -d *debug_level* -u *ncp_uart_device* -b *baud_rate*

For example::

sudo python3 spinel-cli.py -d 4 -u /dev/ttyACM0 -b 1000000
For example::

Radio co-processor (RCP)
When connecting to an RCP node, you must use the ``ot-ncp`` tool to establish the connection.
See :ref:`ug_thread_tools_ot_apps` for more information.
To enable logs from the RCP Spinel backend, you must build the ``ot-ncp`` tool with option ``LOG_OUTPUT=APP``.
See :ref:`ug_thread_tools_building_ot_apps` for information on how to build the tool.

Use the following command to connect to an RCP node:

.. parsed-literal::
:class: highlight

sudo python3 spinel-cli.py -d *debug_level* -p './output/posix/bin/ot-ncp spinel+hdlc+uart://\ *ncp_uart_device*\ ?uart-baudrate=\ *baud_rate*

For example::

sudo python3 spinel-cli.py -d 4 -p './output/posix/bin/ot-ncp spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=1000000'
sudo python3 spinel-cli.py -d 4 -u /dev/ttyACM0 -b 1000000

.. _ug_thread_tools_ot_apps:

OpenThread POSIX applications
ru-fu marked this conversation as resolved.
Show resolved Hide resolved
*****************************

OpenThread POSIX applications allow to communicate with a radio co-processor in a comfortable way.
OpenThread POSIX applications allow to communicate with a radio co-processor (RCP) in a comfortable way.

OpenThread provides the following applications:

* ``ot-ncp`` - Supports :ref:`ug_thread_tools_wpantund` for the RCP architecture.
* ``ot-cli`` - Works like the :ref:`ot_cli_sample` sample for the RCP architecture.
* ``ot-daemon`` and ``ot-ctl`` - Provides the same functionality as ``ot-cli``, but keeps the daemon running in the background all the time.
See `OpenThread Daemon`_ for more information.
Expand All @@ -451,29 +426,68 @@ Building the OpenThread POSIX applications
Build the OpenThread POSIX applications by performing the following steps:

#. Open a shell in the OpenThread source code directory :file:`ncs/modules/lib/openthread`.
#. Initialize the build and clean previous artifacts by running the following commands:
#. Clean previous artifacts by running the following commands::

.. code-block:: console
rm -rf build

# initialize GNU Autotools
./bootstrap
#. Build the applications with the required options.
For example, to build the ``ot-cli`` application with support for USB transport and Thread v1.1, run the following command::

# clean previous artifacts
make -f src/posix/Makefile-posix clean
./script/cmake-build posix -DOT_SPINEL_RESET_CONNECTION=ON -DOT_THREAD_VERSION=1.1

#. Build the applications with the required options.
For example, to build POSIX applications like ``ot-cli`` or ``ot-ncp`` with log output being redirected to the application, run the following command:
Alternatively, to build the ``ot-daemon`` and ``ot-ctl`` applications with support for USB transport and Thread v1.1, run the following command::

./script/cmake-build posix -DOT_SPINEL_RESET_CONNECTION=ON -DOT_THREAD_VERSION=1.1 -DOT_DAEMON=ON

You can find the generated applications in :file:`./build/posix/src/posix/`.

.. note::
The build option ``OT_SPINEL_RESET_CONNECTION`` is required to properly handle USB communication with RCP devices that perform a hard reset.
ru-fu marked this conversation as resolved.
Show resolved Hide resolved
It depends on the libudev-dev library, and it is supported only on Linux.

The option is required when working with the :ref:`ot_coprocessor_sample` sample (|NCS|) or the :ref:`zephyr:coprocessor-sample` sample (Zephyr).

.. code-block:: console

# build core for POSIX (ot-cli, ot-ncp)
make -f src/posix/Makefile-posix LOG_OUTPUT=APP

Alternatively, to build POSIX applications like ``ot-daemon`` or ``ot-ctl``, run the following command:
Running the OpenThread POSIX applications
=========================================

.. code-block:: console
Use the following commands to connect to an RCP node.

# build daemon mode core stack for POSIX (ot-daemon, ot-ctl)
make -f src/posix/Makefile-posix DAEMON=1
* For ``ot-cli``:

You can find the generated applications in :file:`./output/posix/bin/`.
.. parsed-literal::
:class: highlight

sudo ./build/posix/src/posix/ot-cli 'spinel+hdlc+uart://\ *ncp_uart_device*\ ?uart-baudrate=\ *baud_rate*' --verbose

* For ``ot-daemon`` and ``ot-ctl``:

.. parsed-literal::
:class: highlight

sudo ./build/posix/src/posix/ot-daemon 'spinel+hdlc+uart://\ *ncp_uart_device*\ ?uart-baudrate=\ *baud_rate*' --verbose
sudo ./build/posix/src/posix/ot-ctl

Replace the following parameters:

* *ncp_uart_device* - Specifies the location of the device, for example:

* For UART transport: :file:`/dev/ttyACM0`
* For USB transport - symlink: :file:`/dev/serial/by-id/usb-Nordic_Semiconductor_ASA_Thread_Co-Processor_07AA4C22D2E2C88D-if00`

* *baud_rate* - Specifies the baud rate to use.
The Thread Co-Processor sample supports baud rate ``1000000``.

For example, to use ``ot-cli`` with USB transport, enter the following command::

sudo ./build/posix/src/posix/ot-cli 'spinel+hdlc+uart:///dev/serial/by-id/usb-Nordic_Semiconductor_ASA_Thread_Co-Processor_07AA4C22D2E2C88D-if00?uart-baudrate=1000000' --verbose

For example, to use ``ot-daemon`` with UART transport, enter the following commands::

sudo ./build/posix/src/posix/ot-daemon 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=1000000' --verbose
sudo ./build/posix/src/posix/ot-ctl

.. note::
You must use a symlink to specify the device for a USB connection.
Otherwise, communication will fail after resetting the device.
18 changes: 18 additions & 0 deletions samples/openthread/cli/sample.yaml
Expand Up @@ -18,3 +18,21 @@ tests:
integration_platforms:
- nrf52840dk_nrf52840
- nrf52833dk_nrf52833
samples.openthread.cli.minimal_multiprotocol:
build_only: true
platform_allow: nrf52840dk_nrf52840 nrf52833dk_nrf52833 nrf5340dk_nrf5340_cpuapp
tags: ci_build
extra_args: OVERLAY_CONFIG=overlay-minimal_multiprotocol.conf
integration_platforms:
- nrf52840dk_nrf52840
- nrf52833dk_nrf52833
- nrf5340dk_nrf5340_cpuapp
samples.openthread.cli.minimal_singleprotocol:
build_only: true
platform_allow: nrf52840dk_nrf52840 nrf52833dk_nrf52833 nrf5340dk_nrf5340_cpuapp
tags: ci_build
extra_args: OVERLAY_CONFIG=overlay-minimal_singleprotocol.conf
integration_platforms:
- nrf52840dk_nrf52840
- nrf52833dk_nrf52833
- nrf5340dk_nrf5340_cpuapp
3 changes: 3 additions & 0 deletions samples/openthread/coap_client/overlay-dfu_support.conf
Expand Up @@ -21,3 +21,6 @@ CONFIG_BT_BUF_ACL_RX_SIZE=264

# Reduce GAP event length to avoid heavy BLE traffic generated during DFU
CONFIG_SDC_MAX_CONN_EVENT_LEN_DEFAULT=3000

# Enable minimal logging implementation to decrease memory footprint
CONFIG_LOG_MODE_MINIMAL=y
6 changes: 4 additions & 2 deletions samples/openthread/common/overlay-ot-defaults.conf
Expand Up @@ -4,8 +4,10 @@
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

CONFIG_NCS_SAMPLES_DEFAULTS=y
edmont marked this conversation as resolved.
Show resolved Hide resolved

CONFIG_ASSERT=y
CONFIG_ASSERT_NO_COND_INFO=y
CONFIG_ASSERT_NO_MSG_INFO=y
CONFIG_HW_STACK_PROTECTION=y
CONFIG_NEWLIB_LIBC=y

# Enable floating point Hard ABI
Expand Down
2 changes: 1 addition & 1 deletion samples/openthread/coprocessor/README.rst
Expand Up @@ -128,7 +128,7 @@ The following configuration files are available:
* :file:`overlay-minimal_rcp.conf` - Enables a minimal configuration that reduces the code size and RAM usage.
This file enables the RCP architecture with basic functionality and optimizes stacks and buffer sizes.
For more information, see :ref:`app_memory`.

* :file:`overlay-usb.conf` - Enables emulating a serial port over USB for Spinel communication with the host.

Building and running
********************
Expand Down
18 changes: 16 additions & 2 deletions samples/openthread/coprocessor/overlay-logging.conf
Expand Up @@ -3,11 +3,25 @@
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

# Option for configuring log level in sample module
CONFIG_OT_COPROCESSOR_LOG_LEVEL_INF=y
# Disable Spinel logging backend
CONFIG_LOG_BACKEND_SPINEL=n

# Enable RTT logging backend
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y

# Option for configuring log level in whole Zephyr
CONFIG_LOG_MAX_LEVEL=3

# Option for configuring log level in sample module
CONFIG_OT_COPROCESSOR_LOG_LEVEL_INF=y

# Option for configuring log level in OpenThread
CONFIG_OPENTHREAD_LOG_LEVEL_INFO=y

# Disable logging from net config library
CONFIG_NET_CONFIG_LOG_LEVEL_OFF=y

# Adjust log strdup settings
CONFIG_LOG_STRDUP_BUF_COUNT=32
CONFIG_LOG_STRDUP_MAX_STRING=128
18 changes: 18 additions & 0 deletions samples/openthread/coprocessor/overlay-usb.conf
@@ -0,0 +1,18 @@
#
# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Use USB-CDC-ACM for Co-Processor
CONFIG_OPENTHREAD_COPROCESSOR_SPINEL_ON_UART_ACM=y
CONFIG_OPENTHREAD_COPROCESSOR_SPINEL_ON_UART_DEV_NAME="CDC_ACM_0"

CONFIG_USB=y
CONFIG_USB_CDC_ACM=y
CONFIG_USB_DEVICE_MANUFACTURER="Nordic Semiconductor ASA"
CONFIG_USB_DEVICE_PRODUCT="Thread Co-Processor"
CONFIG_USB_DEVICE_VID=0x1915
CONFIG_USB_DEVICE_PID=0x0000

CONFIG_UART_LINE_CTRL=y
1 change: 0 additions & 1 deletion samples/openthread/coprocessor/prj.conf
Expand Up @@ -13,7 +13,6 @@ CONFIG_OT_COPROCESSOR_LOG_LEVEL_ERR=y
CONFIG_LOG_MAX_LEVEL=1
CONFIG_OPENTHREAD_LOG_LEVEL_CRIT=y
CONFIG_NET_CONFIG_LOG_LEVEL_OFF=y
CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_BACKEND_SPINEL=y
CONFIG_LOG_BACKEND_RTT=n
CONFIG_LOG_BACKEND_UART=n
Expand Down
9 changes: 9 additions & 0 deletions samples/openthread/coprocessor/sample.yaml
Expand Up @@ -18,3 +18,12 @@ tests:
integration_platforms:
- nrf52840dk_nrf52840
- nrf52833dk_nrf52833
samples.openthread.coprocessor.usb:
build_only: true
platform_allow: nrf52840dk_nrf52840 nrf52840dongle_nrf52840 nrf52833dk_nrf52833
tags: ci_build
extra_args: OVERLAY_CONFIG=overlay-usb.conf;
integration_platforms:
- nrf52840dk_nrf52840
- nrf52840dongle_nrf52840
- nrf52833dk_nrf52833