Nordic nRF5 串口固件更新例子 (C 代碼)

Overview

Based on the documentation of BLE Secure DFU example, it supports on the BLE / ANT/Serial UART DFU.

This blog would mainly focus on the Serial (UART) DFU.  Inside the Nordic official example, it would use the nrfutil (written in Python script) as the host application for device firmware upgrade.

I would use another alternative host application (in C code, based on nRFutil 3.5 version) to show how to do the application FW upgrade only.  This example is tested at the SDK 15.2 under Window or Linux Ubuntu environment.

Procedures 

Here are the procedure how to run on the serial DFU on NRF SDK.

Step 1

Download the Nordic NRF5 15.2 SDK (http://developer.nordicsemi.com/nRF5_SDK/)

Step 2

Prepare the GCC compiler Install the GNU ARM Embedded compiler / Linker

https://developer.arm.com/open-source/gnu-toolchain/gnu-rm

For example,  this compiler is installed at C:\Tools\gcc-arm-none-eabi-7-2018-q2-update-win32

Modify the corresponding makefile inside the Nordic SDK (e.g. window -- nRF5_SDK_15.2.0_9412b96\components\toolchain\gcc\Makefile.windows)

Nordic nRF5 串口固件更新例子 (C 代碼)_第1张图片

Step 3

Download / Compile the micro-ecc library (because secure DFU requires to use the micro-ecc 3rd party library)

Under Window:

  • Install the Chocolatey (Software Management Automation) 
  • Install the make package under chocolatey tool (run the command prompt terminal as administrator right)

Nordic nRF5 串口固件更新例子 (C 代碼)_第2张图片

  • Install the git at the terminal (recommended to use cmder terminal or download from choco install git)
  • Run the batch file (build_all.bat) under nRF5_SDK_15.2.0_9412b96\external\micro-ecc folder

Step 4

Generate the private key and public key (Make sure the version of nRFUtil is 4.0 if you are using the SDK 15.2 DFU,  nrfutil version)

You can download the pre-compiled execute file at https://github.com/NordicSemiconductor/pc-nrfutil/releases.  nRFUtil works on the Python 2.7.x currently.

@echo generate the private key
nrfutil keys generate demo_private.key

@echo generate the public_key from private key
nrfutil keys display --key pk --format code demo_private.key --out_file demo_public_key.c

Step 5

Update the public key at the bootloader project (dfu_public_key.c)

Recompile the bootloader (secure_bootloader\pca10040_uart_debug in this case) on the SES project file.

Step 6

Prepare two difference application firmware files and generate corresponding zip package for testing by using the private key.

nrfutil pkg generate --hw-version 52 --application-version 1 --application ble_app_uart_pca10040_s132_FW1.hex --sd-req 0xB7 --key-file demo_private.key app_uart_fw1.zip

nrfutil pkg generate --hw-version 52 --application-version 1 --application ble_app_uart_pca10040_s132_FW2.hex --sd-req 0xB7 --key-file demo_private.key app_uart_fw2.zip

The softdevice version (sd-req) can be found at nrfutil github (https://github.com/NordicSemiconductor/pc-nrfutil).

In this case, S132v6.1.1 (version 0xB7) is used.

Step 7

Program the softdevice on the nRF52 DK board.

nrfjprog --program s132_nrf52_6.1.1_softdevice.hex --reset --sectorerase

Program the bootloader on the DK board .

Step 8

Compile the Serial DFU Host (written in C code, UartSecureDFU.exe) tool

Nordic nRF5 串口固件更新例子 (C 代碼)_第3张图片

Step 9

Run the DFU by using the UartSecureDFU.exe

Nordic nRF5 串口固件更新例子 (C 代碼)_第4张图片

All the materials are placed at

https://github.com/jimmywong2003/NRF5_SERIAL_UART_DFU_HOST

 

https://jimmywongbluetooth.wordpress.com/2019/03/06/serial-uart-dfu-on-nrf5-sdk-by-using-host-tool-instead-of-nrfutil-in-c-code-application/

你可能感兴趣的:(Nordic nRF5 串口固件更新例子 (C 代碼))