Device firmware updates (DFU) on the Nordic nRF52

I consider myself an optimist. In fact, I usually expect things to turn out well. However, even as an optimist, I know that everyone makes mistakes (especially myself). We have had some clients that expressed the desire to not spend time incorporating DFU in their products, citing that the firmware should be written without error for the first release (and in record time!). Here's the thing: unless you are deep-pocketed, have a trivial application, a lot of testing time, and are part of NASA, your firmware will not be perfect the first time.

You will need to incorporate device firmware updates in your application.

It's possible to do it with the Nordic nRF52. In this blog, it will be shown how to take one of the Nordic examples and update the nRF52-DK with it:

Requirements:

Step 1: Flash the IC with the Softdevice.

Open nRFGoStudio and connect your development kit through USB. Toggle the power switch to ON. You should see the nRF52 development kit represented as a segger programmer. Click on it.
nRFgostudio Click on the Program SoftDevice tab. Here, you want to program the SoftDevice hex file that comes with the SDK. In the case of the nRF52-DK, the file you need in <nRFx_SDK11_rootdirectory>/components/softdevice/s132/hex/s132_nrf52_2.0.0_softdevice.hex:
Once it's selected, click on the Program button.

In the output log section of nRFgo Studio you should see that the SoftDevice has been programmed successfully.

Step 2: Build and flash the Keil BLE Bootloader example project

In the Nordic SDK, you will find that there is a ready-to-go example project that shows how to perform a DFU through BLE.

It is located at:<nRFx_SDK11_rootdirectory>/examples/dfu/bootloader/pca10040/dual_bank_ble_s132/arm5_no_packs/dfu_dual_bank_ble_s132_pca10040.uvprojx:

This example contains the bootloader and DFU code.

Double-click on the example to open it. Click on the build button or press the F7 key to compile.

Note: You may need to install the Keil MDK project packs associated with the Nordic Semiconductor devices.

Make sure the development kit is plugged in and the power switch is toggled to ON. Click on the LOAD button to flash the firmware. If you have any problems with this step, make sure the latest nrfjprog.exe executable is installed and the right executable is pointed to in your environment system PATH variable.

Step 3: Build the Heart Rate Sensor project and package it.

The next step is to build the target application and package it in such a way that you can flash it through BLE.

Compile the project but don't flash your board with it. You will want to flash it through BLE from your smartphone. The compilation with produce a .hex file.
The next step is to use the Nordic utilities to package this hex file into a format that contains information about the binary file alongside it. You do this with a program called nrfutils.exe.
Open a command window and change your working directory to where the compiled hex file is. In that directory, execute the command:
"C:\Program Files (x86)\Nordic Semiconductor\Master Control Panel\3.10.0.14\nrf\nrfutil.exe" dfu genpkg --application-version 1 --application nrf52832_xxaa_s132.hex hrs.zip

A .zip file called hrs.zip should appear in your working directory. If you open the zip you should see it contains three files:

  • manifest.json
  • nrf52832xxaas132.bin
  • nrf52832xxaas132.dat

The manifest contains the information about the binary (application version, crc, etc):
{ "manifest": { "application": { "bin_file": "nrf52832_xxaa_s132.bin", "dat_file": "nrf52832_xxaa_s132.dat", "init_packet_data": { "application_version": 1, "device_revision": 65535, "device_type": 65535, "firmware_crc16": 9775, "softdevice_req": [ 65534 ] } }, "dfu_version": 0.5 } }

Your .bin file contains the application and the .dat file contains almost the same data as json, but in binary.

Step 4: Flash the new firmware using BLE bootloader

There are many ways of uploading a new firmware file to your smartphone. It's a matter of drag-and-drop with Android, but it's a whole other ballgame when it comes to iOS. The easiest way I found was to send it to myself by e-mail and open the attachment with the nRF-toolbox app.

Open the attachment with the nRF toolbox app. This will copy the zip file to the app and make it available.
Open the nRF Toolbox app and select DFU. Tap on "Select Device". You should see the your Dev kit running the bootloader app as "DfuTarg". Tap on it.
Back to the upload screen, tap "Select File". Tap on the hrs.zip file you copied from the e-mail earlier.
Tap on "Upload File"
A dialog pop-up indicates that the DFU is complete.

References

Nordic SDK Documentation

This post was written by our former employee Alexander Courtemanche.


Motsai designs and builds innovative embedded systems, and is the leading Canadian developer of miniature low-power, wireless devices used in wearables and human motion analysis. Please feel free to send us an email at info@motsai.com or drop us a line at +1-888 -849-6956. Don't forget to signup for blog updates below.

Motsai Research

Read more posts by this author.

Subscribe to Motsai Musings

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!
Motsai Inc
1395 rue Marie-Victorin
Saint Bruno-de-Montaville, Quebec J3V 6B7
Canada
Email: info@motsai.com
Toll free: 1.888.849.6956