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 then 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 source code and project file for supporting BLE DFU Service can be found in the
<InstallFolder>\Nordic\nrf51822\Board\nrf6310\s110\ble_app_hrs
folder.
Open the project file ble_app_hrs_dfu.uvproj
with Keil for testing and examine the BLE DFU Service functionality in a BLE example.
The DFU BLE Service support Heart Rate Application can be tested using the Master Control Panel as follows:
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
reset_prepare()
function to allow application specific operations executed for a graceful system shutdownWhen supporting the DFU BLE Service in an existing BLE application the following procedure can be used:
<InstallFolder>\Nordic\nrf51822\Source\bootloader_dfu
<InstallFolder>\Nordic\nrf51822\Source\bootloader_dfu
<InstallFolder>\Nordic\nrf51822\Source\ble\ble_services
This can be seen in figure 1-3
In order to support the BLE DFU service in an application then 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 in order for the DFU Service to function properly then 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
)
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.
In order to support a graceful shutdown then 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 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 show the basic principle of switching from running a BLE Application to run the Bootloader/DFU.
After entering Bootloader/DFU mode then a SoftDevice, Bootloader or Application can be transfered Over-the-Air as described in Device Firmware Update over BLE.