You are here

Header Files

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

Commands description:

BOOT_READ_FLASH

On receipt of this command bootloader reads and transfers to PC requested part of flash memory.

BOOT_WRITE_FLASH

On receipt of this command bootloader writes data received from PC into the microcontroller flash memory.

BOOT_ERASE_FLASH

On receipt of this command bootloader erases requested part of flash memory.

BOOT_GET_FW_VER

On receipt of this command bootloader sends back its version number.

BOOT_RESET

On receipt of this command bootloader clears EEPROM mark, resets the microcontroller and enters user mode (launching user mode application).

BOOT_READ_ID

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.

BOOT_WRITE_ID

On receipt of this command bootloader writes data sent by host into the microcontroller ID locations.

BOOT_READ_EEPROM

On receipt of this command bootloader reads and transfers to PC requested part of microcontroller EEPROM memory.

BOOT_WRITE_EEPROM

On receipt of this command bootloader writes data sent by host into the microcontroller EEPROM memory.

BOOT_CMD_UNKNOWN

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.