Developing with nRF52 Series
The nRF Connect SDK provides support for developing on all nRF52 Series devices and contains board definitions for all development kits and reference design hardware.
See one of the following guides for detailed information about the corresponding nRF52 Series development kit (DK) hardware:
To get started with your nRF52 Series DK, follow the steps in the Getting started with nRF52 Series section. If you are not familiar with the nRF Connect SDK and its development environment, see Installation and Configuration and building documentation.
You can update the firmware of the device over the air, thus without a wired connection. Such an update is called a FOTA (firmware over-the-air) update. You can also use FOTA updates to replace the application.
For the possibility of introducing an upgradable bootloader, refer to Adding a bootloader chain.
FOTA updates are supported using MCUmgr’s Simple Management Protocol (SMP) over Bluetooth.
The application acts as a GATT server and allows the connected Bluetooth Central device to perform a firmware update.
To use FOTA over Bluetooth LE, samples must support Bluetooth peripheral role (
The application supports SMP handlers related to:
Operating System (OS) management used to reboot the device after the firmware upload is complete.
Erasing settings partition used to ensure that a new application is not booted with incompatible content in the settings partition written by the previous application.
To enable support for FOTA updates, do the following:
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFUKconfig option, which implies configuration of the following:
All of the SMP command handlers mentioned in the previous paragraph.
SMP BT reassembly feature.
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUPKconfig option automatically extends the Bluetooth buffers, which allows to speed up the FOTA transfer over Bluetooth, but also increases RAM usage.
If necessary, you can modify any of the implied options or defaulted values introduced by the
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU Kconfig option.
You can either add these Kconfig options to the configuration files of your application or have them inline in a project build command. Here is an example of how you can build for the Bluetooth: Peripheral LBS sample:
west build -b build_target -- -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
When you connect to the device after the build has completed and the firmware has been programmed to it, the SMP Service is enabled with the
If you want to add SMP Service to advertising data, refer to the SMP Server Sample.
Build configuration additions for MCUboot in the direct-xip mode
FOTA updates are also supported when MCUboot is in the direct-xip mode. In this mode, the MCUboot bootloader boots an image directly from a given slot, so the swap operation is not needed. It can be used either with or without the revert mechanism support. For more information about the direct-xip mode and the revert mechanism support, go to the Equal slots (direct-xip) section on the Bootloader page.
To use MCUboot in the direct-xip mode together with FOTA updates, do the following:
CONFIG_BOOT_DIRECT_XIPKconfig option in the MCUboot bootloader configuration.
CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIPKconfig option to inform the application about the chosen MCUboot mode of operation.
See how to build the Bluetooth: Peripheral LBS sample with MCUboot in the direct-xip mode when the revert mechanism support is disabled:
west build -b build_target -- -Dmcuboot_CONFIG_BOOT_DIRECT_XIP=y -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y -DCONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP=y
Optionally, if you want to enable the revert mechanism support, complete the following:
CONFIG_BOOT_DIRECT_XIP_REVERTKconfig option in the MCUboot bootloader configuration.
CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERTKconfig option in place of
CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIPto inform the application about the chosen MCUboot mode of operation.
See how to build the Bluetooth: Peripheral LBS sample with MCUboot in direct-xip mode when the revert mechanism support is enabled:
west build -b build_target -- -Dmcuboot_CONFIG_BOOT_DIRECT_XIP=y -Dmcuboot_CONFIG_BOOT_DIRECT_XIP_REVERT=y -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y -DCONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT=y
When building the application for the first time with MCUboot in direct-xip mode and the revert mechanism support, use an additional option
This option will mark the application as
confirmed during the image signing process.
If the application is built without this option, it will fail to boot.
It must, however, be disabled when building update images.
CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT Kconfig options automatically enable
CONFIG_BOOT_BUILD_DIRECT_XIP_VARIANT, which allows to build application update images for both slots.
To read about the files that are built when the option is enabled, refer to the MCUboot output build files page.
Support for FOTA updates with MCUboot in the direct-xip mode is available since the following versions of the nRF Connect Device Manager mobile app:
To perform a FOTA update, complete the following steps:
Generate the DFU package by building your application with the FOTA support over Bluetooth Low Energy. You can find the generated
dfu_application.ziparchive in the following directory
For each image included in the DFU-generated package, use a higher version number than your currently active firmware. Otherwise, the DFU target may reject the FOTA process due to a downgrade prevention mechanism.
dfu_application.ziparchive to your device. See Output build files (image files) for more information about the contents of update archive.
nRF Connect for Desktop does not currently support the FOTA process.
Use the nRF Connect Device Manager mobile app to update your device with the new firmware.
Ensure that you can access the
dfu_application.ziparchive from your phone or tablet.
In the mobile app, scan and select the device to update.
Switch to the Image tab.
Tap the SELECT FILE button and select the
Tap the START button.
Initiate the DFU process of transferring the image to the device:
If you are using an Android device, select a mode in the dialog window, and tap the START button.
If you are using an iOS device, tap the selected mode in the pop-up window.
Wait for the DFU to finish and then verify that the application works properly.
The SMP Server Sample demonstrates how to set up your project to support FOTA updates.
The sample documentation is from the Zephyr project and is incompatible with the Multi-image builds. When working in the nRF Connect SDK environment, ignore the part of the sample documentation that describes the building and programming steps. In nRF Connect SDK, you can build and program the SMP Server Sample as any other sample using the following commands:
west build -b build_target -- -DOVERLAY_CONFIG=overlay-bt.conf west flash
Make sure to indicate the
overlay-bt.conf overlay configuration for the Bluetooth transport like in the command example.
This configuration was carefully selected to achieve the maximum possible throughput of the FOTA update transport over Bluetooth with the help of the following features:
Bluetooth MTU - To increase the packet size of a single Bluetooth packet transmitted over the air (
Bluetooth connection parameters - To adaptively change the connection interval and latency on the detection of the SMP service activity (
Consider using these features in your project to speed up the FOTA update process.
When performing a FOTA update when working with the Bluetooth mesh protocol, use one of the following DFU methods:
DFU over Bluetooth mesh using the Zephyr Bluetooth mesh DFU subsystem.
Point-to-point DFU over Bluetooth Low Energy as described in FOTA over Bluetooth Low Energy above.
For more information about both methods, see Performing Device Firmware Updates (DFU) in Bluetooth mesh.
To perform a FOTA upgrade when working with the Matter protocol, use one of the following methods:
DFU over Bluetooth LE using either smartphone or PC command-line tool. Both options are similar to FOTA over Bluetooth Low Energy.
This protocol is not part of the Matter specification.
DFU over Matter using Matter-compliant BDX protocol and Matter OTA Provider device. This option requires an OpenThread Border Router (OTBR) set up either in Docker or on a Raspberry Pi.
For more information about both methods, read the Performing Device Firmware Upgrade in the nRF Connect examples page in the Matter documentation.
Thread does not offer a proprietary FOTA method.
You can enable support for FOTA over the Zigbee network using the Zigbee FOTA library. For detailed information about how to configure the Zigbee FOTA library for your application, see Configuring Zigbee FOTA.
If you have an nRF52 Series DK with the Bluetooth: Peripheral UART sample and either a dongle or second Nordic Semiconductor development kit that supports Bluetooth Low Energy, you can test the sample on your computer. Use the Bluetooth Low Energy app in nRF Connect for Desktop for testing.
To perform the test, connect to the nRF52 Series DK and complete the following steps:
Connect the dongle or second development kit to a USB port of your computer.
Open the Bluetooth Low Energy app.
Select the serial port that corresponds to the dongle or second development kit. Do not select the kit you want to test.
If the dongle or second development kit has not been used with the Bluetooth Low Energy app before, you may be asked to update the J-Link firmware and connectivity firmware on the nRF SoC to continue. When the nRF SoC has been updated with the correct firmware, the nRF Connect Bluetooth Low Energy app finishes connecting to your device over USB. When the connection is established, the device appears in the main view.
Click Start scan.
Find the DK you want to test and click the corresponding Connect button.
The default name for the Peripheral UART sample is Nordic_UART_Service.
Select the Universal Asynchronous Receiver/Transmitter (UART) RX characteristic value.
30 31 32 33 34 35 36 37 38 39(the hexadecimal value for the string “0123456789”) and click Write.
The data is transmitted over Bluetooth LE from the app to the DK that runs the Peripheral UART sample. The terminal emulator connected to the DK then displays
In the terminal emulator, enter any text, for example
The data is transmitted to the DK that runs the Peripheral UART sample. The UART TX characteristic displayed in the Bluetooth Low Energy app changes to the corresponding ASCII value. For example, the value for
48 65 6C 6C 6F.
You can program applications and samples on the nRF9160 DK after obtaining the corresponding firmware images.
To program applications using the Programmer app from nRF Connect for Desktop, follow the instructions in Installing the sample.
In Step 5, choose the
.hex file for the application you are programming.
Complete the following steps to build and program using the nRF Connect for VS Code extension:
Open Visual Studio Code.
If you installed the nRF Connect SDK using the Installing the nRF Connect SDK steps, you can click the Open VS Code button next to the version you installed.
Complete the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation.
Connect the nRF52 Series DK to the computer with a micro-USB cable, and then turn on the DK.
LED1 starts blinking.
In nRF Connect for VS Code extension, click the Flash option in the Actions View.
If you have multiple boards connected, you are prompted to pick a device at the top of the screen.
A small notification banner appears in the bottom right corner of Visual Studio Code to display the progress and confirm when the flash is complete.
Complete the command-line build setup before you start building nRF Connect SDK projects on the command line.
To build and program the source code from the command line, complete the following steps:
Open a terminal window.
Go to the specific sample or application directory.
For example, the folder path is
ncs/nrf/applications/nrf_desktopwhen building the source code for the nRF Desktop application.
Make sure that you have the required version of the nRF Connect SDK repository by pulling the nRF Connect SDK repository sdk-nrf on GitHub.
To get the rest of the dependencies, run the
west updatecommand as follows:
To build the sample or application code, run the
west buildcommand as follows:
west build -b build_target -d destination_directory_name
For the build_target parameter, see the list of supported boards for the build target corresponding to the nRF52 Series DK you are using.
You can use the optional destination_directory_name parameter to specify the destination directory in the west command. By default, the build files are generated in
build/zephyr/if you have not specified a destination_directory_name.
Connect the nRF52 Series DK to the computer with a micro-USB cable, and turn on the DK.
LED1 starts blinking.
Program the sample or application to the device using the following command:
The device resets and runs the programmed sample or application.
The nRF Desktop application is a complete project that integrates Bluetooth LE, see the nRF Desktop application. You can build it for the nRF Desktop reference hardware or an nRF52840 DK.
The nRF Desktop is a reference design of a HID device that is connected to a host through Bluetooth LE or USB, or both. This application supports configurations for simple mouse, gaming mouse, keyboard, and USB dongle.