Bluetooth: Central SMP Client

The Central SMP Client sample demonstrates how to update the firmware of a remote device over Bluetooth® Low Energy using the Simple Management Protocol (SMP). It uses the DFU target with the SMP Bluetooth backend to transfer the firmware image to the target device.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

nRF54LM20 DK

PCA10184

nrf54lm20dk

nrf54lm20dk/nrf54lm20b/cpuapp nrf54lm20dk/nrf54lm20a/cpuapp

nRF54L15 DK

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l15/cpuapp

nRF54L15 DK (emulating nRF54L10)

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l10/cpuapp

nRF54L15 DK (emulating nRF54L05)

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l05/cpuapp

nRF5340 DK

PCA10095

nrf5340dk

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

The sample requires a second device that acts as the remote target. The device must run an SMP server over Bluetooth LE, such as another development kit running the SMP server sample with the Bluetooth LE SMP transport enabled.

The sample looks for the firmware update image at /lfs1/update.bin. Before starting the update, upload a valid signed MCUboot update image for the remote target to this path.

To upload the firmware update image, use the nRF Device Manager mobile app or another client that supports the File System management group over SMP with Bluetooth LE:

Overview

The DFU target transfers arbitrary data supplied by the application. In a production application, the firmware update image can therefore come from any source the application can access, such as an SD card, external flash, or a web server. For demonstration purposes, this sample uses a LittleFS partition in non-volatile memory as intermediate storage for the firmware update image. To allow the image to be uploaded to that storage, the sample also acts as a Bluetooth LE peripheral that exposes an mcumgr SMP server with the File System management group.

On boot, the sample mounts the LittleFS file system and starts scanning as a central for the remote SMP server. The sample automatically connects to any device that advertises the SMP Service UUID. To connect based on other criteria, such as the device name, update the scan filter configuration in the prj.conf and src/main.c files. For details about the available filter types, see Filtering.

To upload the firmware update image for the remote target, press the following button:

Press Button 2.

The sample starts connectable advertising with the SMP service, so an mcumgr client such as the nRF Device Manager mobile app can connect and upload the signed image to /lfs1/update.bin using the File System management group over SMP. Advertising stops automatically once the host connects or after a 60-second timeout. Press the same button again to restart advertising.

By default, the File System management group grants a connected mcumgr client access to every file in the file system. The sample registers a file access hook (CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK) that rejects any path other than /lfs1/update.bin. The SMP transport is also configured without authentication, so it accepts any client that is in range.

To start the update of the remote target, press the following button:

Press Button 1.

The sample then performs the following operations:

  1. Opens /lfs1/update.bin on the LittleFS file system, checks that it starts with an MCUboot image header, and uses the file size as the exact size of the stored image.

  2. Initializes the SMP DFU target and uploads the image to the remote device in chunks using the MCUmgr image management group over SMP.

  3. Marks the uploaded image as pending (schedule update) and reboots the remote target so that MCUboot can apply the update.

Note

The uploaded image is only marked for test, not confirmed. After the reboot, MCUboot swaps in and runs the new image once. The target firmware can call the boot_write_img_confirmed() function to confirm the running image and make it permanent. Otherwise, MCUboot reverts to the previous image on the next reset.

User interface

Button 1:

Start the firmware update of the remote target.

Button 2:

Start advertising so a host can upload the firmware update image using the File System management group over SMP.

Building and running

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

For more security, it is recommended to use the */ns variant of the board target (see the Requirements section above.) When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

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

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

Button assignments depend on the development kit family. See the User interface section for the assignments.

  1. Connect the kit to the computer using a USB cable. The kit is assigned a serial port. Serial ports are referred to as COM ports on Windows, /dev/ttyACM devices on Linux, and /dev/tty devices on macOS. To list Nordic Semiconductor devices connected to your computer together with their serial ports, open a terminal and run the nrfutil device list command. Alternatively, check your operating system’s device manager or its equivalent.

  2. Connect to the kit with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.

  3. Program a second development kit with the SMP server sample and enable the Bluetooth LE SMP transport. This test uses the SMP server sample, but any sample that provides an SMP server with image management support over Bluetooth LE can act as the remote target.

  4. Observe and record the build time printed by the remote target.

  5. Perform a pristine rebuild of the SMP server sample, but do not program the rebuilt image to the remote target. The pristine rebuild ensures that the build time printed by the firmware on startup is updated, making it easy to verify if the target application was updated. Use the resulting zephyr.signed.bin file as the firmware update image.

  6. Reset the Central SMP Client.

  7. Observe that the text “Starting Bluetooth Central SMP Client sample” is printed on the COM listener running on the computer. The device starts scanning for peripherals with the SMP service.

  8. Press the advertising button on the Central SMP Client, then upload the signed image to the LittleFS file system using the nRF Device Manager mobile app:

    1. Start the nRF Device Manager mobile app for Android or the nRF Device Manager mobile app for iOS.

    2. Connect to the device that advertises as SMP Client Sample.

    3. Open the File System management (Files) section, select the signed image file, and upload it to /lfs1/update.bin.

  9. Observe that the kits connect. After service discovery completes, the sample reports that the SMP DFU client is ready.

  10. Press the firmware update button on the Central SMP Client. Observe messages similar to the following:

    Starting DFU of the remote target over BLE SMP
    Update image size: 262144 bytes
    Uploaded 4096 / 262144 bytes
    ...
    DFU completed. The target will reboot to apply the update.
    
  11. Observe that the remote target reboots into the new firmware. Verify that the printed build time differs from the build time recorded before the update.

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the following Zephyr libraries: