#Option Bootloader

Syntax:

    #option bootloader address

Explanation:

#option bootloader prevents the overwriting of any pre-loaded bootloader code, vectors, etc. below the specified address. The GCBASIC code will start at the specified address.

A bootloader is a program that stays in the microcontroller and communicates with the PC, typically through a serial interface. The bootloader receives a user program from the PC and writes it to the flash memory, then launches this program for execution. Bootloaders can only be used with microcontrollers that can write to their flash memory through software.

The bootloader itself must be written into the flash memory with an external programmer.

In order for the bootloader to be launched after each reset, a goto bootloader instruction must exist somewhere in the first 4 instructions. There are two types of bootloaders: some that require the user to reallocate the code, and others that themselves reallocate the first 4 instructions of the user program to another location and execute them when the bootloader exits.

The diagram below shows the architecture of a bootloader. The left-hand side shows the operation of the instructions without a bootloader. The right-hand side shows the initial instruction jumping to the bootloader, then, once the bootloader has initialised, execution of the start code.

graphic

See example bootload software.

The space taken by the bootloader itself (everything below address) is now counted against the chip’s available program memory, the same way #Option ReserveHighProg is - the "program too large" check, and the Program Memory: n/total words line, both include it. If the bootloader also needs to keep a region free at the top of flash (for its own HEF/SAF data, or for configuration words on the last page), still add #option ReserveHighProg for that separate region; the two options now add together correctly rather than one of them being silently ignored by the size check.

Example:

    #option bootloader 0x800

See Also:

  • #Option NoConfig — another option commonly used alongside a bootloader
  • #Option ReserveHighProg — reserving space at the top of flash, counted alongside the bootloader’s own space at the bottom