USB PIC Bootloader. User Manual


7.3.3. BOOT_WRITE_FLASH command

BOOT_WRITE_FLASH command is used to write data into flash memory.

[Warning]Warning

Before writing, flash memory must be erased by BOOT_ERASE_FLASH command.

Bootloader does not verify written data while processing BOOT_WRITE_FLASH command. You can use BOOT_READ_FLASH command for reading and further verification of the data.

If XTEA encryption algorithm is used (see the section called “XTEA - The encryption key”), the command must contain the encrypted data. The encryption can be performed with encoder application, which is included into the bootloader installation package. During encryption you have to use the password, identical to the password in Bootloader.

Before sending this command you have to fill in boot_cmd_write_flash structure:

typedef struct
{
   unsigned char cmd;
   unsigned char echo;
   unsigned char addr_lo;
   unsigned char addr_hi;
   unsigned char reserved[1];
   unsigned char size8;
   unsigned char data[BOOT_CMD_SIZE - 6];
} boot_cmd_write_flash;

Fields assignment:

cmd

Command code; the given field must be initialized by BOOT_WRITE_FLASH constant value.

echo

Package ID. Its value is selected arbitrarily before the command is sent. In the simplest case it is a counter value, increased by one while sending every new command. Bootloader does not analyze this field value. It simply copies it into response. Therefore, when response received, PC program can connect this response to previously sent command.

addr_lo

LSB byte of the address, from which flash memory write starts. As flash memory is organized to store data as words, addr_lo parameter value must be odd – aligned with 16-bit word boundary.

addr_hi

MSB byte of the address, from which flash memory write starts.

reserved

Not used.

size8

The size of the data block to be written. The size specifies the number of bytes to write and must be divisible by 8.

data

Data to write.

After this command is processed, Bootloader sends response with code BOOT_WRITE_FLASH.