Important: Before you run this example, make sure to program the SoftDevice .
Also, make sure to program the BLE Secure DFU Bootloader .
The Buttonless Secure DFU Service Template Application is an example that shows the functionality of running a Buttonless Device Firmware Update using the hardware delivered in the nRF5 Development Kit.
You can configure this template project to either support bonds or not. If the template project is configured to support bonds, the application will exchange bond information with the bootloader, guaranteeing that only bonded devices are allowed to perform DFU operations.
For more information on the Buttonless Secure DFU Service, see Buttonless Secure DFU Service .
Configuration
To enable or disable the support of bonds, modify the configuration parameters in the
sdk_config
file. For details on editing the SDK configurations, see
SDK configuration header file
.
You can also use the following config parameters to customize the behavior of your application:
- NRF_DFU_BLE_ADV_NAME
- NRF_DFU_BLE_MIN_CONN_INTERVAL
- NRF_DFU_BLE_MAX_CONN_INTERVAL
- NRF_DFU_BLE_CONN_SUP_TIMEOUT_MS
When the application starts, the Buttonless Secure DFU Service is initialized.
- Note
- This example requires a compatible bootloader to be present (currently, only the secure BLE bootloader). Otherwise, it will hang indefinitely during boot-up.
- This application is not power optimized!
- The application will stop advertising after 3 minutes and go to System Off mode. Push Button 1 to restart advertising.
nRF52810 limitations:
Due to limited flash size on nRF52810, the following restrictions apply when using this SoC.
- It is not possible to perform SoftDevice updates, including combined bootloader and SoftDevice.
- The Debug version of the Secure DFU bootloader cannot be used together with this example on nRF52810.
Bootloader settings page
The bootloader settings page is required on the device so that it can boot the application. Among other information, this page contains the CRC value and length of the bootable application (if present). This CRC value is calculated on boot-up to verify that a valid application is present.
If there is no bootloader settings page present on the device, the bootloader creates a default version signifying that there is no application available to boot. In such case, the only option for the Secure DFU is to enter DFU mode during boot-up.
Programming a bootloader settings page with information about a bootable application is required for using Secure DFU compiled with bond support. The reason for this is that the Secure DFU bootloader has no functionality to create bonds with a client device and it relies on the main application on the device to do so.
For information on creating a valid bootloader settings page, see Generating bootloader settings .
Setup
You can find the source code and the project file of the example in the following folder:
<InstallFolder>\examples\ble_peripheral\ble_app_buttonless_dfu
Testing
Testing is done by using a pre-generated hex file that contains the following
- Debug version of Secure DFU bootloader
- SoftDevice
- Buttonless Secure DFU template application
- Bootloader settings page generated for the application.
- Note
- The Debug version of the Secure DFU bootloader is compiled with a signature public key that only works with pre-compiled test-images for doing firmware upgrade bundled with this release.
The hex files available for testing have been compiled with or without bond support.
- Note
- When devices are bonded, Service Changed indications must be enabled, if available, before starting the DFU process. Otherwise, the client will fail after the update if the new app's GATT database has changed.
Test the Buttonless DFU Template Application with the nRF Toolbox app, which is available on both iOS (App Store) and Android (Google Play). You can also test the application with nRF Connect by performing the following steps:
Testing Buttonless Secure DFU with bonds
This procedure assumes you are using nRF52832. If you are working with a different SoC, make the following changes.
- For nRF52840, substitute 'nrf52832' with 'nrf52840' and 's132' with 's140' in all paths.
- For nRF52810, substitute 'nrf52832' with 'nrf52810' and 's132' with 's112' in all paths.
-
Use nrfjprog to program the following precompiled hex file:
-
examples\dfu\secure_dfu_test_images\ble\nrf52832\sd_s132_bootloader_buttonless_with_setting_page_dfu_secure_ble_debug_with_bonds.hex
-
- Reset the board and observe that the BSP_INDICATE_ADVERTISING state is indicated.
- Bond to the device using nRF Connect (it is advertising as 'Nordic_Buttonless'). Click the settings button, select "Security Settings", check "Perform bonding", and click "Apply".
- Observe that the BSP_INDICATE_CONNECTED state is indicated.
-
Observe that the
Secure DFU serviceis shown in the connected device. Expand the service and observe that the characteristic namedButtonless Secure DFU with bondsis present.Buttonless Secure DFU with bonds - Enable indications on Service Changed characteristic if it exists.
- Click the DFU icon to start the Device Firmware Upgrade process. This will open up a window where you can browse to and select a firmware upgrade package to program on the device.
-
Pick a test image to program to the device, for example
examples\dfu\secure_dfu_test_images\ble\nrf52832\softdevice_s132.zip. ClickStart DFU. - Observe the progress indication for the Device Firmware Upgrade.
- If the firmware upgrade is successful, the Device Firmware Upgrade window will close and the device will disconnect.
- Observe that the BSP_INDICATE_ADVERTISING state is indicated.
Testing Buttonless Secure DFU without bonds
-
Use nrfjprog to program the precompiled hex file:
-
examples\dfu\secure_dfu_test_images\ble\nrf52832\sd_s132_bootloader_buttonless_with_setting_page_dfu_secure_ble_debug_without_bonds.hex
-
- Reset the board and observe that the BSP_INDICATE_ADVERTISING state is indicated.
- Connect to the device using nRF Connect (it is advertising as 'Nordic_Buttonless').
- Observe that the BSP_INDICATE_CONNECTED state is indicated.
-
Observe that the
Secure DFU serviceis shown in the connected device. Expand the service and observe that the characteristic namedButtonless Secure DFU without bondsis present.Buttonless Secure DFU without bonds - Click the DFU icon to start the Device Firmware Upgrade process. This will open up a window where you can browse to and select a firmware upgrade package to program on the device.
-
Pick a test image to program to the device, for example
examples\dfu\secure_dfu_test_images\ble\nrf52832\softdevice_s132.zip. ClickStart DFU. - Observe the progress indication for the Device Firmware Upgrade.
- If the firmware upgrade is successful, the Device Firmware Upgrade window will close and the device will disconnect.
- Observe that the BSP_INDICATE_ADVERTISING state is indicated.