Features:

  • Available under the GPL license
  • Supports PIC16F87xA parts (block writes to flash ROM) and the older non-A parts
      4K word parts not yet tested, but only EEPROM support differs from 8K word version
  • Requires no space in bank 0
  • User program has immediate control at power-on and after resets
  • Uses read-write-verify sequence to minimize writes
  • Uses the USART on the PIC and no other pins
  • Robust error handling
  • Supports program flash ROM and data EEPROM (optional)
  • Reports the address range used by the bootloader to detect an overlap of the program to write and the bootloader (the bootloader still checks addresses to prevent writting over itself)
  • Allows for updating the bootloader on 8K word parts -- use a bootloader in bank 1 to write another in bank 3, or vise versa
  • Written mostly in C (CCS PIC C compiler)
  • Depending on options, requires between 316 and 340 instructions
  • Command line uploader available in C for POSIX compliant systems (has been compiled with gcc on Linux and Windows)
*
Updated 2003-3-18

Configurable options:

Not all possible options have been tested.

Requirements

Files

Full source as bzipped tar file (43k)
Full source as zip file (73k)
The full source includes all my GPL'd code, not just the bootloader, an example program using the bootloader, and a program for uploading code to the bootloader.
bb-hexfiles.tar.bz2 (5KB)
bb-hexfiles.zip (18KB!)
A set of precompiled bootloaders. See below for more details.
Linux i386 uploader for the bootloader A tested binary of a command line uploader for use with the B Bootloader. The full source above includes the source for this program.
Windows i386 uploader for the bootloader An untested binary of a command line uploader for use with the B Bootloader. Just the Linux version recompiled. It runs, but is otherwise untested. Requires at least a minimal install of Cygwin. In the Cygwin installer, the cygwin package under the Base category must be installed. I don't think anything else needs to be installed, but I'm not sure.

Ready to use bootloaders in Intel HEX files

All these bootloaders are either configured for asynchronous 19.2kbps (the USART enable/disable feature) or assume the USART is already initalized (lack of the feature). The hex files include a short program to continually re-run the bootloader, and will initalize the USART for 19.2kbps if the bootloader won't. If this program is not wanted, then remove everything from address 0x000 to 0x7FF.

If a configuration is not present here, it is because I didn't bother to make it, not because the configuration won't work. However, I have not tested every possible configuration. I did test the individual options, save for the 4K word parts, that can be matched together for a specific configuration, so I think these bootloaders will work. I have been wrong before, though. The 4K word part versions only differ in their EEPROM support, so any bootloader for 4K word parts that lack EEPROM support should work.

There is no distinction between 28 and 40 pin parts because the only I/O is through the USART so the code is identical.

File Max program size Clock speed (for 19.2kbps) Bootloader location Use port B pullups USART enable /disable EEPROM write support Bootloader instruction count
bb-4k-4-1-e.hex 4K words 4MHz Bank 1
0x800 - 0x947
entry: 0x86D
no no yes 328
bb-4k-20-1.hex 4K words 20MHz Bank 1
0x800 - 0x93B
entry: 0x867
no no no 316
bb-4k-20-1-e.hex 4K words 20MHz Bank 1
0x800 - 0x947
entry: 0x86D
no no yes 328
bb-4k-20-1-u.hex 4K words 20MHz Bank 1
0x800 - 0x94B
entry: 0x86D
no yes no 332
bb-4k-20-1-ue.hex 4K words 20MHz Bank 1
0x800 - 0x957
entry: 0x873
no yes yes 344
bb-8k-4-1.hex 8K words 4MHz Bank 1
0x800 - 0x93B
entry: 0x186B
no no no 316
bb-8k-4-1-ue.hex 8K words 4MHz Bank 1
0x800 - 0x953
entry: 0x871
no yes yes 340
bb-8k-4-3.hex 8K words 4MHz Bank 3
0x1800 - 0x193B
entry: 0x186B
no no no 316
bb-8k-4-3-e.hex 8K words 4MHz Bank 3
0x1800 - 0x1943
entry: 0x186B
no no yes 324
bb-8k-4-3-ue.hex 8K words 4MHz Bank 3
0x1800 - 0x1953
entry: 0x1871
no yes yes 340
bb-8k-20-1.hex 8K words 20MHz Bank 1
0x800 - 0x93B
entry: 0x867
no no no 316
bb-8k-20-1-e.hex 8K words 20MHz Bank 1
0x800 - 0x943
entry: 0x86B
no no yes 324
bb-8k-20-1-u.hex 8K words 20MHz Bank 1
0x800 - 0x94B
entry: 0x86D
no yes no 332
bb-8k-20-1-ue.hex 8K words 20MHz Bank 1
0x800 - 0x953
entry: 0x871
no yes yes 340
bb-8k-20-3.hex 8K words 20MHz Bank 3
0x1800 - 0x193B
entry: 0x1867
no no no 316
bb-8k-20-3-e.hex 8K words 20MHz Bank 3
0x1800 - 0x1943
entry: 0x186B
no no yes 324
bb-8k-20-3-u.hex 8K words 20MHz Bank 3
0x1800 - 0x194B
entry: 0x186D
no yes no 332
bb-8k-20-3-ue.hex 8K words 20MHz Bank 3
0x1800 - 0x1953
entry: 0x1871
no yes yes 340

Usage from PIC software

The best method is this:
  1. Compile justBootloader.c modified to provide the settings you require, or use one of the pre-compiled bootloaders given on this site.
  2. Load the compiled result onto the PIC to you want to use.
  3. Write and compile your own program without the bootloader. Take these factors into consideration:
  4. Your program will have to call the bootloader. The following code are examples for calling the bootloader; you'll need to modify them to meet your needs. Specifically, the entry address of the bootloader (listed under Bootloader location in the table above) will need to be set correctly, and changes will be needed when making the call outside of bank 0.
    C Assembly
    /**
     * Calls the bootloader's main function.
     */
    void BB_main() {
       #bit romBank0 = 0xA.3
       #bit romBank1 = 0xA.4
       #asm
       // select program bank 3
       bsf romBank0
       bsf romBank1
       // call the bootloader at 0x1867
       call 0x67
       // select program bank 0
       bcf romBank0
       bcf romBank1
       #endasm
    }
    ;Calls the bootloader's main function.
    
    BSF    0A.3   ; select program bank 3
    BSF    0A.4
    CALL   67     ; call the bootloader
    BCF    0A.3   ; select program bank 0
    BCF    0A.4
    
  5. To update the bootloader using an existing bootloader, write a new bootloader to a different address space. For example, use a bootloader stored in bank 3 to write a new one in bank 1. Be sure to change the way the bootloader is called, too.

Protocol

Look in programUploader.cpp. It uses binary values and requires a program to process HEX files.

Other questions

They can be answered here.
* The B Bootloader logo was made using images by Michael Jastremski that are available from Openphoto.