How to Create and Flash a DFU package to a CoreModule

This tutorial will cover a couple of topics:

1-Building an NRF52 project from the SDK.

2-Steps to convert the application into a .zip distribution package

3-How to DFU from a smartphone to the CoreModule.

1- Building an NRF52 project from the SDK.

For this example we will be flashing the blinky project provided by the NRF52 SDK. The first step is to build the project.

1.1- For steps on setting up the necessary tools (GCC, MinGW) follow this tutorial.

1.2- For steps on setting up the Nordic NRF52 SDK follow this tutorial.

1.3- Open a command terminal and navigate to the Blinky Project in the NRF52 SDK. Using: >cd [YourDirectory]\PUREmodules\nrf52\nRF5_SDK_12.2.0_f012efa\examples\peripheral\blinky\pca10040\s132\armgcc

Note: Pictures contain paths on my computer. Just replace "Users/Michael/Desktop/" with your directory for the PureModules repo.

1.4- Run make command

>make

2- Create a zip distribution package from the built application

2.1- Create public key.

-It is important that the zip package you build has the same key as the one we have flashed to the CoreModule. Here are the steps for getting the correct public key. Our private key is located in the Puremodules/nrf52 folder.

Run:

> nrfutil keys display --key pk --format code ../../../../../../../private.pem --out_file dfu_public_key.c

-This will create a dfu_public_key file as shown below.

2.2- Create zip distribution package.

-We want to create a distribution package that also contains the Bootloader so that you can continue to wirelessly re-flashing the board.

2.2.1- Create a Settings.hex file

> nrfutil settings generate --family NRF52 --application nrf52832_xxaa.hex --application-version 3 --bootloader-version 2 --bl-settings-version 1 settings.hex

2.2.2- Combine Softdevice with Bootloader

A) Navigate to the Bootloader in your nrf52 sdk and replace the key with your key.

> cd [YOURDIRECTORY]\nRF5_SDK_12.2.0_f012efa\examples\dfu\bootloader_secure\

B) Replace the dfu_public_key.c file in this directory with the one created in the last step. (peripheral/ blinky/pca10040/s132/armgcc)

C) Build the project by running:

>make

-This will create the bootloader hex file inside the _build folder as shown below.

D) I will rename this file to nrf52832_bootloader.hex to not confuse it with the blinky file's hex file and move it into our [peripheral/ blinky/pca10040/s132/armgcc] directory.

-Your directory should look something like this:

E) Navigate to the directory above and merge the SoftDevice (SD) and the Bootloader (BL) using the following command:

> mergehex --merge ../../../../../../components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex nrf52832_bootloader.hex --output SD_BL.hex

2.2.3- Add Application to SD_BL using the following command:

>mergehex --merge SD_BL.hex _build/nrf52832_xxaa.hex --output SD_BL_APP.hex

2.2.4- Add settings file to BL/SD/APP file.

> mergehex --merge SD_BL_APP.hex settings.hex --output SD_BL_APP_valid.hex

3) Flash your project

If you have a wired connection to your CoreModule you can flash your project using the command below. If you do not have a wired connection, continue to step 4.

> nrfjprog --chiperase --program SD_BL_APP_valid.hex -f NRF52 -r

4) Create a .zip distribution package to wirelessly program CoreModule

>nrfutil pkg generate --hw-version 52 --sd-req 0x8C --application-version 4 --application SD_BL_APP_valid.hex --key-file ../../../../../../../private.pem app_dfu_package.zip

5) Move the app_dfu_package.zip to your phone.

-I usually just email it to myself and download it on my phone.

6) Open nrftoolbox app on your phone. Go to the "dfu" tab.

-Press SELECT FILE and navigate to the app_dfu_package on your phone.

-Press SELECT DEVICE and find your PureEngineering-CoreModule.

-Press UPLOAD

For more information on setting up DFU packages follow this link:

http://infocenter.nordicsemi.com/pdf/nrfutil_v1.0.pdf