FOTA mbed app to NRF52_DK with Nordic DFU boot loader and SDK 14.2

Prerequisites

  • I assume you have set up mbed-cli and gcc arm toolchain and are able to build mbed projects using mbed-cli. Make sure to use gcc-arm-none-eabi 4.9
  • Download and unpack Nordic SDK 14.2
  • Install nrfutil
  • Install nRF5x Command Line Tools
  • Install Android app "nRF Toolbox" or it's analog for iOS.

Process

Prepare secret key

  1. Create key and store it somewhere in a safe place:

nrfutil keys generate private.pem

Prepare NRF52_DK

  1. Generate code view for public key:

nrfutil keys display --key pk --format code private.pem
  1. Replace content of file {NRF SDK PATH}/examples/dfu/dfu_req_handling/dfu_public_key.c with generated text
  2. Setup micro-ecc
  3. Flash SoftDevice. In NRF SDK enter any example requiring BLE and run flash_softdevice target. For example:

cd {NRF SDK PATH}/components/softdevice/s132/hex
nrfjprog -f nrf52 --program s132_nrf52_5.0.0_softdevice.hex --sectorerase
  1. Compile and flash dfu boot loader with generated key.

cd {NRF SDK PATH}/examples/dfu/bootloader_secure_ble/pca10040/armgcc/
make
cd _build
{path to nrfjprog}/nrfjprog --reset --program nrf52832_xxaa_s132.hex --family NRF52 --sectorerase

Prepare firmware

We will be using mbed-os-example-blinky as exemplar project to do FOTA.

  1. Create mbed project:

mbed import mbed-os-example-blinky
cd mbed-os-example-blinky
  1. Create or open file mbed_app.json in the root folder of application (If created, don't forget to add root braces {}). Add to it:

"target_overrides": {
  "*": {
    "target.mbed_app_start": "0x23000",
    "target.mbed_app_size": "0x55000",
    "target.bootloader_img": null
  }
}

target.mbed_app_start and target.mbed_app_size set correct place for our app in device flash memory, target.bootloader_img set to null makes compiler to not embed SoftDevice to our hex since SoftDevice is already flashed onto device.

  1. Build mbed project and create firmware zip using nrfutil and generated previously private key:

mbed compile -t GCC_ARM -m NRF52_DK
cd BUILD/NRF52_DK/GCC_ARM/
nrfutil pkg generate --hw-version 52 --sd-req 0x9D --application-version 1 --application mbed-os-example-blinky.hex --key-file {{path_to_private_key}} package.zip

FOTA

  1. Upload package.zip to mobile device
  2. Power on NRF52_DK while holding button 4. It will enter DFU mode
  3. In nRF Toolbox press DFU button
  4. Select package.zip as firmware
  5. Select DfuTarg device (that is name of our device in DFU mode)
  6. Upload firmware


5 comments on FOTA mbed app to NRF52_DK with Nordic DFU boot loader and SDK 14.2:

17 Jul 2018

Thanks for the post! However, branch feature-nrf528xx no longer exists as far as I can see.

19 Jul 2018

I finally got this working.. You have to flash SoftDevice BEFORE flashing the bootloader. And it is not needed to update to branch feature-nrf528xx, however I updated to master branch (there were some memory issues in latest mbed os release, fixed in master)

03 Aug 2018

Andreas Krebs, thanks for your comments. Updated article.

23 Oct 2018

Hi did you implement the DFU service for buttonless FOTA?

05 Nov 2018

No, I didn't try to do buttonless FOTA

Please log in to post comments.