USB HID Bootloader and USB OTG

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

USB HID Bootloader and USB OTG

#1 Post by Rotary_Ed » 02 Oct 2013 23:38

I again wrestling with the USB HID bootloader -again!. With some kind assistance from several folk, I finally got the bootloader code to load to my PIC32MX795F512L on my Mikro easyPICFusion 7 development board got it to work.

So now I am at the point I am trying to use the code on my own board. This board is configured for the PIC32MX795F512H (64 pins) as contrasted to the easyPIC board PIC32MX795F512 (100 pin) chip.

I have repeated tried to upload the bootload code (which appears to happened successfully) to my board, but the USB HID Tool never finds it. In fact, the PC (Windows 7 64 bit) gives a "Device not recognized" message each time I press the reset button on my board. From my research, apparently the most common caused by a frequency mismatch, or lack of the properly TPL list.

The only thing I changed when I compile for the PIC32MX795F512H is the device name. Frequency is the same at 80 MHz. The USB pins are the same on both chips.

But my chip does have the micro a/b socket (required for OTG mode) which is wired so that a micro b plug will short plug pins 4 and 5 to ground - which should tell my chip to become a USB device. I have tried it on two boards, so not too likely a board build error giving the same results - and I have checked it a dozen times.

Are their different drivers required for the OTG mode that are not present/available? I know the OTG mode needs to have a TPL(Targeted Peripheral List) table of specific devices listed - perhaps that is missing?
I had assumed that it only needed that list if it were acting as an OTG host, but perhaps I am incorrect on that point.

Anyone successfully using the USB HID booltloader to other than a mikro board?

Thanks
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: USB HID Bootloader and USB OTG

#2 Post by Rotary_Ed » 03 Oct 2013 19:43

Well, thought I had found an error in the installation of the USB port on my board (would have been quick to fix), but turns out it's installed correctly - so no luck there.

Whenever I press the reset button on my board, the PC responds with a "Device not recognized" message.

When I click on the offending port on the PC - it tells me that either a required driver is not loaded OR not needed for this device. It will do this each time in response to my reset. So there is some signal of some type back and forth between PC and PIC.

Attached Is screen copy of error messages - any suggestion about what I might try to determine where the problem lays?

I checked the configuration bytes for both the code that runs successfully on the easyPic Fusion 7 board and the code for my board. The only difference is the different chip ..512H at compile time rather than the ..512L on the easyPic board.
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: USB HID Bootloader and USB OTG

#3 Post by Rotary_Ed » 03 Oct 2013 20:16

Ok, I'm beginning to doubt what little understanding I thought I had about the PIC and USB.

Here is dumb question #1.

I see that there are registers/bits to set to turn on the various features of the USB/OTG on the PIC32MX795F512H. These include U1PWRC.USBPWR to power up the USB module, then there are U1OTGIE to set up the OTG function for interrupts, etc, etc.

I initially thought that the bootloader code would have instructions to set whatever USB registers were necessary - and it may have. But when I use the IDE "Find in file" and try to locate in the code where these registers may be addressed - I get no hits. So am I correct that all of the essential registers/configuration are set in the USB HID Library?

OR am I suppose to set these in source code before loading the bootloader code and run them? Just can't believe that is correct, the bootload operation erases the source code.

Going in ever decreasing circles.
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: USB HID Bootloader and USB OTG

#4 Post by Rotary_Ed » 04 Oct 2013 18:20

Success!! Finally!

Yes, I finally got the USB HID bootloader working with my chip and board. And yes, as is typical it was a small - but extremely important fact that I had not understood.

It was when I was reading the data sheet section on oscillators and saw a more comprehensive drawing of the oscillator and timing components that the light bulb came on.

As you know whatever xtal/resonator freq you are using to use the PLL system, that input must be between 4-5mhz. So in my case using a 24 Mhz (won't get into why that choice) for the PPL system I must divide by 6, 24/6 = 4 Mhz. So FPLLIDIV must be set for divide by 6.

What I didn't understand before looking at the diagram was that while I knew the input for USBPLL must also be 4mhz, I had assumed that dividing by 6 for the PPL input did the job. Not So! You must also divide you frequency input so that the USBPLL will also have an input of 4 Mhz. You must do this in addition to the FPLLIDV register. In this case for the USB, it is UPLLIDIV register set for divide by 6 (for my 24 MHz osc)

My system clock freq is 64Mhz and peripheral bus is 1/4 that or 16 Mhz.

Using the original USB_HID code in the example it was set up for an 8 Mhz oscillator (as is my easyPIC Fusion 7 board) and so it worked right off the bat. With this configuration:

8-80Mhz

DEVCFG3 :$1FC02FF0 : 0xC7070000
DEVCFG2 :$1FC02FF4 : 0x00000151 //This is for an 8 MHz osc and is the register where changes were required for my board
DEVCFG1 :$1FC02FF8 : 0x0094C503
DEVCFG0 :$1FC02FFC : 0x110FF00F

But for my board that would not work, I was screwing it up because I thought the division for the USBPLL was handled by the division for the PPL (system).

So when all of this is set up correctly my configuration bits look like this:

DEVCFG3 :$1FC02FF0 : 0xC7070000
DEVCFG2 :$1FC02FF4 : 0x00000515 //Notice the difference for my 24Mhz Osc
DEVCFG1 :$1FC02FF8 : 0x0014C5A3
DEVCFG0 :$1FC02FFC : 0x110FF00F


The config editor display for each is attached. Note that the PPL Input Divider selection and the USB PPL Input Divider are different because of the two different oscillator frequencies on the two boards, but they are the same value for each chip.

So after a few days, one datasheet diagram turned on the light bulb.

Now was it worth the effort?- well, my products bootloading of new code typically takes 8-16 minutes using the UART Rs232 method. My customers do grumble about the length of time it takes, well this USB_HID loads it all in 10 (that's right ten) seconds. For an improvement ratio of around 60:1 - so well worth it.

So there it is folks.
Attachments
Configuration for 512H 24Mhz  chip bootloader.jpg
Configuration for 512H 24Mhz chip bootloader.jpg (79.64 KiB) Viewed 7620 times
Configuration for 512L 8Mhz chip bootloader.jpg
Configuration for 512L 8Mhz chip bootloader.jpg (79.31 KiB) Viewed 7620 times
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: USB HID Bootloader and USB OTG

#5 Post by filip » 07 Oct 2013 13:04

Hi,

I'm glad that you have managed to sort of this issue, the clocking options can some be a pain. :)

Regards,
Filip.

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: USB HID Bootloader and USB OTG

#6 Post by Rotary_Ed » 07 Oct 2013 16:53

Thanks, fillip

Yes, really need to pay attention to all of the different bus clocks on the PIC32. System bus, Peripheral Bus and USB bus and perhaps others.

I don't know how many times I tried to get it to work (and of course it wouldn't), before I was reading in the oscillator section of the datasheet and the diagram made it very clear that the oscillator freq also had to had 4 MHz input and that making it 4 Mhz for the PPL input was not sufficient.

What is surprising is that the USB_HID bootloader loads my code almost twice as fast as the MikeProSuite programmer does.

Makes a big different in uploading code, so was worth the effort, just wish it did not take so much of my effort to get it right :(
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: Last Gotcha! USB HID Bootloader and USB OTG

#7 Post by Rotary_Ed » 19 Apr 2014 23:48

After some time ( 7 months) of wondering around other areas of the PIC32 - after getting the USB HID bootloader to load my code, I returned to the USB HID bootloader topic today.

Previously, I had manage with some help to get the bootloader to load my code. However, I encounted one odd problem - none of my code's interrupts would work. Well, I had other things I need to get working on, so I left the USB HID bootloader project at that stage only to return to it today.

This is probably pretty elementary to most of you, but must admit, it never occurred to me until today.

Again, the USB bootloader loaded my code successfully and again the interrupts would not work. I figured it must have something to do with the chip's configuration - but what? Where to Look? what parameters to look at? It seem a daunting task.

Then the light bulb came on :!: - I decided to recompile the Mikro bootloader code with the same/identical scheme (configuration file you find with the Project Editor)file that I configure my PIC32 project with. That's all it took. The code bootloaded successfully and all of the interrupts now work. :D

Thought I would mention it - in case anyone else runs into a similar problem.

Best Regards
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Re: USB HID Bootloader and USB OTG

#8 Post by JimKueneman » 06 May 2014 14:05

Rotary Ed,

With the big sale on compilers I think I have found the push I need to move to the PIC32. Is the boot loader code yours or is it a mE library?

Jim

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: USB HID Bootloader and USB OTG

#9 Post by Rotary_Ed » 06 May 2014 14:48

Hi Jim,

Yes, hard to believe that I had one of the first(if not the first version) Pascal compiler the MK team produced. It was rather rudimentary and I had to write 12 procedures in assembly to get it to do all I wanted it to, but, boy have they come a long ways since then :D !

Good time to purchase one of their compilers with the current sale underway.

To answer you question - the USB HID Bootloader is MK developed - you can find it on the compiler under the tool menu or in the tools folder of the compiler. The bootload code for your chip is located in one of the example folders of the compiler as well.

The only thing I had to change with the bootload code (actually the compiler setting) and then recompile - was the Freq parameter(the default is 80 MHz and I use 64Mhz) and (at least for me) to compile the bootload code with the same configuration as your project(you can find configurations under the Project/Edit Project menu and then "Load scheme" will show you several configuration schemes). I have my own configuration to meet my project needs and then I save my "Scheme" to the Scheme folder so I always have and can load my own configuration as needed.

I must say the USB HID bootloader is terrific!! :!: I loads my 130K of code in approx. 8 seconds. When I used the older Rs232 UART bootloader it took 8 minutes to load the same amount of code. In fact, it faster than my Mk ProSuite programmer - so that I am now using the bootloader to load my code because its several times faster.

Best Regards
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Re: USB HID Bootloader and USB OTG

#10 Post by JimKueneman » 10 May 2014 14:41

Rotory_Ed,

Took the plunge, ordered the compiler and the PIC32 board for the Fusion 7. Can't wait to have Ethernet built in, the Microchip Ethernet interface chips have been nothing but a trouble. When I moved from the external CAN controller to the internal CAN module on the dsPIC life became good, moving to the internal Ethernet module I am hoping life becomes awesome.....

I am sure I will become a pest to you very shortly :D

Jim

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: USB HID Bootloader and USB OTG

#11 Post by Rotary_Ed » 10 May 2014 16:59

Glad to help where I can, Jim

Although with your experience with 16 bit chips, the 32 bit may not be as large a step as from 8 bit.

Yes, I added an USB chip to my 18F6772 board, finally got it to work, but I was disappointed in that it was no faster than the Usart ports of the 18F6772. Uploading with the Rs232 link took me 8 minutes and with the USB chip it also took 8 minutes - so I moved on.

I find the OTG USB on the PIC32MX795F512H works as advertised. My bootloaded code now loads in 8 seconds!!!! using the MK USB HID bootloader tool.

I have managed to read the directories of a thumbwheel flash drive based on some code I found, but have not gotten any further at the moment.

So have fun with your new board and compiler!!
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Re: USB HID Bootloader and USB OTG

#12 Post by JimKueneman » 14 May 2014 13:56

Had some time to look at the PIC32 data sheet. Well of course my libraries for CAN, etc are mostly of little use as is. It is not as far a jump from the 8 bit parts but MicroChip thought they needed to "improve" things a bit more in most of the peripherals I use. It will be a slow transition.

Jim

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: USB HID Bootloader and USB OTG

#13 Post by Rotary_Ed » 14 May 2014 14:24

Sorry to hear that, Jim

From what I had seen on some of the forums, it appeared that some modules are little changed from the 16bchips, but clearly a number have been. Well, hope the change brings improvement in performance or ease of use.

Yeah, I had to completely restructure all of my 8 interrupt handlers code which took weeks because of the compiler optimizing out the variable I used to empty the interrupt modules buffer. So my code would never return from an interrupt.

Ah, the joys of progress.

Good luck, Jim
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Post Reply

Return to “mikroPascal PRO for PIC32 General”