USB Bootloader with PICKit 2? Confused!

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

USB Bootloader with PICKit 2? Confused!

Post by Aresby » Tue Jul 21, 2015 6:28 pm

Hi Guys

After a 2 (or is it 3) year absence from this forum (life goes on, while God laughs at your PIC-related plans and all that) I have a fundamental question that has foxed me on my return.

I now have a PIC 18F4550 development board, with a PICkit2 interface to upload (download?) the programs onto the chip, which works just fine.

I now want to experiment with the USB side of things on this chip and am looking at the USB HID Demo project on this very site (see USB HID Keyboard Demo. Written by Nathan Herbert), but which seems to be intended for use on a board with a USB Bootloader (it has #option org_reset = $800).

Now, I'm thinking, I don't need or want any kind of code download capability via USB as I have my trusty PICkit2 so why do I need a USB bootloader? Surely this doesn't actually provide the USB basic fundamental functionality (the USB Demo HID project seems to indicate that David or Jerry has already provided all that in that project in standard Swordfish code as a port from the original Microchip version).

So the question is: do I *need* a USB bootloader regardless, because it does more than just allow program uploads, or can I remove that compiler directive and just run my code from address 0x00?

Oh it's good to be back!
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB Bootloader with PICKit 2? Confused!

Post by Jerry Messina » Tue Jul 21, 2015 7:35 pm

Welcome back, Aresby!

It looks like it should build ok if you comment out the '#option org_reset = $800' statement in the example code and run it standalone w/the PICkit2.

Just be sure to use the original USB libraries that come with the compiler.

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Re: USB Bootloader with PICKit 2? Confused!

Post by Aresby » Wed Jul 22, 2015 7:03 am

Thanks for the welcome, Jerry, I hope it's not a temporary visit!

I'll give this a go then, and just build and load the entire sample USB HID Keyboard project and see what happens.

Can you just elaborate what you mean by "be sure to use the original USB libraries that come with the compiler" - the aforementioned project uses those by default, yes? Is there something special I need to look out for?
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB Bootloader with PICKit 2? Confused!

Post by Jerry Messina » Wed Jul 22, 2015 12:23 pm

> Is there something special I need to look out for?

I don't think so. I was just trying to point out that I think the demo was written for the original stack, so to avoid having to make any changes you'll want to use that one.

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Re: USB Bootloader with PICKit 2? Confused!

Post by Aresby » Wed Jul 22, 2015 6:09 pm

So my newly prepared development board is all set up, the obligatory, flashing LED program downloaded (via PICkit2) and working --- and then the obligatory brick wall.

I've built the USBKeyboardDemo project and downloaded it (minus the #option org_reset = $0800). So the code should start running at address 0x0.

I then plug it into the USB port on my PC expecting a "New Hardware Found, HID Keyboard" message from Windows (or similar) but no, not a ding, not a message, absolutely nothing. Basically, Windows doesn't seem to know I've plugged anything into the USB port.

Has anyone actually ever used this project code successfully?

Any ideas on what possibly could go wrong? I was really hoping to avoid 'rolling my own' USB interface, I don't have that many years left on this earth.

I've checked that I have a 20Mhz Xtal installed as I'm aware that the USB interface is picky about clock rates.

The board itself 'works' as the flashing LED program proves.

Any ideas?
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB Bootloader with PICKit 2? Confused!

Post by Jerry Messina » Thu Jul 23, 2015 2:30 pm

I don't have a 4550 handy, but I built the program for an 18F2553 (which is pretty much the same thing) and it ran ok for me. Fired right up (win7 x64).

The only changes I made were some minor ones to match my device/osc setting. The clock setup as posted looks ok for 20MHz xtal.

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Re: USB Bootloader with PICKit 2? Confused!

Post by Aresby » Thu Jul 23, 2015 6:21 pm

Thanks for the update Jerry.

When you say you just built it, did you do so removing the $0800 address or did you have a USB bootloader present?

And when you plugged it into the Windows USB port it immediately came up with the "New Hardware Found" message?

I tried a different USB cable but same (non) result.

Perhaps the development board is dodgy after all...
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB Bootloader with PICKit 2? Confused!

Post by Jerry Messina » Thu Jul 23, 2015 7:56 pm

Sorry... should have been more specific.

>> did you do so removing the $0800 address
Yes, I commented out the '#option org_reset'

>> it immediately came up with the "New Hardware Found" message
I seem to remember seeing it once, but I usually monitor that sort of thing with USB TreeView which gives you all the gory details
http://www.uwe-sieber.de/usbtreeview_e.html

The only thing I really changed was the device and osc config setting since my hdw has a 24MHz xtal.

Is your board powered via USB 5V?

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Re: USB Bootloader with PICKit 2? Confused!

Post by RangerBob » Fri Jul 24, 2015 1:58 pm

Aresby wrote: Has anyone actually ever used this project code successfully?
Yup, I wrote up the demo after a good chunk of it went into a commercial project (along with a bunch more code) ;).

I've also used the core of that code, with updates to Jerrys new USB stack on 18F27J53, 18F47J53 and 18F87J50 devices.

As Jerry said, the bootloader is entirely optional, just comment out the line as suggested. I just prefer having a bootloader on my projects as it makes in field / in system updates much easier. It can be safely removed by just commenting that line.

If you would like an example of an updated project I can share with you, let me know and I'l PM you one that will work with Jerrys (recommended!) updated USB stack. Not much has to change really, just

Dim KeyReport As TKeyReport Absolute TXReportRAM // Set to use original USB libraries
to
Dim KeyReport As TKeyReport Absolute TX_REPORT_RAM // Set to use updated 1.4 stack USB libraries
and
Dim LedsReport As TLedsReport Absolute RXReportRAM // Set to use original USB libraries
to
Dim LedsReport As TLedsReport Absolute RX_REPORT_RAM // Set to use updated 1.4 stack USB libraries

Regards

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Re: USB Bootloader with PICKit 2? Confused!

Post by Aresby » Fri Jul 24, 2015 2:15 pm

@Jerry Yes I power the board from the USB but I also tried powering from external PSU, no difference either way.

@RangerBob Yes, I'd appreciate a version that is absolutely known to work for you. If I load it up and nothing happens then it's my board and not the code, at least :) Does the project already have Jerry's updated USB code embedded within it or do I have to load something else?
Aresby
Swordfish & PIC Newbie

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Re: USB Bootloader with PICKit 2? Confused!

Post by RangerBob » Fri Jul 24, 2015 2:40 pm

You can get the updated USB 1.4.3 library from the User Modules Page:
http://www.sfcompiler.co.uk/wiki/pmwiki ... USBLibrary

Check your PM for more information.

Here's a Hex file compiled and Tested on my 18F4550 PICDEM FS USB board. I just changed the Led ports, from the one I gave you eg. change to:
Dim
LED0 As PORTD.0,
LED1 As PORTD.1,
LED2 As PORTD.2,
LED3 As PORTD.3

Plug it in, it will enumerate as "Keyboard" on devices and printers, plus flash the capslock 3 times, then activate after a while.

https://dl.dropboxusercontent.com/u/634 ... Roller.hex

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Re: USB Bootloader with PICKit 2? Confused!

Post by Aresby » Fri Jul 24, 2015 5:20 pm

I'm afraid this gave me 404 reasons to be sad :(

I'm willing to give it another go if you are :)
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB Bootloader with PICKit 2? Confused!

Post by Jerry Messina » Fri Jul 24, 2015 7:11 pm

Not to confuse things, but I built the wiki keybd demo with the USB library included with the compiler, so I know that works too.

What's your hardware look like?
USB D+ and D- around the right way?

When you power it up do you have 3V3 on the VUSB pin (along with the req'd capacitor?)

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Re: USB Bootloader with PICKit 2? Confused!

Post by Aresby » Sat Jul 25, 2015 4:38 pm

Will check the USB connections but the hardware is the RKPK40 Prototype Kit (I'll try and attach a photo of it) so it is less likely I got the connections wired up the wrong way (this from the man who connected the PICkit2 the wrong way round for more than a year and wondered why it didn't work).

Here's a company that sells it although I got mine from eBay:

http://www.rapidonline.com/Design-Techn ... Kit-551978

My version is slightly different inasmuch that it supports both 5v and 3v3 via a small switch (it has two power regulators on board rather than just the one).

Anyway, if RangerBob could send me a replacement working link for the project source / hex that would be great so I can absolutely prove whether it's the board (I have two) or me being stupid.

I can't believe this project is giving me so much grief. Maybe it's an omen.
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB Bootloader with PICKit 2? Confused!

Post by Jerry Messina » Sat Jul 25, 2015 7:31 pm

I got a schematic for the RKPK40 from the RK Education website and I don't know how well it matches what you've got, but there are a few discrepancies/issues with what's shown.

On that board some things to double-check:
- the xtal is shown as 10MHz, not 20MHz

- the USB D+/D- signals at the connector don't appear to be connected right (but I think they're just mislabeled).
PIC pin 23 RC4/D- should go to USB pin 2
PIC pin 24 RC5/D+ should go to USB pin 3

- there's a 100uF cap on the output of the 7805 5V regulator, and that violates the USB spec.
max should be 10uF. A lower value will make the PICKit2 happier also.

- the USB VBUS 5V is connected to the output of the 7805 5V regulator, so DO NOT try to use the external power connection or power it from the PICkit2!!!
That'd force 5V down the VBUS rail back to the host, which is forbidden


I'd recommend you use the USB 5V to power the board anyway. The USB stack doesn't handle being self-powered very well without making some changes. You have to have an IO pin connected to the USB VBUS signal (pin 1) so that you can monitor if you're attached. You're not supposed to turn on the USB peripheral unless there's 5V on that pin, otherwise the host will probably lock out the port. By default the software turns on the USB peripheral when it powers up.

So much for an education. Is there a schematic for what you actually have?

Post Reply