The Device Firmware Upgrade over TFTP is an example that uses the TFTP module and the Background DFU library to show how to update firmware using IPv6 connectivity.
To demonstrate support for background DFU on nRF52, Nordic's IPv6 stack and TFTP protocol are used.
This example implements a simple application which involves the Background DFU module providing the upgrading service as a background process.
This example requires you to create new firmware images. For more information, see Creating DFU images.
The demo setup and flow diagram are presented in Figure 1.
This example demonstrates how Nordic's IPv6 stack can be used for transmitting and receiving new firmware. It uses the TFTP module as a transport layer to transfer new firmware.
The application spends most of the time in normal IDLE mode. In the background, the software configuration file is downloading and checking every time the user pushes a button. The configuration file is located on the TFTP server and is read to determine when it should download and apply new firmware. It checks the current CRC32 firmware block and compares it with the values obtained from the configuration file. If DFU module decides to download new firmware, it starts downloading an init file used to perform a secure update. When the init file is downloaded, the Background DFU module starts retrieving the firmware image.
The MSC below provides an overview of the data exchange in the application between the node (nRF52) and the router/cloud in two instances:
Each device has its own configuration file. The path for those files is created in the following way:
In the above file path:
This file should be a JSON-formatted object that consists of a few parts: one per each firmware type, one for paths to init files, and one for paths to firmware images. For example:
Each part is described by four values and the path to the appropriate init file and firmware block:
In order to configure new firmware, modify the JSON elements to match the new firmware path, size, and its CRC32, and place it in the corresponding field. If any type of image is not available for download, set the sizes and CRC to 0 and paths to empty string "". Use the trigger_creator.py
Python script that is available in the example directory to prepare the JSON file automatically.
This section summarizes the usage of nRF52 resources and common modules in the examples apart from the IoT 6LoWPAN and IPv6 stack library.
Module | Inclusion/Usage | Description |
---|---|---|
Timer | 3 | Two timers - IoT timer, button module. |
Buttons | 1 | One button is used to start downloading a firmware configuration file. |
LEDs | 4 | LEDs are used to indicate that the application is still working and to show if it is connected. See LED assignments. |
Scheduler | Yes | Scheduler is used for processing stack events. |
You can find the source code and the project file of the example in the following folder: <InstallFolder>\examples\iot\tftp\background_dfu
Application State | LED 1 State | LED 2 State | LED 3 State | LED 4 State |
---|---|---|---|---|
Advertising | BLINKING | OFF | OFF | OFF |
IPv6 Interface Up | OFF | ON | OFF | OFF |
IPv6 Interface Down | ON | BLINKING | OFF | OFF |
ASSERT | ON | ON | ON | ON |
See Connecting devices to the router for a list of relevant Linux commands.
Unless stated otherwise, run all of the presented commands in the main folder of the background DFU example: <InstallFolder>\examples\iot\tftp\background_dfu
.
The <ProjectFolder>
is located at:
<InstallFolder>\examples\iot\tftp\background_dfu\pca10040\s132\armgcc
nRF52840: <InstallFolder>\examples\iot\tftp\background_dfu\pca10056\s140\armgcc
dfu_public_key.c:
dfu_public_key.c
file to the project folder <InstallFolder>\examples\dfu
, replacing the existing file. <InstallFolder>\examples\iot\tftp\background_dfu
. Use the path provided above.<InstallFolder>\examples\iot\bootloader
directory.make
command in the <ProjectFolder>
.main()
function: make
command in the <ProjectFolder>
.By default, the UART interface is connected to a computer via a J-Link virtual USB serial interface. In order to read from this interface:
Property | Value |
---|---|
Baud rate | 115200 |
Flow control | None |
Data bits | 8 bits |
Number of stop bits | 1 bit |
Parity | None |