To show how to add BLE DFU Service support to an application, the SDK contains a version of the Heart Rate Application that includes DFU support. This example illustrates how a standard application can be extended so that you can easily update the device firmware at any time, just by connecting to the application.
The name of the example is ble_app_hrs_s130_with_dfu_pca10028. If you are not using the Keil Pack Installer, you can find the source code and project file of the example in the following folder: <InstallFolder>\examples\ble_peripheral\ble_app_hrs
When testing the example, you can choose to use bonding to share encryption keys between the application and the bootloader. If you use bonding, the link between the DFU target and the DFU controller will be re-established with encryption when the device restarts in bootloader mode. See Sharing bonding information for more information.
Testing the example with bonding
Test the Heart Rate Application with BLE DFU Service support using bonding with the Master Control Panel by performing the following steps:
- Program the DFU bootloader.
- Compile the application and perform a Device Firmware Update to program it. Observe that the BSP_INDICATE_ADVERTISING state is indicated.
- Connect to the device from Master Control Panel, then bond to it.
- Perform service discovery. The device is advertising as "Nordic_HRM". Observe that the BSP_INDICATE_CONNECTED state is indicated.
- Write the value "0200" to the Service Changed characteristic to enable the Service Changed indication when the GATT Server Attribute Table changes.
- Write the value "0100" to the CCCD for the DFU Control Point characteristic or click Enable services to enable DFU notifications.
- Write the command to start a DFU procedure to the DFU Control Point:
- "01-01" if you want to update the SoftDevice
- "01-02" if you want to update the bootloader
- "01-03" if you want to update the SoftDevice and bootloader
- "01-04" if you want to update the application
- Observe that the connection to the device is lost. The message "SERVER: Received Link Loss" is displayed in the log window.
- The device is now performing directed advertising to the bonded peer. When the connection is established, a Service Changed indication is received and displayed in the Master Control Panel.
- Perform a Device Firmware Update. You do not need to connect to the device again, because you are already connected.
Testing the example without bonding
Test the Heart Rate Application with BLE DFU Service support not using bonding with the Master Control Panel by performing the following steps:
- Program the DFU bootloader.
- Compile the application and perform a Device Firmware Update to program it. Observe that the BSP_INDICATE_ADVERTISING state is indicated.
- Connect to the device from Master Control Panel.
- Perform service discovery. The device is advertising as "Nordic_HRM". Observe that the BSP_INDICATE_CONNECTED state is indicated.
- Write the value "0100" to the CCCD for the DFU Control Point characteristic or click Enable services to enable DFU notifications.
- Write the command to start a DFU procedure to the DFU Control Point:
- "01-01" if you want to update the SoftDevice
- "01-02" if you want to update the bootloader
- "01-03" if you want to update the SoftDevice and bootloader
- "01-04" if you want to update the application
- Observe that the connection to the device is lost. The message "SERVER: Received Link Loss" is displayed in the log window.
- Click "Back" in the Master Control Panel to see an overview of the discovered devices.
- Clear the discovered devices and click "Start discovery".
- Verify that the device is now advertising as "DfuTarg".
- Perform a Device Firmware Update.