Product Comparison: USB I2C | USB SPI | USB GPIO

USB PIC Bootloader. User Manual


7.3.4. BOOT_ERASE_FLASH command

BOOT_ERASE_FLASH command is used to erase flash memory.

Before sending BOOT_ERASE_FLASH command you have to fill in boot_cmd_erase_flash structure:

typedef struct
{
   unsigned char cmd;  /* command code, see BOOT_xxx constants */
   unsigned char echo;  /* echo is used to link between command and response */
   unsigned char addr_lo;  /* address must be divisible by 64 */
   unsigned char addr_hi;
   unsigned char reserved[1];
   unsigned char size_x64;  /* size in 64 byte blocks */
} boot_cmd_erase_flash;

Fields assignment:

cmd

Command code; the given field must be initialized by BOOT_ERASE_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 erase starts. As the minimum erase block is 64 bytes, addr_lo parameter value must be divisible by 64.

addr_hi

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

reserved

Not used.

size_x64

The number of 64-bytes blocks to erase. As programs memory in PIC18 microcontrollers is erased by blocks of 64 bytes, this parameter sets the number of 64 bytes blocks.

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