PIC18F2550 USB bootloader

Support for Bloader and Screamer

Moderator: phalanx

PIC18F2550 USB bootloader

Postby plecharts » Sat Oct 30, 2010 7:04 am

Hi, I am looking for working bootloader for PIC18F2550. I have tried few, but noone talked to my PC (Windows 7). Do you know some?
plecharts
 
Posts: 6
Joined: Sat Oct 30, 2010 6:42 am

Re: PIC18F2550 USB bootloader

Postby EmbeddedMan » Sun Oct 31, 2010 4:46 pm

In the Microchip Application Libraries (http://www.microchip.com/MAL) they have two USB bootloaders that will work with that PIC. A custom USB class one and a HID based one. Both work fine - I use them on the UBW, UBW32 and EBB boards (all sold by SparkFun). PC software, including source, is included as well. As long as you use the code on Microchip PICs, you are free to use it for anything you want.

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Re: PIC18F2550 USB bootloader

Postby moorejl » Mon Feb 07, 2011 12:19 pm

I have been looking at USB bootloader options for the 18F4550, and ran accross the issue of needing to bump the code start and interrupt vectors. I understand the basic concept since the bootloader is occuping the space the app normally does, but my question is: why not just locate the bootloader at the end of memory and load the app in the normal space?

Jamie
moorejl
 
Posts: 48
Joined: Fri May 07, 2004 9:41 pm

Re: PIC18F2550 USB bootloader

Postby EmbeddedMan » Mon Feb 07, 2011 9:23 pm

That IS a good question! I believe the answer is that the way that some (all?) PICs allow you to select pages of Flash to protect works from the bottom (0x000) up. So you can protect page 0, or page 0 and 1, or 0, 1 and 2, but not just page 1 or just 1 and 2. So you can't set the protection bits on the last page(s) (which would contain the bootloader) - you would have to set the protection bits on the whole part, which wouldn't work very well when you wanted to bootload. Why set them at all? So people can't over-write the bootloader. (Ask me how I know that.)

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Re: PIC18F2550 USB bootloader

Postby moorejl » Mon Feb 07, 2011 11:02 pm

Brian, thanks for the answer, makes perfect sense. I didn't realize the bank protection was not bank by bank.

Being a bit of a greenhorn on boot loaders, I have another question: If a bootloader needs/uses interrupts in it's operation, does that rule out using interupts in the app that gets loaded, since they are remapped to the high memory locations?

Jamie
moorejl
 
Posts: 48
Joined: Fri May 07, 2004 9:41 pm

Re: PIC18F2550 USB bootloader

Postby EmbeddedMan » Wed Feb 09, 2011 6:30 am

No. You can use interrupts in your bootloader AND your app. Here's how it work (with all bootloaders that I've seen for the PIC):

There are three interrupt 'vectors' on an 8-bit PIC. Reset, ISR_High and ISR_Low. Reset is always located at 0x0000, ISR_High is at 0x0008 and ISR_Low is at 0x0018. (I think - I don't have my code in front of me. But the actual address don't matter for you to understand how they work.) Because this area is located in the boot block where the bootloader lives, the bootloader needs to deal with these vectors in some way, not only for itself but also for the app.

In the application, there are 3 relocated reset 'vectors'. For example, with the USB HID Bootloader, they are at 0x1000, 0x1008 and 0x1018. (Notice the pattern.) Those vectors are at the very beginning of the _application_ space in Flash.

So here's what the bootloader does. For any of the vectors that the bootloader DOESN'T need, it simply puts a jump from that vector to the relocated vector. For any vectors that it DOES need (Reset at a minimum) it puts a jump to it's own routine, and then inside that routine, decides if the bootloader is active or not, and if it is not, jumps to the new vector location.

I'll give you an example. Let's say the bootloader needs the ISR_High at 0x0018. So it puts a jump from 0x0018 to it's ISR_High() routine (which is inside the bootloader code). In the ISR_high() routine, it checks to see if the bootloader is running (maybe there's a global variable with a unique location or some other means of knowing) and if not, it does a jump to 0x1018.

So your application code will put a jump at 0x1018 to it's own ISR_High_App() routine, which will then process the interrupt like normal.

This way the bootloader and the app can, in essence, share each of the vectors, and the app can put it's vector jump table right at the beginning of its own space in Flash. It all works quite well.

The only downside is that there is a several instruction speed penalty when you use interrupts in an application in a system with a bootloader, because of the extra couple jumps necessary.

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Re: PIC18F2550 USB bootloader

Postby moorejl » Wed Feb 09, 2011 11:22 am

Brian, thanks for the detailed and informative explanation. It doesn't seem all that mysterious anymore.

I had another thought on protecting the bootloader flash region by range checking the address of any table writes. That way you can put the loader in high memory and not worrry about it getting sent addresses that stomp its own area. You would have to take similar precautions in the app code if it also will also write to flash.

I did lookup in the config info on the 18F4550 and you can protect single blocks at a time, but the block size is huge, so that is what sent me off thinking about other ways to protect the bootloader without wasting application space.

Jamie
moorejl
 
Posts: 48
Joined: Fri May 07, 2004 9:41 pm

Re: PIC18F2550 USB bootloader

Postby EmbeddedMan » Thu Feb 10, 2011 6:25 am

Yes, I have modified the stock Microchip USB HID bootloader for use on my EBB board, and I do address range checking so that you can't over-write the bootloader with a new HEX file. It is a good thing to check for.

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm


Return to Boot Loading

Who is online

Users browsing this forum: No registered users and 1 guest