How to upgrade Specify FW from SPI flash on nRF52 Series

This blog is to show how to use the SPI bootloader to load the specify firmware from SPI flash for device firmware upgrade. Following up the blog (SPI bootloader), I would continuous to use the nRF52840 DK board and use its onboard qspi flash as SPI flash.

For example, there are 3 difference application firmware storing on the SPI flash.

By using the SPI bootloader, it would swap on the application region.

On each Application firmware, it consists of two binary files.

  • Initial header file of FW
  • Binary file of FW

The format of the init configure file is

WORDData field length = 16
WORDFirmware version
WORDFirmware size
WORDFirmware CRC-32
WORDCRC-32 for the 12-byte data
Header file of the FW (init)

The address of the application firmware on the SPI flash are

Test Firmwares

I used the ble_app_buttonless as the demo application firmware.

  • ble_app_buttonless_01.hex
  • ble_app_buttonless_02.hex
  • ble_app_buttonless_03.hex

Each application firmware has its own device name which would be shown during power up.

Each application firmware has the button to trigger for upgrade difference firmware by using the general retention register.

#define BOOTLOADER_DFU_START_FW1        0x03//00000011b
#define BOOTLOADER_DFU_START_FW2        0x0C//00001100b
#define BOOTLOADER_DFU_START_FW3        0x30//00110000b

Preparation the application firmware to store on QSPI flash

Generate the header file and binary file from the hex file.

nrfutil_spi pkg generate --hw-version 52 --application-version 1 --application ble_app_buttonless_01.hex --sd-req 0xAE
nrfutil_spi pkg generate --hw-version 52 --application-version 1 --application ble_app_buttonless_02.hex --sd-req 0xAE
nrfutil_spi pkg generate --hw-version 52 --application-version 1 --application ble_app_buttonless_03.hex --sd-req 0xAE

After unzip the file, it consists of binary file (.bin), header file (.dat) and file info (json).

By using the objcopy to re-map the address (in order to store on the QSPI),

arm-none-eabi-objcopy -v -I binary -O ihex --change-addresses 0x12000000 ble_app_buttonless_01_pkg\ble_app_buttonless_01.dat   qspi\ble_app_buttonless_01_qspi_init.hex
arm-none-eabi-objcopy -v -I binary -O ihex --change-addresses 0x12001000 ble_app_buttonless_01_pkg\ble_app_buttonless_01.bin   qspi\ble_app_buttonless_01_qspi_app.hex
arm-none-eabi-objcopy -v -I binary -O ihex --change-addresses 0x12020000 ble_app_buttonless_02_pkg\ble_app_buttonless_02.dat   qspi\ble_app_buttonless_02_qspi_init.hex
arm-none-eabi-objcopy -v -I binary -O ihex --change-addresses 0x12021000 ble_app_buttonless_02_pkg\ble_app_buttonless_02.bin   qspi\ble_app_buttonless_02_qspi_app.hex
arm-none-eabi-objcopy -v -I binary -O ihex --change-addresses 0x12040000 ble_app_buttonless_03_pkg\ble_app_buttonless_03.dat   qspi\ble_app_buttonless_03_qspi_init.hex
arm-none-eabi-objcopy -v -I binary -O ihex --change-addresses 0x12041000 ble_app_buttonless_03_pkg\ble_app_buttonless_03.bin   qspi\ble_app_buttonless_03_qspi_app.hex

For example,

  • QSPI address 0x1200000 is equal to the SPI flash address 0x0000 0000.
  • QSPI address 0x1202000 is equal to the SPI flash address 0x0002 0000.

Program the application firmware on the qspi flash,

nrfjprog -f nrf52 --qspicustominit --qspieraseall

nrfjprog -f nrf52 --qspicustominit --program qspi\ble_app_buttonless_01_qspi_init.hex
nrfjprog -f nrf52 --qspicustominit --program qspi\ble_app_buttonless_01_qspi_app.hex
nrfjprog -f nrf52 --qspicustominit --program qspi\ble_app_buttonless_02_qspi_init.hex
nrfjprog -f nrf52 --qspicustominit --program qspi\ble_app_buttonless_02_qspi_app.hex
nrfjprog -f nrf52 --qspicustominit --program qspi\ble_app_buttonless_03_qspi_init.hex
nrfjprog -f nrf52 --qspicustominit --program qspi\ble_app_buttonless_03_qspi_app.hex

After program the bootloader and softdevice,

By pressing the button on the NRF52840 DK,

  • Button 2 – Device 01 (ble_app_buttonless_01.hex)
  • Button 3 – Device 02 (ble_app_buttonless_02.hex)
  • Button 4 – Device 03 (ble_app_buttonless_03.hex)

All the demo hex can be found at URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.