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:
- Nordic nRF52-DK hardware
- A smartphone with the nRF Toolbox app
- Nordic nRF52 command line tools
- Nordic nRFx SDK
- Keil uVision with the nRF5x MD5 pack or GNU Maketools
- nRFGo Studio
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
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:
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\188.8.131.52\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:
The manifest contains the information about the binary (application version, crc, etc):
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.
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 email@example.com or drop us a line at +1-888 -849-6956. Don't forget to signup for blog updates below.