nRF51 SDK - S110 SoftDevice
|
This page describes how to include and use the possibility of including the DFU BLE Service into an application so that Bootloader/DFU mode can be automatically entered.
After entering Bootloader/DFU mode, a DFU Over-The-Air update can be performed.
An example application based on Heart Rate Application has been created for testing this feature. The project file for this example is located together with the existing Heart Rate example.
The name of the example is experiemental_ble_app_hrs_s110_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>\Nordic\nrf51\example\ble_peripheral\ble_app_hrs
Open the project file experimental_ble_app_hrs_dfu.uvproj
with Keil for testing and examine the BLE DFU Service functionality in a BLE example.
Test the DFU BLE Service support Heart Rate Application with the Master Control Panel by performing the following steps:
Any BLE application can easily be extended to support the DFU Service, which allows nRF51 to enter DFU mode by writing 'DFU Start' to the DFU Service Control Point.
The following must be done to support entering of DFU mode from application:
When supporting the DFU BLE Service in an existing BLE application, the following procedure can be used:
<InstallFolder>\Nordic\nrf51\components\libraries\bootloader_dfu
<InstallFolder>\Nordic\nrf51\components\libraries\bootloader_dfu
<InstallFolder>\Nordic\nrf51\components\ble\ble_services\ble_dfu
See figures 1-3:
To support the BLE DFU service in an application, the DFU Service must be initialized in the application.
The following code snippet shows how this is done in the Heart Rate example supporting DFU in main.c:
#include "ble_dfu.h" #include "dfu_app_handler.h"
Remember that for the DFU Service to function properly, all BLE Stack events from the SoftDevice must be propagated to the DFU Service by calling ble_dfu_on_ble_evt containing the event as parameter.
BLE Stack events are usually progated to sub modules in main.c
in a function named ble_evt_dispatch(ble_evt_t * p_ble_evt).
When supporting the DFU BLE Service in an application that uses the Device Manager, it is possible to transfer bonding information from the application to the Bootloader/DFU.
Bonding information consists of the peer address, IRK, and LTK of the connected peer.
The bonding information will be used to re-establish the secure connection between the devices.
When switching from application to Bootloader/DFU mode as described in Switching from application to Bootloader/DFU mode, the Bootloader/DFU will do directed advertisement if bonding information is available. If the peer does not reconnect to the device while doing directed advertisement, the system will reset and load the installed application again.
The keys needed to re-establish the secure connection can be retrieved using dm_distributed_keys_get. After retrieving the keys from the Device Manager, they must be passed to the Bootloader/DFU.
Before switching from application to bootloader/DFU mode for receiving a new firmware image, it might be important for the current application to shut down gracefully.
To support a graceful shutdown, the dfu_app_handler.c supports a reset_prepare function to be implemented in the application. This function will be executed prior to the reset and allows the application to perform any tasks considered important prior to reset.
Be aware that the reset will not occur until the reset_prepare function returns.
Such tasks could be:
In main.c
of the Heart Rate example, the prepare function contains:
Example of Reset prepare implementation:
Switching from running the application into Bootloader/DFU mode is done through writing to the control point of the DFU Service. See DFU Control Point for further details.
The below flowchart shows the basic principle of switching from running a BLE Application to run the Bootloader/DFU.
After entering Bootloader/DFU mode, a SoftDevice, Bootloader, or Application can be transfered Over-the-Air as described in Device Firmware Update over BLE.