En Français

Colt PIC18F Bootloader


Shortly after the release of the PIC18F family, Microchip released a bootloader compatible with the new devices. There were several attributes that I liked about this bootloader. It was built to fit in the PIC18F boot code block and could be code protected separately from the user code. It also supported a wide range of PIC devices and clock speed, which I hadn't found in other bootloaders. Best of all, it was free!

However, there were some things I didn't find in this bootloader. I wanted the PIC to stay in boot mode after reset for a short time and then jump to user code if the bootloader was not invoked. I also wanted to be able to program new code in one operation (Microchip's bootloader application forced you to first erase the whole code space, then program the chip). Finally, I wanted a way for the bootloader to change Config bits and EEPROM data.

For these reasons, I decided to create my own bootloader. I first created the Jolt bootloader, a combination of a bootloader application that runs on a PC or Unix workstation and a bootloader firmware that runs on the PIC18 devices. Following the release of Jolt, I have received several requests to have a version of the bootloader that does not require Java Runtime Environment. I have decided to port Jolt to Visual C++ and Colt is born.


News

January 27, 2007: Released version 0.6b. An issue with the programming of some of the 2 kb boot sector devices was reported by a number of users. PicDevices.properties has been updated accordingly. Changes were done to address problems with the following devices: PIC18F2585, PIC18F2680, PIC18F4585, PIC18F4680, PIC18F2420, PIC18F2520, PIC18F4420, PIC18F4520, PIC18F2455, PIC18F2550, PIC18F4455, PIC18F4550.

July 5, 2006: Released several flavors of bootloader firmware (firmware for devices that use internal oscillator and 4xPLL, firmware that uses USART2 port for devices that have 2 USART ports. Fixed issue with 2 kb boot block devices. Updated documentation.

December 1, 2005: Released version 0.6 of the bootloader application. Added ability to invoke Colt from command-line. Added Edit Config dialog. Added support for devices that require 32 byte and 64 byte write blocks.

March 12, 2005: Released version 0.5 of the bootloader application and version 0.12 of PIC18F firmware for models that have 2 kb boot block. Fixed problem with loading of Configuration bits from HEX file generated by HI-TECH compiler.

August 20, 2004: Released version 0.4 of the bootloader application. Added read and save menus. Fixed a few bugs. Added a few devices.

August 12, 2004: Released version 0.3 of the bootloader application. This version adds support for numerous PIC devices including PIC18F1220/PICF1320. This version also addresses issues with configuration of PIC devices in PicDevices.properties, adds auditive feedback when operation completed and adds capability to program data EEPROM and Config independently from flash.

May 25, 2004: Released version 0.2 of the bootloader application. This version fixes serial transfer issues under Windows XP, adds Verify command, adds key accelerators and streamlines some of the error dialogs.

May 14, 2004: Released version 0.1 of the bootloader application. This version uses the same firmware as Jolt.


Requirements


Features

The Colt bootloader firmware is based on Microchip PIC16F/18F bootloader firmware. The bootloader firmware can be written to the boot section of the PIC18F chips. This boot section can be independently boot protected. A nice feature of this bootloader is that it automatically detects the baud rate at which it should run. This means that you do not require a .hex file for different baud rate or clock speed. Also, I have modified the firmware to allow for a two seconds delay on startup to trigger bootloading operations.

The Colt bootloader application that works with the Colt firmware streamlines the loading process and supports the following new features:

Here is a screenshot of the Colt bootloader application:


Download

Colt Bootloader application v0.6b (Windows)


Usage

To use the Colt bootloader, here are the steps you need to follow:

Firmware PIC Models Notes
bootload.hex PIC18F242/252/442/452,
PIC18F6390/6490/8390/8490,
PIC18F6520/6620/6720/8520/8620/8720,
PIC18F248/258/448/458,
PIC18F2331/2341/4331/4341,
PIC18F2439/2539/4439/4539
512 Byte Boot Block
bootloaduart2.hex PIC18F6390/6490/8390/8490,
PIC18F6520/6620/6720/8520/8620/8720
512 Byte Boot Block,
USART2
bootload1x20.hex PIC18F1220/1320 USART on Port B
bootload2k.hex PIC18F2220/2320/4220/4320,
PIC18F2410/2510/2515/2610/4410/4510/4515,
PIC18F2420/2520/4420/4520,
PIC18F2455/2550/4455/4550,
PIC18F2525/2620/4525/4620,
PIC18F6525/6621/8525/8621,
PIC18F6585/8585/6680/8680
2 kb Boot Block,
Legacy Mode
bootload2kuart2.hex PIC18F6525/6621/8525/8621,
PIC18F6585/8585/6680/8680
2 kb Boot Block,
USART2
bootload2k_e.hex PIC18F2410/2510/2515/2610/4410/4510/4515,
PIC18F2420/2520/4420/4520,
PIC18F2455/2550/4455/4550,
PIC18F2525/2620/4525/4620
2 kb Boot Block,
Extended Mode
bootloadint.hex PIC18F2220/2320/4220/4320,
PIC18F2455/2550/4455/4550*,
PIC18F2525/2620/4525/4620*
2 kb Boot Block,
Internal Oscillator,
4xPLL*,
Legacy Mode
bootloadint_e.hex PIC18F2455/2550/4455/4550,
PIC18F2525/2620/4525/4620
2 kb Boot Block,
Internal Oscillator,
4xPLL,
Extended Mode

Table 1 - Firmware Selection

Colt uses Delayed boot mode, which mean that the bootloader kicks in on startup for two seconds. If it does not receive any bootloader commands, it automatically transfers to the user application (jumps to address 0x0200 or 0x0800 depending on the firmware used).

Starting from version 0.6, Colt can be invoked from command line. If the executable launched from command line in this form:

Colt [filename]

Colt will start in non-interactive mode, will download the specified filename and exit.

I have included two test HEX files (blink-led.hex and blink-led2k.hex) in the installation directory to test 512 byte and 2048 byte boot block devices. If you download this file using the bootloader application, LEDs connected to pin B0 to B3 should start blinking after the bootloader gives control to the user application code.

I intend to support the Colt bootloader application. So, if there are additional devices you would like to support, or have suggestions on new features, send me a mail.


How to Relocate User Code

User code must be relocated at address 0x0200 or 0x0800 depending on the model and firmware used. The start of user space depends on the size of the boot block. Originally, the boot block for PIC18F devices was 512 bytes. However, most new models have a boot block of 2048 bytes. To determine the size of the boot block for your device, you may look at the PicDevices.properties file.

If you are not concerned about protecting the boot block, you can still relocate the user code to address 0x0200 even if your device boot block is 2048 bytes, but you must change the appropriate entry in the PicDevices.properties file and you must use the appropriate bootloader firmware (bootloader.hex).

CCS

For models using a 512 byte boot block, add the following directives in you .c file:

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
  nop
#endasm
} // Reserve space for the bootloader

For models using a 2 kb boot block, add the following directives in your .c file:

#build(reset=0x800)
#build(interrupt=0x808)
#org 0x0000,0x07ff
void bootloader() {
#asm
  nop
#endasm
} // Reserve space for the bootloader

SDCC

Use the compiler directive --ivt-loc 0x200.

HI-TECH PICC-18

In the link phase, use the linker directive -a200h.

Microchip C18

Edit the Linker script 18f452.lkr to add an entry for the boot block. For models using a 2 kb boot block (such as the PIC18F4620), use the Linker script 18f4620.lkr.

Copy or generate the startup objects in MCC18\lib directory. To generate the objects, read end of section.

In the linker script, change reference to startup object. Use c018_200.o or c018i_200.o for 512 byte block microcontrollers. Use c018_800.o, c018_800_e.o, c018i_800.o or c018i_e_800.o for 2k byte block microcontrollers (the startup objects with _e in their name have extended mode enabled).

Also make sure that you have not defined absolute code sections in the source code to start in the boot block. For instance, directives such as this one:

#pragma code InterruptVectorHigh = 0x08

must be changed to

#pragma code InterruptVectorHigh = 0x208

or for 2 kb boot block:

#pragma code InterruptVectorHigh = 0x808

or starting with version 3.0:

#pragma code low_vector = 0x18

must be changed to

#pragma code low_vector = 0x218

or for 2 kb boot block:

#pragma code low_vector = 0x818

To generate C18 startup objects:

Go into the directory where you installed MCC18 (i.e.: C:\MCC18), then go into src\traditional\startup

There are 3 files, you can change all of them, or just the one you need.

Find the line that says:

#pragma code _entry_scn=0x000000

Change it to:

#pragma code _entry_scn=0x000200

or

#pragma code _entry_scn=0x000800

depending on the size of the boot block.

Then, go up one directory (to C:\MCC18\src\traditional) and run the bat file called makestartup.bat. It will put your new libraries into the proper directory (C:\MCC18\lib).

PIC Basic Pro

Add the following line:
DEFINE  RESET_ORG  200h
or
DEFINE  RESET_ORG  800h

The 18F452.inc file (or the appropriate include file) also needs to be modified. In the first '__config' line, the "XT" needs to change to "HS" unless the Configuration bits are changed on the PIC.


Menu Description

You can access Colt menu by clicking the Colt icon in the top left corner of Colt main window.

File

Load File...
Load a hex file in the memory buffer. If the Reload before Program option is selected, the specified hex file is reloaded before every Program command is executed.

Edit Config...
Edit the Configuration bits. Ensure the Reload before Program option is not selected if you want to be able to program Configuration bits after changing them through this dialog, otherwise the content of the HEX file will be reloaded from disk before programming the Configuration bits.

Program
Program device using content of memory buffer. If the Reload before Program option is selected, the memory buffer is filled with the latest version of the file shown in the window title. If the Reset after Program is selected, after the program is loaded, the device is reset. If the Program Config option is selected, the Config bits are also programmed. If the Program Data EEPROM option is selected, the data EEPROM is also programmed.

Program Data EEPROM
Program data EEPROM using content of memory buffer. If the Reset after Program is selected, after the data EEPROM is programmed, the device is reset.

Program Config
Program Config bits using content of memory buffer. If the Reset after Program is selected, after the Config bits are programmed, the device is reset.

Verify
Verifies that firmware on device matches file loaded in memory.

Run
Reset device. It is not necessary to execute this command after Program if the Reset after Program option is selected.

Options

Reload before Program
When this option is selected, the Colt bootloader application reloads the file shown on the windows title before every Program command is executed.

Reset after Program
When this option is selected, the Colt bootloader application resets the device after the Program operation is completed.

Program Config
When this option is selected, the Colt bootloader application also programs the Config bits along with the program memory when a Program command is executed. If this option is selected, user must ensure that the Config value in .hex are set to valid values, otherwise, this may disrupt use of bootloader. For instance, if WDT were enabled in .hex, this would cause disruption because Colt firmware does not support WDT.

Program EEPROM Data
When this option is selected, the Colt bootloader application also programs the data EEPROM along with the program memory when a Program command is executed. Note that the last byte of EEPROM is not programmed, as it is used by Colt firmware to determine startup delay.

Baudrate
Specifies the data transfer baudrate. Colt firmwares auto-detects the baudrate. Unless the PIC is clocked with a crystal of 4 or 8 MHz, the user should be able to transfer programs using a baudrate of 115,200. My recommendation is to start using the highest value and step down only if you see the transfer is really slow (which indicates there are several retransmissions). On a PIC18F1x20 running internal RC at 8MHz, the highest baudrate that can be used is 38,400.


Background Information on the Colt PIC18F Bootloader

The bootloader firmware is based on Microchip's bootloader firmware written by Ross Fosler. Microchip's firmware and bootloader application can be found in the AN851 application note archive.

The bootloader firmware and bootloader application are described in the application note AN851. The source code is available in the ZIP archive.


Devices Tested

Here is a list of PIC devices tested against the Colt bootloader.

The Colt bootloader firmware is very generic and should work with all PIC18F models.

Support for new PIC microcontrollers can be added by adding new entries in the PicDevices.properties file. Each entry has the following format:

<DEVICE_NAME>=<DEVICE_ID>,<LO_PROGRAM>,<HI_PROGRAM>,<LO_CONFIG>,<HI_CONFIG>,<LO_EEPROM>,<HI_EEPROM>,<READ>,<WRITE>,<ERASE>

where the DEVICE_NAME field specifies the device name, the DEVICE_ID field is used to identify the Device ID, LO_PROGRAM and HI_PROGRAM fields define the program code space (low and high addresses) excluding the boot sector. The LO_CONFIG and HI_CONFIG fields specify the low and high Configuration addresses and the LO_EEPROM and HI_EEPROM fields specify the low and high EEPROM data addresses. DEVICE_NAME is a decimal number and all other fields are in hexadecimal format.

For instance, the following entry is used to describe the PIC18F452:

PIC18F452=33,200,7fff,300000,30000d,0,ff,1,8,64

This entry tells the bootloader application that the PIC microcontroller with Device ID 33 is a PIC18F452 with program space starting at address 0x0200 and ending at 0x7FFF. Its Configuration bits are stored between address 0x300000 and 0x30000D and the EEPROM data starts at 0 and ends at address 0xFF. The bootloader application should use 1 byte read block, 8 byte write block and 64 byte erase block for reading and programming purposes.


Contact Info

To contact me, mail to user mdubuc at freeshell.org domain.

Number of hits: 109660

Last updated: January 27, 2007

PIC is a registered trademark of Microchip Technology Inc.