nRF51 SDK - S110 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 over UART. See Serial (HCI)
dfu_single_bank_hci Project target using single bank solution and image is transferred using HCI Transport layer over 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

In the nRF51 series, a Master Boot Record (MBR) will be placed at address 0x00000000. The SoftDevice will be placed at address 0x00001000.
The s110 nRF51822 SoftDevice image includes both the MBR and the SoftDevice but on SoftDevice update only the SoftDevice will be updated. In the Bootloader/DFU example, the S110 SoftDevice v7.0.0 or later is used and thus it must be present at this address, (see the nRF51822 DK User Guide on how to flash the SoftDevice).

The MBR will initiate the Bootloader present at the address defined in UICR.BOOTLOADERADDR. During iniitialization the Bootloader will determine wether DFU mode should be entered or request the SoftDevice to start the application. UICR.BOOTLOADERADDR register is located at address 0x10001014 .

The Bootloader/DFU with SoftDevice update is located at address 0x0003C000, as seen in Figure 1..

dfu_bootloader_flash_view.png
Figure 1: 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 2 shows the settings for nrfjprog.exec in Keil.

keil_project_flash_tool.png
Figure 2: 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 3.

keil_project_popup.png
Figure 3: 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 0x3800 to new address 0x00038000 gives 0x4800 additional bytes (18 pages), thus the new size becomes 0x8200.

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 4 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 4: Bootloader/DFU Start address setting in Keil.