Device Firmware Updates (DFU) on the Nordic nRF52

We all consider ourself optimists when we write firmware.

In fact, we usually expect things to turn out well. However, even as an optimist, we know that everyone makes mistakes and even with the most perfect code, the requirements or environment may change and require updates in the product. 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 very deep-pocketed, have a trivial application, a lot of testing time, have a QA group the size 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 post, it will be shown how to take one of the Nordic examples and update the nRF52-DK with it:


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. 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\\nrf\nrfutil.exe" dfu genpkg --application-version 1 --application nrf52832_xxaa_s132.hex 

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

  • manifest.json
  • nrf52832_xxaa_s132.bin
  • nrf52832_xxaa_s132.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 a binary representation of it that is suitable for the bootloader to interpret it.

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 file you copied from the e-mail earlier.  Tap on “Upload File”   A dialog pop-up indicates that the DFU is complete.


Nordic SDK Documentation

Two Free Tools Not To Be Missed!

Motsai is committed to keeping you informed about emerging technologies and their potential contributions to your product development process.
We are pleased to present you with two resources focusing on trending technologies and the real issues in the product development process. To begin with, we have put together a guide covering everything you need to know about OEM and ODM, and more importantly, what information you need to make the best decisions for your product development.
In addition, we have written an e-book on micro FPGAs, an important technology that deserves a closer look.
Enjoy the discovery!

A guide to making the right decision!
We are pleased to send you “OEM vs ODM: a guide to navigating the creation of new electronic products”.
For over a decade, we have been accumulating useful information that we would now like to share with you, so that your electronic product development projects are a real success. DOWNLOAD

Micro FPGAs, or Field Programmable Gate Arrays, are revolutionary chips that you can program to perform complex digital calculations. They are becoming increasingly popular in product development due to their versatility and power.
Our ebook takes a closer look, explaining everything from the basics of micro FPGAs to their potential applications in product development.
It could be the game changer you need for your next project. DOWNLOAD

Comments are closed.