To ease PC software development Bootloader source code contains boot_if.h file. This file is not used by Bootloader itself. It defines Bootloader and PC software interaction protocol in C programming language.
It is strongly recommended not to modify this file! Any modifications of data structure, commands, constants etc. can lead to interface change and to unpredictable behavior!
The boot_if.h file defines commands sent by PC program to bootloader. Bootloader supports the following commands:
#define BOOT_READ_FLASH 0x01 #define BOOT_WRITE_FLASH 0x02 #define BOOT_ERASE_FLASH 0x03 #define BOOT_GET_FW_VER 0x04 #define BOOT_RESET 0x05 #define BOOT_READ_ID 0x06 #define BOOT_WRITE_ID 0x07 #define BOOT_READ_EEPROM 0x08 #define BOOT_WRITE_EEPROM 0x09 #define BOOT_CMD_UNKNOWN 0xFF
On receipt of this command bootloader reads and transfers to PC requested part of flash memory.
On receipt of this command bootloader writes data received from PC into the microcontroller flash memory.
On receipt of this command bootloader erases requested part of flash memory.
On receipt of this command bootloader sends back its version number.
On receipt of this command bootloader clears EEPROM mark, resets the microcontroller and enters user mode (launching user mode application).
On receipt of this command bootloader reads and sends back to PC the content of PIC microcontroller ID locations. Eight memory locations (200000h-200007h) are designated as ID locations, where the user can store checksum or other code identification numbers.
On receipt of this command bootloader writes data sent by host into the microcontroller ID locations.
On receipt of this command bootloader reads and transfers to PC requested part of microcontroller EEPROM memory.
On receipt of this command bootloader writes data sent by host into the microcontroller EEPROM memory.
Unknown command. PC program must not send this program. Bootloader sets this code in response, if it fails to identify the received command.
All interaction between Bootloader and PC program is based on sending and receiving data packages of fixed length. The size of these packages is also defined in boot_if.h file:
#define BOOT_CMD_SIZE 64 #if( defined HID_OUT_EP_SIZE && (HID_OUT_EP_SIZE<BOOT_CMD_SIZE) ) #error "HID_OUT and CMD size mismatch HID_OUT_EP_SIZE<BOOT_CMD_SIZE" #endif #define BOOT_REP_SIZE 64 #if( defined HID_IN_EP_SIZE && (HID_IN_EP_SIZE<BOOT_CMD_SIZE) ) #error "HID_IN and CMD size mismatch HID_IN_EP_SIZE<BOOT_REP_SIZE" #endif
No matter how much data command or response contains, package length must always be equal to 64 bytes. If there are less data it is located at the beginning of the package. The rest of the package is simply ignored.