You are on page 1of 6

Microtronics Pakistan

USB Bootloader

User Manual

Amer Iqbal Qureshi

www.electronicspk.com
M
icrocontroller need to be programmed by a properly generated .hex file before they
can do anything useful. Traditionally there have been an external device with a ZIF
socket to accept the microcontroller. It is
then programmed, and put back into the pro-
ject board where it starts executing the program. In case the
program needs to be changed, the newly generated .hex file
has to be updated into the controller. Using an external
standalone programmer has been a fun for a few time users,
but it becomes a nuisance when you have to reprogram the
controller frequently, specially when developing an appli-
cation.
Moreover newer microcontrollers are small, and usually
can not be taken out of the circuit, like SMDs. Microcon-
troller manufacturers therefore came up with the idea of “In
Circuit Programming”. This gave developers a sigh of relief
as now controller does not need to be taken out of the development board. However still you need
a dedicated hardware, a programmer to do the job.

Bootloader came next. Newer advanced controllers have the capability write into their own flash
memory. A small firmware is first installed into the controller using a standard programmer. The
firmware then communicates with its client pro-
gram in PC over the Serial or USB interface. The
client program gets a new copy of the .hex file and
transfers it into the free program memory of mi-
crocontroller. This has eliminated use of a dedi-
cated hardware programmer.
As Laptops no longer have the standard serial
port, it is highly desirable to have a USB based
bootloader that can be used with development
boards or projects. Microchip PIC18F4550 and
PIC18F2550 and many others have built-in USB
module. So you do not need an external chip to
establish USB capabilities.
Once you have the basic hardware that supports USB communication you can load your controller
with an appropriate bootloader firmware. There are quite a few available, including one from Mi-
crochip, I shall introduce here Mikroelectronica (www.mikroe.com) USB HID Bootloader. The
bootloader itself is a small self executable file, that runs directly on PC. To use it you do not need
Mikroelectronica compilers necessarily. It can be used to upload the .hex file generated by any
compiler, may it be PROTON Basic, CCS-C or anything else.
Before using the bootloader, you must load your controller with appropriate firmware. The word
appropriate is important because the firmware is compiled for each MCU type, and oscillator your
board is using.
Microtronics Pakistan PIC Lab-III has PIC18F4550 and an oscillator of 20MHz on board. PIC
Lab-III comes pre-loaded with appropriate firmware file. In case you accidently erase it with your
regular programmer, the file can be downloaded from our site (www.electronicspk.com) and is
also supplied as part of this package.
So now we assume your controller has the bootloader in it, and we have generated a .hex file with
some compiler, like PROTON BASIC and want to upload it. Start the “mikroBootloader USB

HID” application from the package


folder. You will get this application.
This is the client part and waiting for
the bootloader in your board to commu-
nicate with it.
Now connect the board with USB cable
and power it up. Usually you have two
options in most development boards,
either to get external power supply, or
get power from USB. Both are valid,
but make sure if you have enabled USB
power the external power is not there.
As soon as the power is applied to the
development board, or it is made to re-
set, by pressing the reset button, the
bootloader firmware inside the controller starts executing and communicates with the client pro-
gram.

Notice when the bootloader has successfully communicated with client the device name, like PIC
Lab-III appears. Now you have 5 second to press the Connect Button. If you do not press the con-
nect button in 5 seconds the bootloader in controller disconnects itself and if there is already a
loaded program, it is started.
So if you want to load a new program, just click the connect button while the device name is ap-
pearing. Now you can click the “Browse for Hex” button and locate the .hex file that your com-
piler has generated, like Blink.hex and then Click Begin Uploading button. The progress bar will
show the uploading progress.
After the upload process is completed successfully, the client program will disconnect the USB
connection and your program will start executing automatically. In case you want to upload a
new .hex file, just press the reset button on your board, or power OFF and ON and bootloader will
be active again, you will get the device name in client program, press the Connect button immedi-
ately, and rest of the process is same.

You can use this tool with .hex file generated from any PIC microcontroller.
A Note About your Programs
Since bootloader is running, the microcontroller is actually running at 48MHz. Although we have
an external oscillator of only 20MHz, its frequency has been multiplied by an internal mechanism
in PIC called PLL. Therefore when compiling your programs, mention 48MHz oscillator speed
instead of 20. Secondly if required set the HS + PLL fuse for oscillator in your program
When compiling with MikroC we use these fuses.

You might also like