Working with nRF5340

The nRF Connect SDK provides support for developing on the nRF5340 System on Chip (SoC) using the nRF5340 PDK (PCA10095).

Warning

nRF5340 support is a work in progress. This user guide explains how to work with nRF5340 once all required features have been merged. Currently, not everything that is described here is actually supported.

Introduction

nRF5340 is a wireless ultra-low power multicore System on Chip (SoC) with two fully programmable Arm Cortex-M33 processors: a network core and an application core. The nRF Connect SDK supports Bluetooth Low Energy communication on the nRF5340 SoC.

See the nRF5340 Product Specification for more information about the nRF5340 SoC. nRF5340-DK gives an overview of the nRF5340 PDK support in Zephyr.

Network core

The network core is an Arm Cortex-M33 processor with a reduced feature set, designed for ultra-low power operation.

This core is used to communicate with the network. With regards to the nRF5340 samples, this means that the network core runs the radio stack and real-time procedures. In the current implementation, the network core runs the controller part of the Bluetooth Low Energy stack. In general, this core should be used for real-time processing tasks involving low-level protocols and layers.

The board name for the network core in Zephyr is nrf5340_dk_nrf5340_cpunet.

Application core

The application core is a full-featured Arm Cortex-M33 processor including DSP instructions and FPU.

In the current implementation of the nRF5340 samples, this core is used to run the high-level radio stack (the host part of the Bluetooth Low Energy stack) and the application. In general, this core should be used for tasks that require high performance and application-level logic.

The board name for the application core in Zephyr is nrf5340_dk_nrf5340_cpuapp.

Note

The M33 TrustZone divides the application core into secure (nrf5340_dk_nrf5340_cpuapp) and non-secure (nrf5340_dk_nrf5340_cpuappns) domains. However, all nRF5340 samples currently run in the secure domain, so you should not use the nrf5340_dk_nrf5340_cpuappns board.

Inter-core communication

Communication between the application core and the network core happens through a shared memory area. The application core memory is mapped to the network core memory map. This means that the network core can access and use the application core memory for shared memory communication.

Interprocessor Communication (IPC) is used to indicate to the other core that there is new data available to pick up. The actual data exchange is handled by Open Asymmetric Multi Processing (OpenAMP).

Zephyr includes the OpenAMP library, which provides a complete solution for exchanging messages between the cores. The IPC peripheral is presented to Zephyr as an Interprocessor Mailbox (IPM) device. The OpenAMP library uses the IPM SHIM layer, which in turn uses the IPC driver in nrfx.

Available samples

nRF5340 samples consist of two separate images: one that runs on the network core and one that runs on the application core.

Network sample

For network communication, Zephyr provides the Bluetooth: HCI RPMsg sample that implements a Bluetooth Low Energy controller.

This sample must be programmed to the network core to run any Bluetooth Low Energy samples on nRF5340.

You might need to adjust the Kconfig configuration of this sample to make it compatible with the peer application. For example:

  • CONFIG_BT_MAX_CONN must be equal to the maximum number of connections supported by the application sample.

  • If the application sample uses specific Bluetooth LE functionality, this functionality must be enabled in the network sample as well. For example, you must modify the configuration of the network sample to make it compatible with the Bluetooth: Throughput sample:

    CONFIG_BT_CTLR_TX_BUFFER_SIZE=251
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
    

    This configuration guarantees that the network sample can handle the Bluetooth LE DLE update procedure, which is used in the Bluetooth: Throughput sample.

Application samples

The nRF Connect SDK provides a series of Bluetooth Low Energy samples, in addition to the Bluetooth samples in Zephyr. Most of these samples should run on the nRF5340 PDK, but not all have been thoroughly tested. Samples that use non-standard features of the Bluetooth Low Energy controller, like the Bluetooth: LLPM sample, are not supported.

Some samples require configuration adjustments to the Bluetooth: HCI RPMsg sample as described in the Network sample section.

These samples must be programmed to the application core, in the secure domain.

Building and programming a sample

You must program both the network sample and one of the supported Bluetooth Low Energy samples.

Build and program both samples separately by following the instructions in Building with SES. Make sure to use nrf5340_dk_nrf5340_cpunet as board name when building the network sample, and nrf5340_dk_nrf5340_cpuapp when building the application sample.

Important

When programming the samples from SEGGER Embedded Studio, you might get an error message stating that the target cannot be identified. In this case, you can either modify your SEGGER Embedded Studio installation and projects to add support for programming nRF5340, or program the generated HEX files from the command line instead.

See the following sections for more information.

Adding support for programming nRF5340 in SES

The current version of the Nordic Edition of SEGGER Embedded Studio (v4.20a) does not include SEGGER J-Link version v6.54c. However, this J-Link version is required to program nRF5340 devices.

To add support for programming nRF5340 in SEGGER Embedded Studio, complete the following steps:

  1. Download and install the latest J-Link Software and Documentation Pack (v6.54c or later).

  2. Copy the JLink_x64.dll file from the J-Link installation directory into the bin folder of your SEGGER Embedded Studio (Nordic Edition) folder, replacing the existing file. On Windows, this file is by default located in C:/Program Files (x86)/SEGGER/JLink/JLink_x64.dll. Note that the file might be named differently for other operating systems.

  3. Restart SEGGER Embedded Studio.

  4. Open an nRF Connect SDK project with the full path to boards/arm/nrf5340_dk_nrf5340 in the Zephyr repository as board directory and either nrf5340_dk_nrf5340_cpunet or nrf5340_dk_nrf5340_cpuapp as board name.

  5. Right-click on the project in the Project Explorer and select Options.

  6. Navigate to Debug > Debugger.

  7. Double-click the value for Target Device and select nRF9160 from the list. nRF5340 is not included in the list yet, but selecting nRF9160 sets the required configuration.

  8. Double-click the value for Target Device again and enter nRF5340 in the search field. Click OK to use this value.

You can now build and program the sample for nRF5340.

Programming from the command line

To program a HEX file after building it with SEGGER Embedded Studio, open a command prompt in the build folder of the sample that you want to program and enter the following command:

west flash

If you prefer to use nrfjprog (which is part of the nRF Command Line Tools) instead, open a command prompt in the build folder of the network sample and enter the following commands to program the network sample:

nrfjprog -f NRF53 --coprocessor CP_NETWORK --eraseall
nrfjprog -f NRF53 --coprocessor CP_NETWORK --program zephyr/zephyr.hex

Then navigate to the build folder of the application sample and enter the following commands to program the application sample and reset the board:

nrfjprog -f NRF53 --eraseall
nrfjprog -f NRF53 --program zephyr/zephyr.hex

nrfjprog --pinreset