3.1. Flash Code¶
Flash Code tool allows users to program the Flash and execute code from it.
Figure 5 Flash Code tool with several sections enabled.
For DA1459x family devices the user can select among QSPI, eFlash or eFlash Asymmetric memories to use with the Flash Code tool (Figure 6). When a memory type is selected from the drop down menu the start and end addresses are updated to reflect the properties of the selected memory. Asymmetric eFlash should be selected in order to prepare a flash image for asymmetric SUOTA.
Figure 6 Memory selection for DA1459x family devices
On the top left of the tool user can see the available sections. Depending on the selected device different sections are available. Some sections may need to be enabled from Settings -> Advanced Settings main menu
For DA1469x, DA1470x, DA1459x and RA6W1/RA6W2_Wi-Fi device families (Not supported for DA16200 device) the available sections are dynamic and depend on the Product Header contents, on FW images and CS presence. Start and End address indicate the start and end address of each section. For the rest of the families only Complete Flash is available. On the center of the tool two tables are presented: Content Read table is read only and presents the data read from Flash memory for this section. Content to Burn is editable and user can either edit the fields of a section or import the contents of a file at this table and then burn the respective section to Flash Memory. The following sections exist for DA1469x, DA1470x, DA1459x and RA6W1/RA6W2_Wi-Fi family devices:
Configuration Script (CS): Enable section from menu Settings -> Advanced Settings. This section contains a script with a certain format which is used for programming registers with values that are defined during production testing, storing a trim value for the application software, and defining UART time-out time during booting. The booter will execute the script to prepare and initialize the system, before the CPU starts running application code from the Flash.
CS, if present in Flash, should be programmed at the beginning of the flash (address 0x00000000). CS section start address cannot be changed by the user and its end address depends on the size of the CS. When the Configuration Script section is selected, a set of filters is activated on the left of the tool, which help the user locate specific entries in the CS. The user can filter the CS by CS group, register name or bit field name or filter only the commands programming values to registers. User can mouse over the Value column of the Configuration Script field in Content to Burn table in order to edit the CS by adding or removing commands from it using the Manage Configuration Script dialog.
Product Header: Enable section from menu Settings -> Advanced Settings. This section contains important information about the system and the flash type. Product Header is used by the device booter to detect if flash is programmed and boot FW images from flash. Product Header is the first section in Flash (at address 0x00000000) unless Configuration Script is programmed in Flash. In such a case and if Booter value is not programmed in Configuration Script, Product Header will start one sector after CS, namely at address 0x00001000. If Booter Value has been programmed in CS, then Product Header will be located at the address indicated by Booter Value. Note that start-end addresses of this section cannot be changed by the user, since Product Header should be located at predefined addresses, according to the cases described already, in order for the device booter to locate it.
Product Header (Backup): Enable section from menu Settings -> Advanced Settings. The backup Product Header is a read only copy of the primary Product Header. Each time the primary Product Header is updated (new values burned or values erased), the backup Product Header is also updated in order to contain a copy of the contents of the primary Product Header. Backup Product Header will always start one sector after the primary Product Header. So if the primary Product Header starts at 0x00001000, the backup Product Header will start at 0x00002000. For DA1459x family devices, if the primary Product Header starts at 0x00001000, the backup Product Header will be found at address 0x00001800. Similarly to primary Product Header, backup Product Header start-end addresses are not editable by the user.
FW Image 1: Enable section from menu Settings -> Advanced Settings. It contains the FW Image programmed at the Active FW Image address field of Product Header. Start address can not be edited by the user since it depends on Active FW Image address value and the end address depends on the size of the FW Image.
FW Image 2: Enable section from menu Settings -> Advanced Settings. It contains the FW Image programmed at the Upgrade FW Image address field of Product Header. If active and upgrade FW Image addresses have the same value, only FW Image 1 section will be available. Similarly to FW Image 1 section, start and end address text fields cannot be edited by the user.
NVPARAMS: Enable section from menu Settings -> Advanced Settings. This section allows the user program the NVPARAMS block on Flash memory. See QSPI NVPARAMS for more info on this section.
The Complete Flash button presents the contents of the complete Flash as raw data. Complete Flash view is available for all families. User can import a file on Content to Burn table using the Import from File button. The user can specify the address to burn the Content to Burn by editing the Start Address text field. Content Read table presents by default 32K of data. The user can change the start and end addresses to read the preferred memory segment.
The sections are initially updated when the Connect button is pressed and after burn and erase actions, which change the contents of the memory.
The tool provides the following buttons and options:
- Connect: Establishes connection to the target device by initializing communication interface and downloading appropriate FW required for the communication to the target.
- Read: Reads Flash region between start and end address and loads its contents into Content Read
- Burn: Burns Content to Burn table to flash at the address indicated by start address. When fields are presented in the Content to Burn table, light red rows indicate the fields which will change in Flash memory when the Burn button will be pressed. For DA1459x family devices, when a flash image is going to be burned, new CS commands, if any, from the flash image in Contents to Burn table are appended to the CS that is already burned in memory. In that way existing CS commands in memory are not erased or modified. If a CS command has different value(s) in the flash image to burn compared to the same command in memory CS, it will also be appended to the memory CS and in that way the bootloader will execute it twice.
- Erase: Erases memory region between start and end address. Note that for DA1459x family devices the user is advised to not erase the Configuration Script from memory in order not to loose important trim/calibration values. If CS is detected in the memory region to be erased, the user will be asked if he/she wants to erase the CS too (Figure 7). If no is selected, which is the default option, only the sectors after the CS end will be erased. If yes is selected, the selected memory region, including the CS, will be erased.
- Import from File: Can be used to import the selected section contents from a file. When Complete Flash is selected, the Import from File button can be used to import the contents of any section (e.g. Configuration Script, Product Header) or import a ready FW image or import a FW file that will later be prepared as a FW image.
- Export to File Exports the contents of the region between start and end address to a file.
- Check Flash size here: Shows the total Flash size attached to the target device. There is a default value per family but the user can change this value if a non default Flash is being used.
Figure 7 CS detected in memory region to be erased for DA1459x family devices
3.1.1. Programming Flash memory¶
Programming a whole Flash Image:
Figure 8 Preparing flash image for DA1469x family devices
User first selects the Complete Flash section and then selects Import from File (Figure 8). In the “Select binary file” field the user can select one of the following after pressing the Browse button:
- Simple firmware (FW) file: This file does not contain Product Headers or Image Header. The contents of the file will be first converted to a Firmware image and then will be used to create a whole Flash Image.
- Firmware Image file: This file is a ready FW image, containing Image Header. The contents of the file will be used to create a whole Flash Image.
- Whole Flash Image: This file contains Product Headers and Firmware Image(s). The contents of the file will not change, since Product Header is already included in the file contents.
In the first two cases the Product Header will be created according to the flash configuration matching the selected flash type. This means that specific magic values will be inserted to the Product Header according to the selected flash type. Also the application will find an appropriate address to burn the generated flash image, by checking CS (if present in Flash) and CS Booter value (if present in CS). The address at which the Product Header of the Flash Image will be burned also affects the Active and Upgrade FW address fields of Product Header.
In the last case the application cannot change Product Header (magic values and Active/Upgrade address fields) that is already included in the Flash Image, therefore the user will have to specify the address at which Product Header should be burned. Default address is at the beginning of the Flash.
Note that for DA1459x family devices a whole flash image includes the CS too. If the imported binary does not start with the CS Start command bytes (0xA5A5A5A5), a CS including at least the Start command and the Booter Value command will be added in the beginning of the generated flash image.
If Asymmetric SUOTA has been selected from the FLASH type drop down menu the user will also have to select a SUOTA binary file along with the application binary file (Figure 9). The generated flash image will contain the SUOTA binary at offset 0x2FC00.
Figure 9 Preparing Asymmetric SUOTA flash image for DA1459x family devices
Programming separately the Product Header and the FW Image(s):
- Programming the Product Header first: The user can select either Complete Flash or Product Header and import the product header from a file. Alternatively the user can select Product Header and edit the field values at Content to Burn table. Then the user can program the Product Header at the beginning of the Flash, if CS is not in Flash or at address 0x00001000 if CS is burned in Flash. If Booter Value has been specified in the CS, the user should burn the product header at the address indicated by the Booter Value command of the CS.
- Programming a FW Image next. The user can select Complete Flash and import a ready FW Image (already contains the image header and data) and then set the address the FW Image should be burned to at the start address text field.
- Programming a second FW Image: The user can select Complete Flash and import a ready FW Image, specify the address for the FW Image (a different address than the one used for Firmware Image 1) in the Start Address text field and burn the FW Image. Then the user can set the address that the second FW Image has been burned to Upgrade FW Image Address field of Product Header and then burn the Product Header.
3.1.1.1. DA1453x in BYPASS mode¶
Please note that currently SPI Flash for DA1453x family devices has been tested in BUCK mode at 3V and BOOST mode at 2.7V.
For the Bypass mode the flash programmer binary needs to be updated.
Please follow below steps to generate the new binary with bypass support:
- Open the flash programmer KEIL project under
6.0.14.1114\utilities\flash_programmer. See Figure 10 - Enable the CFG_POWER_MODE_BYPASS flag in arch.h file
- Compile. jtag_programmer_531.bin is generated
- Rename jtag_programmer_531.bin to jtag_programmer.bin
- Under your SmartSnippets™ Toolbox directory installation: For example
C:\Program Files\SmartSnippetsToolbox\SmartSnippetsToolbox5.0.28\common_resources\SupportPackages\DA1453x\toolbox_resources\common\jtag_programmer.bin.
Remove the jtag_programmer.bin and replace it by the new one.
Figure 10 Generate flash programmer binary on KEIL to support bypass mode for DA14531
3.1.2. QSPI NVPARAMS¶
Note
The tool is available for DA1468x, DA1469x, DA1470x, DA1459x and RA6W1/RA6W2_Wi-Fi devices.
This is considered as an advanced tool. Enable it from menu Settings -> Advanced Settings.
This section allows the user to read and write NVPARAMS block on flash memory and is similar to OTP NVDS tool used for DA14580/581/583 chip family.
The recommended address for NVPARAMS differs per family and is prefilled in the start address text field. In case a partition table is already programmed in QSPI, the application will try automatically to detect the start address of NVPARAMS section from the partition table and will recommend this address to the user. By editing the start address text field, user can change the address at which a burn and a read operation will be performed. The address (in bytes) should be a hex number smaller than the maximum address allowed by the QSPI size specified on Device Settings. For burn operations, the address should be such so that the address where the last NVPARAMS data byte will be written is smaller than the maximum QSPI address.
An example of the NVPARAMS section is shown below:
Figure 11 QSPI NVPARAMS Section
User selects or inserts the values of the corresponding parameter at column Value. Default values are shown on column Default Value.
There is a second editable column called Enabled where the user defines that the parameter will be actually used. It is also called Validation Flag. When checked a byte with value 0x00 is added at the end of the parameter value in memory. When left unchecked a byte with value 0xFF is added to define that the parameter is not valid for that configuration.
All values except TAG_BLE_PLATFORM_BLE_CA_MIN_RSSI are accepting unsigned values. Validation error messages are shown when user tries to export or burn invalid values. Value of TAG_BLE_PLATFORM_BLE_CA_NB_BAD_PKT is recommended to be half the value of TAG_BLE_PLATFORM_BLE_CA_NB_PKT.
3.1.3. Configuration Script (CS) in QSPI¶
A Configuration Script can be added to the QSPI memory by pressing the Add button and selecting Configuration Script. The Manage Configuration Script dialog pops up which will help the user build the CS by adding commands to it. In case a valid CS is already present in the QSPI, the same dialog can be shown by selecting the button that becomes visible when mousing over the value column of the Configuration Script field. Please refer to Configuration Script (CS) in OTP for more details about the Configuration Script and how to use the Manage Configuration Script dialog. Since the CS can be burned more than once to the QSPI memory, the user can alter the contents of the CS that is already burned in memory by deleting commands and adding new commands at any place in the CS.
3.1.4. Program SPI/EEPROM¶
The Program SPI/EEPROM feature has a wizard like structure that guides users through all the necessary steps to program a .hex/.bin file to the SPI/EEPROM memory.
In this page users select a .hex/.bin file to be programmed from the wizard. After selection users have 3 options on how to program the selected file.
Figure 12 Program SPI/EEPROM wizard: Intro page
- Do not modify: Using this option no modifications are applied to the contents of the source file. Optionally, if the Bootable option is checked, a bootable header can be added to the contents of the input file.
- Make single image: If this option is selected then a single image of the file will be created. Users have the option to encrypt and sign the final image.
- Make multi image: Users have the option to create an image containing two source files. Also, a secondary bootloader may be included.
Note
Options make single/multi image may change also the source file.
A work-flow of the wizard is presented below.
Figure 13 Program SPI/EEPROM wizard: Work-flow
When single image selected user have the option to encrypt the image. An example is shown in (Figure 14)
Figure 14 Program SPI/EEPROM wizard: Encryption page
- AES key: A 32 hex characters string (without prefix), that will be used to encrypt the image
- IV: Initialization vector as a string of 32 hex string (without any prefix)
- Decrypt AES key index: AES Key index as a value 0 to 4 that tells the bootloader which of the 5 OTP keys to use for decrypting the image.
- AES key revocation index: Optional and if provided, as a value 0 to 4, it will write the image header with an AES/IV key revocation index.
- SDK header file: If not provided, the default file will be used.
Note
If key revocation is desired, the image should be signed afterwards. An unverified image cannot revoke a key. Also, key revocation is only supported by images coming from an external memory (SPI or I2C).
On Sign page user may sign the image. An example of sign page is shown in (Figure 15)
Figure 15 Program SPI/EEPROM wizard: Sign page
- ECC Private Key: Key that should be used for signing. The key should be provided as a 64 hex string without any prefix (no 0x)
- ECC Key index: ECC key index, in values from 0 to 4, that tells the bootloader which of the 5 ECC OTP keys to use for verifying the image
- Revoke Key index: Optional and if provided, as a value 0 to 4, it will write the image header with an ECC key revocation index
If multi-image selected, the first image file is entered on screen (Figure 16)
Figure 16 Program SPI/EEPROM wizard: Select first image on multi-image case
In this page users provide the second image to be program on memory (Figure 17)
Figure 17 Program SPI/EEPROM wizard: Multi image page
Next page after selecting the second image a custom bootloader may be selected. If not, the default bootloader is used (Figure 18)
Figure 18 Program SPI/EEPROM wizard: Bootloader page
On offset page users may configure the memory layout of the image (Figure 19)
Figure 19 Program SPI/EEPROM wizard: Offsets page
On the final page of the wizard there is a summary of all the user choices regarding the creation of the image. If not output directory selected, a default store location is used on user’s temporary folder. The result image is loaded on the tool. If user selected to sign the image, a file with the public key and the signature also is created.