Bluetooth: NUS shell transport

The Nordic UART Service (NUS) shell transport sample demonstrates how to use the Nordic UART Service (NUS) shell transport to receive shell commands from a remote device over Bluetooth®.

Overview

When the connection is established, you can connect to the sample through the Nordic UART Service (NUS) by using a host application. You can then send shell commands that are executed on the device running the sample, and see the logs. See Sending shell commands for more information about the host tools available in nRF Connect SDK for communicating with the sample.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

nRF54H20 DK

PCA10175

nrf54h20dk

nrf54h20dk/nrf54h20/cpuapp

nRF5340 DK

PCA10095

nrf5340dk

nrf5340dk/nrf5340/cpuapp/ns nrf5340dk/nrf5340/cpuapp

nRF52 DK

PCA10040

nrf52dk

nrf52dk/nrf52832

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

When built for a board target with the */ns variant, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

You also need an additional nRF52 development kit, like the PCA10040 for connecting using the bt_nus_shell.py script. Alternatively, you can use Bluetooth LE Console for connecting, using Linux only.

Building and running

This sample can be found under samples/bluetooth/shell_bt_nus in the nRF Connect SDK folder structure.

When built as firmware image for a board target with the */ns variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE). Because of this, it automatically includes the Trusted Firmware-M (TF-M). To read more about CMSE, see Processing environments.

To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the SDK repositories, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

Testing

The nRF Connect SDK provides two alternatives for testing the sample:

Testing using the shell_bt_nus script

The script file scripts/shell/bt_nus_shell.py contains a cross-platform example host application, written in Python 3.

The script uses an additional Nordic development kit, like the PCA10040, as a Bluetooth central device. It connects to the specified device and forwards all NUS traffic to the network port. You can then use a console application, like PuTTY, to connect to that port and use the shell. The default port is set to 8889.

After programming the sample to your development kits, complete the following steps to test it:

  1. Start a console application, like PuTTY, and connect through UART to the shell_bt_nus application running on the development kit to check the log. See Testing and optimization for more information on how to connect with PuTTY through UART.

  2. Run the following command in the nRF Connect SDK root directory to install the script dependencies:

    pip install --user -r scripts/shell/requirements.txt
    
  3. Connect to your PC the nRF52 development kit meant to use the bt_nus_shell.py script.

  4. Start the bt_nus_shell.py script with the correct parameters, for example:

    bt_nus_shell.py --name BT_NUS_shell --com COM237 --family NRF52 --snr 682560213
    
  5. Open a console application, like PuTTY, and open a new session, setting the Connection Type to Raw and the Destination Address to 127.0.0.1:8889.

  6. Press Enter in the terminal window. A console prompt is displayed showing a log message that indicates the active connection.

  7. Enter the commands that you want to execute.

Testing using the Bluetooth LE Console

See Bluetooth LE Console for more information on how to test the sample using the Bluetooth LE Console.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries:

  • API:

    • include/bluetooth/bluetooth.h

    • include/bluetooth/hci.h

    • include/bluetooth/uuid.h

    • include/bluetooth/gatt.h

    • samples/bluetooth/gatt/bas.h

  • Logging

The sample also uses the following secure firmware component: