nRF51 SDK - S310 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Bootloader/DFU Keil project

Bootloader/DFU compile targets

The Bootloader/DFU project can be built using Keil uVision.

The project file contains three targets

Target Description
dfu_dual_bank_hci Project target using dual bank solution and image is transferred using HCI Transport layer on UART. See Serial (HCI)
dfu_single_bank_hci Project target using single bank solution and image is transferred using HCI Transport layer on UART. See Serial (HCI)
dfu_dual_bank_ble (s110) Project target using dual bank solution and image is transferred using BLE with the S110 SoftDevice. See BLE
dfu_dual_bank_ble (s310) Project target using dual bank solution and image is transferred using BLE with the S310 SoftDevice. See BLE

The target can be selected in the project chooser in Keil as seen in Figure 1.

The single bank principle is described further in Single Bank Flash Layout.
Dual bank description is found in Dual Bank Flash Layout.

keil_project_chooser.png
Figure 1: Choosing bootloader project in Keil.

In the nRF51 series, a SoftDevice will be placed at Code Region 0, starting at address 0x00000000.
In the Bootloader/DFU example, the S110 SoftDevice is used and thus it must be present a this address, (see the nRF51822 DK User Guide on how to flash the SoftDevice).

The SoftDevice will usually start the application located at the beginning of code region 1, which is 0x00016000. In order for the SoftDevice to be able to initiate a bootloader, instead of an application, the UICR.BOOTLOADERADDR register must be written. This register is located at address 0x10001014 .

The Bootloader/DFU is located at address 0x0003C000, as seen in Figure 2..

dfu_bootloader_flash_view.png
Figure 2: Bootloader/DFU Flash layout overview.

In the Bootloader/DFU project, the writing of the UICR.BOOTLOADERADDR is linked into the HEX file and will be written automatically when flashing the bootloader with nrfjprog.exe, see Bootloader/DFU Flashing.

This is ensured by the following code in bootloader_util_arm.c

uint32_t m_uicr_bootloader_start_address __attribute__((at(NRF_UICR_BOOT_START_ADDRESS))) = BOOTLOADER_REGION_START;

BOOTLOADER_REGION_START must point to the correct location of the bootloader in the flash. The location in this example is 0x0003C000.

Bootloader/DFU Flashing

The J-Link Target Driver used for flashing other example applications in the nRF51 SDK does not support writing of the UICR register.

Therefore it is necessary to use the nrfjprog.exe tool for programming the nRF51 with the Bootloader/DFU project.
The nrfjprog.exe is delivered as part of the nRF51 SDK installer, and should therefore already be present.

The Bootloader/DFU project is configured to use nrfjprog.exe per default, and is expecting the tool to be present in windows' system path. nrfjprog.exe programs the compiled and linked HEX file to the nRF51 chip when flashing from Keil uVision.

Figure 3 shows the settings for nrfjprog.exec in Keil.

keil_project_flash_tool.png
Figure 3: Flash tool configuration in Keil uVision

If more than one J-Link is present in the system, a pop-up windows will appear requiring the user to choose which to use. Choose the J-Link attached to the Development Kit containing the nRF51 Chip to be flashed with Bootloader/DFU. See Figure 5.

keil_project_popup.png
Figure 4: nrfjprog.exe Pop-up for J-Link selection

Bootloader/DFU Application Image Conversion

The DFU supports only binary images for data transfer as described in DFU Transport Layers.

When compiling an application, such as Heart Rate Measurement, two images are created.

  • A HEX file.
  • An AXF file.

Keil uVision contains a command line tool, fromelf.exe, which can convert the AXF file into a binary image.
The tool is located in the Keil installation folder as:

<Keil-folder>\ARM\ARMCC\bin\fromelf.exe

Converting an AXF image into BIN file can be done as:

<Keil-folder>\ARM\ARMCC\bin\fromelf.exe --bin --output <outfile.bin> <infile.axf>

Bootloader/DFU Flash relocation.

In case the Bootloader/DFU software is extended with additional functionality and a larger code size is needed, then it is possible to move the start address of the Bootloader/DFU. If moving the bootloader to a different location, as example 0x00038000, then the BOOTLOADER_REGION_START defined in dfu_types.h must be updated accordingly.

#define BOOTLOADER_REGION_START 0x0003C000

For the linker to work correctly, then changing BOOTLOADER_REGION_START also requires change to the Keil project. In Keil, go to project->options for target, and change the IROM1 Start address to the new value. Also remember to increase the Size field (default 0x4000 ).

As example, moving from address 0x0003C000, Size 0x4000 to new address 0x00038000 gives 0x4000 additional bytes (10 pages), thus the new size becomes 0x8000.

Note
Changing the Bootloader/DFU Start address requires the UICR register to be erased. To ensure correct behaviour, the following procedure should be followed
1) Erase the whole chip with nrfjprog.exe
2) Flash the SoftDevice
3) Flash the Bootloader/DFU with the new address.

Figure 5 shows the setting in Keil to modify, if the Bootloader/DFU start address must be changed.

Note
All Start addresses MUST be page aligned and the page size is 0x400 (1024d) bytes.
keil_project_bootloader_location.png
Figure 5: Bootloader/DFU Start address setting in Keil.