Returning to PIC18F MCHPUSB Bootloader From Software

This one is dead simple, but toil we did over much websearching to no avail.  What we were trying to do is to lazyfi some MCHPUSB-hosted source code.  If you’re not familar, MCHPUSB is the nickname of the Microchip USB bootloader used on the PIC18F series of devices.  They used to be known for a host of cool applications, but now they are best known for being a PSGroove port.  Ahh, those crazy hax0rz.

The really nice thing is that these devices (eg PIC18F2550) contain an entire USB serial interface engine AND phy on board.  Plus a sweet PLL to clock up your crappy 4MHz crystal to a rippin 48MHz (actually 96MHz, then divided by 2) in order to run high speed USB into a sub-$5 micro.  So your entire USB hardware design consists of dropping a USB connector and wiring D+ and D- to your chip.  Brilliant.

Not that we’ve lost any love for FTDI – Every chip they make is better than the last – but for raw throughput, nothing beats onboard hardware.  And we can’t help but get giddy when the manufacturer fully allows you to choke down more data than the CPU could ever handle.  Yum!  That there is a challenge as we see it!  So if we had our druthers, all those Arduino boards would soon become replaced by Pinguino’s blasting hefty data at high-speed USB rates.  But who knows.

The point of this article is to explain how to get back into the bootloader without holding one button (enter BL) and clicking another (reset).  What, do these people think that we’ve got so many free fingers that we can spare two of them for nonsense like this?  What about our homemade firecracker mishaps?  One finger is all we can spare.

So that’s what we’ll do.  Eliminate the reset button and simply hold down the bootloader button for a sec, and we want to be back in the bootloader updating our obviously broken code to something that is SURE to work THIS TIME!  Assuming you’re using c18, you work this piece of magic with the majestic function:


Yeah, we were just as disappointed when we realized it.  After re-initting a bunch of variables, faking interrupt states and trying to force the software back into the bootloader didn’t work, this is what we came up with.  And it friggin worked.  Damn.  So this unnecessarily wordy article will serve as our electronic post-it for the next time we can’t remember how to soft reset a PIC18.

The full monty of counting down a sentinel and resetting the CPU is hacked together here.  And yes, it’s tested and verified to re-enter the MCHPUSB bootloader when the desired button is held down for one second.

//Check RST Button
 if(pRST==0){  // Is our button down?
if(rsttimer<1){  // And has our counter expired?
pOUT2=!pOUT2; // Toggle a pin - debug
rsttimer=75*LongBounce;  // Not really necessary
} else {
rsttimer--;  // If not expired, then decrement counter and leave
} else {
rsttimer=LongBounce;  // Pin went up before expiry, reload ctr

Wow, we just hope that this can help you NOT waste the 2h that we burned on this silly issue.

This entry was posted in Miscellaneous. Bookmark the permalink.

0 Responses to "Returning to PIC18F MCHPUSB Bootloader From Software"

Leave a reply