[Nordic] nRF52810 OTA upgrade (two)-how to use DFU

related articles

1. "[Nordic] nRF52810 OTA upgrade (1)-DFU environment setup"
2. "[Nordic] nRF52810 OTA upgrade (2)-How to use DFU"
3. "[Nordic] nRF52810 OTA upgrade (3)-DFU theoretical analysis 》

1 Introduction

This article is based on "[Nordic] nRF52810 OTA Upgrade (1)-DFU Environment Setup" to implement the DFU OTA firmware upgrade function.

2. Generate micro_ecc_lib_nrf52.lib library

Nordic will use ECC to verify and authenticate firmware when using DFU for OTA upgrade, so it needs to be produced in the DFU project micro_ecc_lib_nrf52.lib.

  1. micro-ecc-masterCopy the source code downloaded in the previous article to the SDK directory external\micro-eccand rename itmicro-ecc
    Insert picture description here
    Insert picture description here

  2. Open the Cygwin command line
    Insert picture description here

  3. cd to the micro-ecc project directory:nRF5_SDK_17.0.2_d674dde\external\micro-ecc\nrf52nf_keil\armgcc
    Insert picture description here

  4. Execute makecommand
    Insert picture description here
    here because there is no tool to find gcc error occurs, modify the file: nRF5_SDK_17.0.2_d674dde\components\toolchain\gcc\Makefile.windows
    the

    GNU_INSTALL_ROOT := C:/Program Files (x86)/GNU Tools ARM Embedded/9 2019-q4-major/bin/
    GNU_VERSION := 9.2.1
    GNU_PREFIX := arm-none-eabi
    

    Modify the actual installation directory of gcc:

    GNU_INSTALL_ROOT := D:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/
    GNU_VERSION := 10.2.1
    GNU_PREFIX := arm-none-eabi
    

    Execute again makeand the compilation is successful.
    Insert picture description here
    Insert picture description here

3. Generate dfu_public_key.c and join

  1. Generate a private key
    Create a new folder in the D drive, name it key, and enter the following in the cmd command:nrfutil keys generate D:\key\private.keycommand, generate a private key file private.key
    Insert picture description here

    Note: To save the private key private.key, every new firmware upgrade in the future must be signed with this private key. Once lost, DFU will not be able to proceed.

  2. Generate public key
    Enter the command to generate public key:nrfutil keys display --key pk --format code D:\key\private.key --out_file public_key.c
    Insert picture description here
    produce public key public_key.c on the desktop
    Insert picture description here
  3. Add the public key to the project.
    Rename the public key public_key.c to dfu_public_key.c, and replace the file withnRF5_SDK_17.0.2_d674dde\examples\dfudfu_public_key.c in thedirectory
    Insert picture description here

4. Compile the bootloader

Because of the nRF52810 platform I use here , I choose the dfu bootloader path as follows:
nRF5_SDK_17.0.2_d674dde\examples\dfu\secure_bootloader\pca10040e_s112_ble\arm5_no_packs
Insert picture description here
Compilation is successful:
Insert picture description here

5. Burn bootloader and SoftDevice hex files

Use jlink to burn bootloaderand SoftDevice:

  • Burn bootloader
    nRF5_SDK_17.0.2_d674dde\examples\dfu\secure_bootloader\pca10040e_s112_ble\arm5_no_packs\_build\nrf52810_xxaa_s112.hex
  • Burn SoftDevice
    nRF5_SDK_17.0.2_d674dde\components\softdevice\s112\hex\s112_nrf52_7.2.0_softdevice.hex

After burning, use the nRF ConnectAPP installed on the phone to search for BLE, and DfuTarg appears to indicate that it has entered the bootloader mode. Because application hex is not burned, it directly enters the bootloader mode.
Insert picture description here

6.nRF Connect APP for OTA upgrade

Upgrade the application firmware to the firmware compiled in the previous project:nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_uart\pca10040e\s112\arm5_no_packs\_build

  • Make an OTA upgrade package
    nrfutil pkg generate --hw-version 52 --application-version 1 --application nrf52810_xxaa.hex --sd-req 0x0103 --key-file D:\key\private.key dfufile.zip
    Insert picture description here

  • Copy the OTA upgrade package dfufile.zipto the phone

  • Connect BLE DfuTarg
    Insert picture description here

  • Click the small DFU icon in the upper right corner and select the ZIP filedfufile.zip
    Insert picture description here

  • during upgrade…
    Insert picture description here

  • The upgrade is successful, and the name Nordic_UART of application ble appears, as shown in the figure below:
    Insert picture description here

7. Errors that occur

  • Error 1

    ..\..\..\..\..\components\libraries\crypto\backend\micro_ecc\micro_ecc_backend_ecc.h(52): error:  #5: cannot open source input file "uECC.h": No such file or directory
      #include "uECC.h"
    ..\..\..\..\..\components\libraries\bootloader\dfu\nrf_dfu_validation.c: 0 warnings, 1 error
    

    Error analysis:
    Prompt that theuECC.hheader file isnot found.
    Solution:
    Refer to 2. Generate micro_ecc_lib_nrf52.lib library to solve the problem.

  • Error 2

    compiling dfu_public_key.c...
    ..\..\..\dfu_public_key.c(20): error:  #35: #error directive: "Debug public key not valid for production. Please see https://github.com/NordicSemiconductor/pc-nrfutil/blob/master/README.md to generate it"
      #error "Debug public key not valid for production. Please see https://github.com/NordicSemiconductor/pc-nrfutil/blob/master/README.md to generate it"
    ..\..\..\dfu_public_key.c: 0 warnings, 1 error
    

    Error analysis:
    There is no valid dfu encryption public key.
    Solution:
    Refer to 3. Generate dfu_public_key.c and add it to solve the problem.

Guess you like

Origin blog.csdn.net/ZHONGCAI0901/article/details/112311314