6. Images and binaries

This section describes how to create an image (single, multi or configuration) and the final binary file that is written in SPI flash, from the .hex file derived after building the device Section 5.1 (Section 5.2). Application mkimage.exe is a CLI python application to build a single image that is SUOTA compatible, add a configuration struct to the image and to create a final multi image that will be written to SPI flash. Configurator is a graphic interface that, among others, gives the user the ability to create configuration struct images. This is described in the following section. But before starting the procedure of creating any image, the generated .hex files must be converted to binary files with the hex2bin.exe application. For example, hex2bin.exe dsps_device_531.hex.

6.1. To Build SUOTA Ready SW Images

Syntax: mkimage.exe single in_file version_file out_file

Prepend the header to the raw binary image in_file (e.g. .bin file). The header contains version, timestamp and housekeeping information, which is partially extracted from header file version_file. Arguments:

  • in_file is the raw binary to be inserted into the image

  • version_file is normally stored in a header file and is available in dsps_585projectstarget_appsdspssw_version. Depending on the SPS role, version_file can be either dsps_device_sw_version.h for device or dsps_host_sw_version.h for host. The mkimage application looks in these files for definitions such as:

    • #define SW_VERSION “version”

    • #define SW_VERSION_DATE “date”

  • out_file is the resulting image (e.g. .img file)

6.2. Create and Edit Configuration File

Configurator is a graphical user interface application written in python, to create configuration structure files in binary format. The user is able to:

  • Create a new configuration file

  • Open an existing configuration file and read the included elements and their values

  • Modify the configuration file by adding/removing elements or change the value of included elements

  • Save changes in the same file or in a new file

../_images/Configurator_File_Menu.svg

Figure 11 Configurator File Menu

At startup, the application will open and read XML file config-spec.xml, which is in the same file location as the application. The xml file is parsed with which the list of Groups, Element IDs and types are inserted into the application. The XML file has all the specified groups and element IDs with their corresponding fields:

  • names: the name of the element

  • types: the type of the element as defined in the SPS device or the host application

  • units: the measurement unit of each element

  • max_sizes: the maximum size of each element

  • min: the minimum value

  • max: the maximum value

This is an example of an element and its corresponding fields:

<group id ="0x01" name="ADVERTISE"> <element id="0x00"> <name>Advertise Interval Minimum</name> <type>uint16_t</type> <units>BLE slots</units> <max_size>2</max_size> <min>32</min> <max>16384</max> </element> </group>

The number of Groups and Elements is transparent to the Configurator application. New Groups or Elements can be added to the XML file if the format described above is followed. In this case, new item should be added in the SPS Configuration Struct (Section 3.6) and code changes should be made to handle the new item in the XML file. In the left-hand side frame of the application (see Figure 12 ), the user can select the new Group ID and the Element ID that is to be included in the configuration file. Click the Add button to add the element in the Configuration Structure shown in the right-hand side frame of the application. The configurator checks and validates the applied values based on the types and the max sizes of the element’s value. The user can save the changes either every time an element is added, or after completing all changes and then select the Save or Save as option that is under the File menu. When the structure is saved in the file (binary format), all the header’s fields aside from version and encryption flag (provided by the user) will be calculated and the header element will precede the configuration elements.

../_images/edit_delete.svg

Figure 12 Edit/Delete an Element of the Configuration File

6.3. Create a Multi-Image for First Time Programming

Syntax: mkimage.exe multi in_img off1 off2 in_cfg off3 off4 off5 out_file [bloader]

To create a multi-part image out_file, the application image and the configuration image are packed together into one image that can be written to SPI flash.

Arguments:
  • in_img is the output from a single procedure, described in Section Section 6.1

  • off1 is the offset for the application image

  • off2 is the offset for the alternative application image

  • in_cfg is the file with the configuration image to be inserted into the output image, which is generated by the Configurator application (Section 6.2)

  • off3 is the offset for the configuration image

  • off4 is the offset for the alternative configuration image (filled with the same in_cfg)

  • off5 is offset for the product header

  • bloader (.bin file) at offset 0, if the secondary bootloader image is provided. The bloader bin file must always be in offset 0x0

The offset values are available in either Table 6 or Table 7 depending to selected target in the build procedure.

6.4. CLI Flash Programming

Application cli_flash_programming is a command line tool, written in python language, which can be used to access and program the SPI Flash for DA14531 devices. The tool communicates with the SPI flash either over a virtual COM port or over a JTAG interface. After the communication interface is selected, the user is able to:

  • Erase the entire or part of the SPI flash

  • Read all or a specific number of bytes from the SPI flash

  • Write a binary or a specific number of bytes from a binary file to the SPI flash

6.4.1. Hardware setup

For DA14531 devices the only acceptable UART configuration is through single-wire UART that is connected to pin P0_5 and operates at a 115200 baudrate. In order to access the SPI Flash of the DA14531 Module, the jumpers of DK’s SPI Flash should be removed. The figure below shows the hardware setup that is needed, in both DA14531 and DA14531 Module devices, in order to access the SPI flash either with the use of UART or the JTAG interface.

../_images/jumper_config.svg

Figure 13 DA14531 and DA14531 Module ProDev Kit Motherboard Jumper Configuration

6.4.2. How to Use CLI Flash Programming

The user must specify the communication interface and the operation (command) to be executed at the SPI flash. All arguments and commands are described in detail below. To write an application image to the SPI flash, the whole SPI flash memory must be erased first. Arguments:

uart: use the UART interface to communicate with and program the SPI flash.
  • port <PORT>: Specify the serial port to which the device is connected. If the –port argument is either empty or not found during the scan of all available Virtual COM ports, an autodetection graphical interface will display with a list of the available Virtual COM ports.

  • firmware <PATH_FIRMWARE_FILE>: Specify the file to be used as flash_programmer_531.bin instead of the default, which is located in the same folder as cli_flash_programming.exe.

  • spi_cfg <CS_PORT,CS_PIN,CLK_PORT,CLK_PIN,DO_PORT,DO_PIN,DI_PORT,DI_PIN>: Define the GPIO pin assignment for the SPI flash. The configuration is a comma separated list of four pairs of numbers. Each pair describes the port and pin for CS, CLK, DO and DI. If the –spi_cfg argument is not selected, then the default SPI Flash pins are used: –spi_cfg 0,1,0,4,0,0,0,3.

  • port_selector <PORT_SELECTOR>: Define the GPIO pin assignment for UART. The cli_flash_programming uses by default selector 5 through pin P0_5 at baudrate speed 115200 for DA14531. This is the only option for DA14531.

jlink: use the JTAG interface over JLink to communicate with and to program the SPI flash.
  • serialno <SERIAL NUMBER>: Specify the serial number of the board to be connected.

verbose: increases the logging verbosity.
  • If this option is not added, then the default logging level is set to Warning

  • v: increases the logging level to Info

  • vv: sets the logging level to its maximum value for Debugging reasons.

–help: prints a complete help message for all the options in the current parser and then exits.
  • cli_flash_programming.exe -h: prints the help messages for all the top level arguments and options.

  • cli_flash_programming.exe erase -h: prints the related help messages of the required parameters of the erase command. The above command can be used respectively for read and write commands.

device <DEVICE NAME>: Specify the device name. In our case DA14531 is acceptable. bootable: Automatically add an AN-B-001 header at offset 0 of the SPI flash memory. The secondary bootloader will copy only the number of bytes defined in the SPI Flash header.

Commands:

erase: erase the whole or a sector of the SPI flash.
  • start: the start address to be erased. Default is 0.

  • size: the size of the area to be erased. Default is -1. If the start address is not aligned to a page, then the corresponding sector will be erased.

read: read the entire or a specified size from the SPI flash.
  • start: the start address to be read. Default is 0.

  • size: the size of the area to be read. Default is 1.

  • bin: optional output file where to store read data.

write: all contents of a binary file or specified size to the SPI flash.
  • start: the start address to be written.

  • size: the size of the area to be written. If the size is equal to 0, write the entire file to the SPI flash.

  • bin: the input file that will be written to the SPI flash.

6.5. Release Binaries

In the release folder, there is a bin/ folder, which contains all the related binary and image files. The content of the folder is:

  • The binary files after building the SPS project for both chips (DA14531 and DA14585) and both roles (Device and Host):

  • sps_device_535.bin

  • sps_device_585.bin

  • sps_device_531.bin

  • sps_device_531_01.bin

  • sps_host_535.bin

  • sps_host_585.bin

The single images (see :numref: To Build SUOTA Ready SW Images) of the SPS application for both chips (DA14531 and DA14585) and both roles (Device and Host):
  • sps_device_531.img

  • sps_device_531_01.img

  • sps_device_535.img

  • sps_device_585.img

  • sps_host_531.img

  • sps_host_535_multi.bin

  • sps_host_585.img

The multi images (see Section 6.3) of the SPS application for both chips (DA14531 and DA14585) and both roles (Device and Host):
  • sps_device_531_multi.bin

  • sps_device_585_multi.bin

  • sps_host_531_multi.bin

  • sps_host_585_multi.bin

The configuration structure binary files for all supported chips (DA14531 , DA14535 and DA14585) and both roles (Device and Host). In the Host role the configuration structure is the same for all supported chips:
  • spss_device_config_struct_531.img

  • spss_device_config_struct_535.img

  • spss_device_config_struct_585.img

  • spss_host_config_struct_531_535_585.img

The secondary bootloader binary files for all supported chips (DA14531 , DA14535 and DA14585), which is used to create the multi images (see Section 6.3):
  • secondary_bootloader_531.bin

  • secondary_bootloader_531_01.bin

  • secondary_bootloader_535.bin

  • secondary_bootloader_585.bin

The application executables used to create the images (i) and the configuration structures (ii):
  • mkimage.exe

  • configurator.exe

The XML file, used by the Configurator and the SmartConfig application, which contains all the supported configuration elements, their properties and the necessary enumerations and data types:
  • config-spec.xml

The cli_flash_programming executable (see Section 6.4), which programs the SPI flash over either UART or JTAG:
  • i . cli_flash_programming.exe

The binary of the flash_programmer application used to upload and read back the application code that runs on platform DA14531:
  • i . flash_programmer_531.bin

The multi-image follows the memory map of the flash of each chip. The secondary bootloader must be stored in the beginning of the image, in offset 0x0. The Product Header is produced during the multi-image creation and contains the offsets of the Application Images and the Configuration Structure images. The offset of the Product Header is defined during the build procedure of the multi-image and is hardcoded in the code of the SPS host/device and secondary bootloader projects. So, if someone wants to change the Product Header offset, he must also change it in the code. The Flash memory maps and the Product Headers of the multi images of both chips are shown in the following sectors.

6.6. DA14585 Flash Memory Map

Table 8 DA14585 Product Header

Offset

Field

Size (in bytes)

Value

0

Signature

2

0x7052

2

Version

2

<version>

4

Image bank1 offset

4

0x06000

8

Image bank1 offset

4

0x1A000

12

Configuration bank1 offset

4

0x2E000

16

Configuration bank1 offset

4

0x2F000

Table 9 DA14585 flash memory map

Offset

Region

0x00000

Secondary Bootloader

0x06000

SPS Image 1

0x1A000

SPS Image 2

0x2E000

SPS Configuration Image 1

0x2F000

SPS Configuration Image 2

0x39000

Product Header

Table 10 DA14531/DA14535 Product Header

Offset

Field

Size (in bytes)

Value

0

Signature

2

0x7052

2

Version

2

<version>

4

Image bank1 offset

4

0x06000

8

Image bank1 offset

4

0x1A000

12

Configuration bank1 offset

4

0x1B000

16

Configuration bank1 offset

4

0x1F000

Table 11 DA14531/DA14535 flash memory map

Offset

Region

0x00000

Secondary Bootloader

0x06000

SPS Image 1

0x10000

SPS Image 2

0x1A000

SPS Configuration Image 1

0x1B000

SPS Configuration Image 2

0x1F000

Product Header