UBW Firmware B (Bootloader) Documentation
General - What is a bootloader? Why
would I need something to load my boot anyway?
A bootloader is a small piece of code that typically lives on a
microcontroller. It allows you to write (program) your application
(firmware) into the microcontroller. It communicates with a host PC
over some type of communications channel - serial, CAN, Ethernet, or in
the case of the UBW, USB. So why is this a neat thing to have?
Because it allows you to write your own applications (typically in C,
using MPLAB and the C18 compiler, but not necessarily) and program that
application into the micocontroller without needing additional
programming hardware. Without a bootloader, you would need to purchase
some type of hardware programmer that would erase and then program your
microcontroller with your application. But the bootloader does this for
you, and allows you to program the micro with no additional hardware.
On the UBW, the bootloader and the firmware application both live in
Flash memory at the same time. The bootloader lives from 0x000 to
0x7FF, and the firmware application lives from 0x800 on up to the top
of memory. The block of flash from 0x000 to 0x7FF is called the boot
block, and on the UBW it is write-protected, which means that even if
you screw something up really bad, you can't damage the bootloader.
Also the bootloader HEX file contains the config bit settings, and
these are also now (2/23/11) write-protected, so that you should not be
able to brick your UBW no matter what you try to program on it.
How It Works
As a demonstration of their USB chutzpa, Microchip developed a simple
bootloader and corresponding PC application called PDFSUSB.exe. When
you put your UBW into "bootload mode" and run the PC application, you
will then be able to download new firmware HEX files to your UBW.
The UBW bootloader is based upon Microchip's
USB bootloader code, but I had to change it very slightly so it
would use the correct I/O bits for the LEDs and Program switch (and
config settings) on the UBW board rather than the ones that come on
USB dev board. I also had to move some things around in memory so it
would fit in the boot block when compiled by the light version of C18.
So how does it work? Well, if you plug in your UBW, or press the reset
switch, the Bootloader gets control of the processor since it lives at
the reset vector location of 0x000. It checks to see
if the Program (PRG) switch is pressed. If so, it runs its own USB code
that enumerates the UBW as a "PIC18F4550 Family Device" under "Other
Devices" in the Device Manager, which communicates with the PC via
Microchip's custom driver. You then run the bootloader application from
the PC, and you can erase your UBW (only the part that doesn't contain
the bootloader firmware), read it, write it, etc. The really great
thing is that you can quickly and easily put new firmware on your UBW
without having any extra hardware.
If the PRG switch is NOT pressed when the UBW comes out of reset, then
the bootloader just jumps to location 0x800, which is where the main
firmware application is located, and the main firmware then runs from
Firmware using the Bootloader
The first thing you need to do is acquire the new HEX file you want to
program into your UBW. You can find several on this website (for FW C,
D etc.). You can also make your own by using a compiler or assembler.
Then you need to download the for the
"Microchip Custom Driver" from this
link. When you connect your UBW in Bootloader
mode for the first time, with the UBW board plugged into the USB
press and hold the PRG (program) switch
while you press and release the RST
(reset) switch on your UWB. You can then release the PRG switch. If
this is the first time you've run a UBW
in bootloader mode on your PC, Windows will ask you to install a new
device. Point it to the place where the 'mchpusb.inf' file is located
(wherever you downloaded and extracted it from the zip file). Click
through the dialog boxes to install the INF
file. (The exact sequence of this depends upon your version of
Next run the PC Bootloader Application, which is
called 'PDFSUSB.exe'. Once running, select
the PICDEM FS USB 0
(boot) selection from the "Select PICDEM FS USB Board" pulldown, which
will connect the bootloader PC app with the UBW bootloader
code. Then just click "Load HEX File" and navigate to where the new
firmware HEX file is that you want to download. Then click "Program
Device". When it's done, it will tell you in the little log window on
the bottom. After that you just press
the RST switch on the UBW and your new firmware will start running.
This all sounds complicated, but once you do it a couple times it
becomes real quick. And many of the steps above only need to be done
the first time.
To recap, here are the steps to download new code to the UBW (if you've
previously connected it to your PC in Bootloader mode)
- Build your new code and generate a .hex file. (Or just download a
new HEX file from this website - a new firmware version for example.)
- Run PDFSUSB.exe
- Hold down PRG while resetting the board (pressing and releasing
the RST button)
- Pull down "PICDEM FS USB 0 (boot) from within PDFSUSB.exe
- Click "Load HEX File" and load in your new hex file into
- Click "Program Device" and wait until programming is done (just a
couple of seconds)
- Reset your UBW to run the new firmware
What if I have a blank PIC and need to
put the bootloader on it?
This would be the case because you've built your own UBW hardware based
on the schematics from this website. Congratulations!
You need some type of ISCP (In Circuit Serial Programmer - that's the
name of Microchip's proprietary 2-wire programming protocol)
programmer like the PICKit2 or the ICD2 (both from Microchip). You then
connect your programmer to the ICSP port on the UBW, load the
appropriate bootloader HEX file (there are versions for 20MHz, 4MHz and
24MHz oscillators, see the main UBW page) and program it into the PIC.
When you're done, reset
the PIC. Then proceed as above with downloading new firmware to your
- The HEX file for the bootloader firmware (Firmware B) contains
config fuse settings so that it will run on the UBW board. When you
program a new firmware (C, D, S, etc.) on the UBW, those HEX files have
NO config information in them. Whatever is in the BOOTLOADER's HEX file
is what really controls the UBW's config settings. Normally you won't
care about this, but if you want to do things like change the power up
setting of the watchdog timer, or the brownout level, the easiest way
to do this is to change the config settings in the C code of the
bootloader firmware, then recompile and burn a new bootloader HEX file
with the new config settings. (Note that re-programming the bootloader
takes some type of real PIC programmer that can do ICSP.)
- So what if you want to burn a new bootloader hex file? Well, for
that I believe you DO need to use a full blown hardware programmer. I
don't think the bootloader can over-write itself. So connect up to the
5 ICSP pins on the end of the UBW and program with a normal programmer.
(I use the PICKit2
- When the bootloader firmware is active and running on the UBW,
the red LED will flash quickly. This is in
contrast with the normal appearance of the other firmware loads, where
only the yellow LED slowly flashes.
- It doesn't matter if you start PDFSUSB.exe first or put your UBW
board into bootloader mode first. (Steps 2 and 3 above.)
Questions? E-mail me at