SchmalzHaus logoUBW 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 Microchip's 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 there.

To Download New 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 port, 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 Windows.) 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)
  1. 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.)
  2. Run PDFSUSB.exe
  3. Hold down PRG while resetting the board (pressing and releasing the RST button)
  4. Pull down "PICDEM FS USB 0 (boot) from within PDFSUSB.exe
  5. Click "Load HEX File" and load in your new hex file into PDFSUSB.exe
  6. Click "Program Device" and wait until programming is done (just a couple of seconds)
  7. 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 UBW.

Questions? E-mail me at my e-mail address

Creative Commons License
UBW USB Bit Whacker by Brian Schmalz is licensed under a Creative Commons Attribution 3.0 United States License.
Based on a work at
Permissions beyond the scope of this license may be available at