A bootloader is a PIC program used to upload code directly to the PIC memory, without having to deal with a PIC programmer.
A bootloader lives in microcontroller's memory. When powered, it is launched and it tries to contact a host, typically a PC host, and gets some code. This code is then recorded to PIC program memory. The way bootloader reaches host is typically through a serial link or USB.
When using a bootloader, there's actually two programs within your PIC: the bootloader itself and user's program. So, how does the PIC knows which to run ? Usually, bootloader lives near the end of PIC memory. User program, when compiled, adds a special instruction which tells the PIC to jump to bootloader program. This instruction is executed at the very beginning1. When bootloader is launched, it waits for some instructions coming from PC host. This is where user's program is sent, bootloader writing bytes of code at the beginning of memory. If no instructions was received for a given amount of time, it timeouts and jump back to the beginning of PIC memory. User's program is executed.
Why do you need this anyway ? There's no actual need, you can safely skip this part and continue to use PIC programmers. Some even prefer this way, as there are common pitfalls when using bootloaders, pitfalls you may face some day or another... So, does it worth it ?
Using a bootloader can simplify your life. For instance, you may not always have your PIC programmer around, you may not even own one. You may have access to a programmer, at a friend's or your robotic club's. Will you have to go there every time you need to program your PIC ? And possibly loose friends ?... You'd better want to program a bootloader once, then go back home and safely have fun by programming your PIC using your serial port or USB.
In addition, as there's no need for high voltage programming, as when using a PIC programmer, there's no need for yet another power supply. Programming is easier, and usually also faster (programmers can be slow). And because bootloaders use common communication links, you could be able to program your PIC through the air, using for instance a bluetooth-to-serial adapter.
Jaluino comes with bootloaders' sources, in case you need to modify them. This is an ASM file (PIC assembler) for Tinybld, and a Jal file for PDFUSB.
Which one to choose ? There's no definite answer, you may need to switch between both, depending on your project. The only restriction is about serial: if you don't have any serial module, you'll clearly have to use PDFUSB...
The following matrix sums up main features for both bootloaders, this may help you make your choice.
| Features | Tinybld | PDFUSB |
|---|---|---|
| Size | 100 words, or 200 bytes | ~2000 bytes |
| Timeout | 1 second | ~10 seconds |
| Communication link | Serial | USB |
| Serial adapter needed | Yes | No |
| Can reset PIC | Yes, via RTS | No |
In order to get a fully functional Tiny bootloader, you'll need to act on several parts of Jaluino environment.
First, you need to program the bootloader itself. Follow instruction in previous Blink a LED section, and upload Tinybootloader HEX file bootloaders/tinybl/18f4550/tinybld18f4550_20mhz_external_48mhz_pll_115k.hex available in downloaded archive, or from Tiny booloader files SVN repository.
If you want to use Reset via RTS feature, you also need to put a jumper on J7, on Jaluino mainboard. This jumper must be put on the two most left connectors. Please refer Jaluino User Guide, section Hardware Setup. If you don't use this (leave J7 without any jumper, or jumper on the right connectors to activate RTS line), you'll need to push Reset button each you upload a program.
Finally, Jaluino IDE needs to be configured. Because serial link will be used to upload program to the microcontroller, you need to specify serial port and baudrate. Please refer to Jaluino IDE configuration and serial setup. If you didn't change any parameter in bootloader, you'll use 115200 bauds as speed. Serial port should be setup accordingly to your system.
Compilation and Upload default commands should also be set. You'll avoid common pitfalls, like compiling with wrong parameters. Open Jaluino IDE settings, and click on "General" tab. This is where you associate commands with file types. Select "Jalv2" file type, and choose "Jaluino with Tiny/18F" command as default. Just close the window in order your new settings to be saved.
Proceed the same about produced HEX files, uploaded to Jaluino. Select "Hex" file type, and choose "Tiny bootloader"
Except if you forced and specified other options in IDE, this setup will be used by default.
Let's try this by uploading our "Blink a LED" sample with Tinybld. Select appropriate sample following guidelines detailed in previous section. Make sure "Jaluino with Tiny/18F" is your compilation command, and click on "Compile". Jaluino IDE has generated appropriate command line, generated HEX file is ready to be uploaded.
Sample is ready to be uploaded, make sure "Tiny Bootloader" is selected in upload commands, and press "Upload" button. If Reset-via-RTS feature has been enabled, Jaluino will automatically reset and Tinybld2 will send program. If not, just press and release Reset button.
Once uploaded, your program is immediatly executed, you should see your LED blinking.
Closed to what done with Tiny bootloader, using PDFUSB requires you to act both on hardware and software sides.
First program the bootloader itself. HEX file can be found in archive, as bootloaders/pdfusb/18f4550_usb_bootloader_autostart.hex. You can also retrieve it from Jaluino SVN repository. Follow instructions detailed in Blink a LED section, in order to upload this file using a programmer.
Once done, you should configure default commands in Jaluino IDE, both for compilation and upload steps. Open Jaluino settings window, and click on "General" tab. Select "Jalv2" file type, and choose "Jaluino with PDFUSB" as default command.
Proceed the same with default upload command. Select "Hex" file type, and choose "PDFUSB bootloader" as default command. Close window to save new settings.
PDFUSB is now configured. As it doesn't use a serial link, there's no for serial configuration. Remember PDFUSB can't reset a PIC running user's program: in order to upload a HEX file, you'll need to push Reset button.
Now, let's blink again our LED, this time using PDFUSB bootloader. Refer to Blink a LED section and open sample. Ensure "Jaluino with PDFUSB" is selected as compilation command, and click on "Compile" button. Notice the generated command line has changed and includes appropriate parameters.
"PDFUSB Bootloader" should be selected in upload commands. Click on "Upload" button. Jaluino needs to reset to activate bootloader, so press Reset push button on board. Wait for a while, you should get PDFUSB output, claiming it has flashed your program. If you get an error, try again by pushing and maintaining Reset button, then click on "Upload", then release Reset2.
Using -x option, PDFUSB automatically resets and run user's program. You should see your LED blinking as soon as program was flashed. Note the next time Jaluino is turned on, you'll need to wait PDFUSB timeout (approx. 10 seconds) before your program is executed.
This sounds scary, isn't ? Luckily, using Jaluino IDE default compilation commands, "Jaluino with Tiny/18F" and "Jaluino with PDFUSB", will ensure you're using correct options.
And, at the end, breaking a bootloader isn't that bad, you'll have a good reason to visit your friends !
| Attachment | Size |
|---|---|
| jaluinoide_tiny_rts.png | 25.87 KB |
| jaluinoide_tiny_compile.png | 16.02 KB |
| jaluinoide_tiny_upload.png | 16.62 KB |
| jaluinoide_tiny_compile_output.png | 15.45 KB |
| jaluinoide_tiny_upload_output.png | 41.38 KB |
| jaluinoide_pdfusb_compile.png | 15.96 KB |
| jaluinoide_pdfusb_upload.png | 16.65 KB |
| jaluinoide_pdfusb_compile_output.png | 15.54 KB |
| jaluinoide_pdfusb_upload_output.png | 34.47 KB |