Introduction
This section describes the Over The Air (OTA) Device Firmware Update (DFU) solution found in the nRF AirFuel SDK. The DFU solution makes it possible to update the PRU/PTU application in a device. To do this, a bootloader supporting the DFU profile is installed with the application and the SoftDevice. At this time, reliable update of the application code is supported using a banking system where the application is not replaced until the DFU process is complete, and the application has been validated.
DFU device overview.
The DFU Project
The DFU project can be found in apps/dfu/. The DFU project contains both the bootloader and the DFU profile.
When powering up a device, the bootloader will either start the DFU profile or jump to the application. The DFU profile will be started if one of the following conditions is fulfilled:
- There is no application in the device (only SoftDevice and bootloader has been flashed).
- The DFU button is being pressed at reset.
- The application has triggered the DFU process and written a register to indicate that the bootloader should execute the DFU profile on the next reset.
If none of these conditions occur, the application will be started normally.
If the DFU profile is started the device will begin advertising as "WPT DFU", and it will be possible for a peer device to perform the DFU process.
A complete description of the DFU Profile can be found in the nRF5 SDK documentation.
Supporting DFU on PRU/PTU
It is not required that the PRU/PTU application is used to enter DFU mode. The bootloader can be configured to start the DFU process if the DFU button is pressed and held on reset when the device is powered up. Alternatively, entering DFU mode can be done from the PRU/PTU application. This is demonstrated in two ways is the SDK example.
- Pressing the DFU button for more than 5 seconds while the PRU/PTU application is running.
- Sending a special debug command "8" (see section "Debug and Test Interface")
In order to build a PRU/PTU application with support for initiating the DFU profile, select the *_DFU target in uVision. (Note: You need to re-build the project after updating the target selection.)
Two functions should be re-implemented by the PRU/PTU application when supporting jumping to DFU mode:
- bool dfu_check(void): Will be called in the SDK example after a 5 second DFU button press. The purpose of the function is to determine if DFU mode can be entered. The SDK implementation, for example, checks the following before allowing entry to DFU Mode:
- PTU: Are devices are being charged.
- PRU: Is it being powered from coil.
- void terminate(void): Will be called after dfu_check() in the SDK example. The purpose of this function is to make sure the device is in a valid state by stopping the WPT profile.
Example implementations of these functions could be found in [pru/ptu].c.
void dfu_start() triggers DFU mode from the application by writing a special value to a retention register (which is not cleared on reset) and then performing a reset.
Notes on supporting DFU on a PRU
Depending on the architecture of the PRU system, it might not be possible to perform the DFU process. It is only possible to perform DFU on a PRU where the BLE controller is powered independently (i.e. not directly from a PTU transmitter power field). This is due to the fact that the WPT profile cannot be active during the DFU process, so the PTU will not provide any power to the PRU.
The example implementation of void teardown(void) for the PRU ensures this by checking that VRECT is 0.
The DFU Host
The device that sends the firmware update to the PRU/PTU target needs to follow the DFU protocol described in the nRF5 SDK documentation. The Nordic Semiconductor Master Control Panel supports this protocol.
Example
This example shows how to build a PRU/PTU application with support for DFU, the process of entering DFU mode, and performing a firmware update.
The steps taken are:
- Flash device with 3 hex files: SoftDevice, bootloader with support for DFU profile and PRU/PTU application.
- Verify that PRU/PTU application is running
- Enter DFU mode
- Perform DFU
- Verify that new PRU/PTU application is running.
Requirements
- 1 nRF51 Dongle (PCA10000), Evaluation kit (PCA10001) or Development kit (PCA10028) - To use with Master Control Panel
- 1 PCA10028 or PCA10040 - For the PRU/PTU application. We will assume PCA10028 in this example.
- nRFgo Studio >= 1.21.0 x64/x86
- Master Control Panel >= 3.10.0 x64/x86
- Putty (or any application which allows you to communicate over serial port)
NOTE: All paths are relative to the AirFuel SDK install location
Howto
- Load the SoftDevice
- Open nRFgo Studio.
- Select correct PCA10028 device from list to the bottom left.
- Select "Program SoftDevice" tab
- UNCHECK "Enable SoftDevice Protection"
- Locate softdevice hex file:
- Press "Program"
- Compile and load the bootloader
- Open the apps/dfu/pca10028/dual_bank_ble_s130/arm/dfu_dual_bank_ble_s130_pca10028.uvprojx Keil uVision project.
- Build (F7)
- Open nRFgo Studio.
- Select correct PCA10028 device from list to the bottom left.
- Select "Program Bootloader" tab
- Locate bootloader hex file: apps/dfu/pca10028/dual_bank_ble_s130/arm/_build/nrf51422_xxac.hex
- Press "Program"
- Compile and load the PRU/PTU application
- Open the PRU/PTU project
- Select the nrf51422_xxac_s130_DFU target. [NOTE: When changing target it is required to rebuild the project]
- Build (F7)
- Open nRFgo Studio.
- Select correct PCA10028 device from list to the bottom left.
- Select "Program Application" tab
- Locate application hex file: apps/wpt/pru_app/pca10028/s130/arm/_build_DFU/pru_app_s130_pca10028_DFU.hex
- Press "Program"
- Verify that PRU/PTU application is running and jump to DFU mode.
- Identify the COM port associated with the PCA10028 (can be seen in Master Control Panel)
- Connect to it over serial/UART with the following parameters:
- Baud: 460800
- Data bits: 8
- Stop bits: 1
- Parity: None
- Flow Control: RTS/CTS
- Press "z"
- Press "8" to enter DFU mode.
- Perform DFU using Master Control Panel
- Start Master Control Panel
- Select the board you want to use to perform DFU.
- Press "File" -> "Flash Programming". Select "MEFW nRf51822 0.10.0". Press "Program"
- Wait for it to finish and press "Close"
- Press "Start Discovery"
- Wait for device named "Dfu Targ" to be listed.
- Click its name and press "Select Device"
- Press "Connect"
- Wait for message saying its connected.
- Press "Discover Services"
- Press "Enable Services"
- Wait for "DFU" button to be enabled.
- Press "DFU"
- Press "Browse"
- Locate hex file generated in step 3.
- Select "Application"
- Press "Program"
- Verify that PTU/PRU application has been loaded.
- Connect to the device as described in step 4.
- Press "z"
The device should now restart, and you should see regular PTU/PRU output.