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 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.
OK, so the bootloader isn't really in the same league as the other UBW
firmware versions. The bootloader sits in the PIC's flash from 0x0000
to 0x0800 and all of the other firmware versions take up 0x0800 through
the end of Flash. This means that both applications reside in flash at
the same time. You use the Bootloader to program new firmware versions
into Flash with just a USB connection and a special application on the
PC side.
How It Works
The Bootloader is just 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 student 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. 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.
To
Download New Firmware
The first thin 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 install files for the
"Microchip Custom Driver" from this
link. The intaller will put some files onto
your computer which are used when you connect your UBW in Bootloader
mode for the first time. With the UBW board pluged 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
(by default the installer puts it at C:\MCHPFSUSB\Pc\MCHPUSB
Driver\Release). Click through the dialog boxes to install the INF
file. (The exact squence of this depends upon your version of Windows.)
Next run the PC Bootloader Application, which is
called 'PDFSUSB.exe' and is located at C:\MCHPFSUSB\Pc\Pdfsusb by
default. Once running, select the PICDEM FS USB 0
(boot) slection 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
previouslys 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
PDFSUSB.exe
Click "Program Device" and wait until programming is done (just a
couple of seconds)
Reset your UBW to run the new firmware
Notes
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 powerup
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
programmer.)
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.)