6.1. Memory organization

Flash memory sections

The bootloader occupies the first 8 KB (8192 bytes) of the PIC microcontroller’s flash memory. The remaining 24 KB of flash is available for the application. The bootloader places no restrictions on what data can be written to the application section. However, the bootloader will consider the application to be invalid and not allow any code in the application section to run if the first word of the application section (at address 0x2000) is 0xFFFF, which would correspond to a NOP.

Entry and interrupt vectors

The entry vector and interrupt vectors are remapped by the bootloader to the beginning of the application section:

  • The application’s entry vector should be placed at 0x2000. This is the location where code will start executing when the application is started.
  • The high-priority interrupt vector should be at 0x2008.
  • The low-priority interrupt vector should be at 0x2018.

The interrupt vectors can be ignored and those locations can hold normal code if interrupts are not enabled in the application.

The application can start the bootloader by jumping to address 0x0004 using a goto instruction. This method of starting the bootloader does not involve a reset, so the state of the microcontroller matters and certain configurations could cause problems for the bootloader. For example, an application that changes the configuration of the system oscillators will most likely have to revert its changes before starting the bootloader. Also, an application that uses USB should disable the USB module by clearing USBEN and then wait for at least 100 ms before starting the bootloader, in order to give the computer time to detect that the application has disconnected.

The code below is PIC assembly code that shows how these vectors are defined in the bootloader. The two CPU interrupt vectors (0x0008 and 0x0018) each have a goto instruction that jumps directly to the user application. The two entry vectors (0x0000 and 0x0004) each have goto instructions that jump to the appropriate part of the bootloader code.

    org     0x0000              ; CPU reset vector
    goto    powerup             ; Start app or bootloader

    org     0x0004              ; Bootloader launch vector
    goto    powerupBootloader   ; Start bootloader

    org     0x0008              ; CPU high-priority interrupt vector
    goto    0x2008              ; Jump to the application's ISR

    org     0x0018              ; CPU low-priority interrupt vector
    goto    0x2018              ; Jump to the application's ISR

Serial number

The bootloader comes with a unique serial number that is assigned during manufacturing. This serial number is typically an 8-digit decimal number, but in the future we might expand it to have other characters or make it be up to 16 characters long. The serial number is accessible from the application, and applications using USB can expose the serial number as a string descriptor.

Read-only data

Part of the bootloader’s flash memory is used to store some information that can be read by the application:

  • Addresses 0x40–0x51 contain the USB device descriptor of the bootloader, as defined in the USB 2.0 Specification.
  • Addresses 0x60–0x70 contain the serial number as an ASCII string with a null terminator byte. The extra bytes after the null terminator are all set to zero.
  • Addresses 0x80–0xA1 contain the serial number in USB string descriptor format. The extra bytes after the end of the string are all set to zero.

Related Products

P-Star 45K50 Mini SV
P-Star 25K50 Micro
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors