Author Topic: PIC24F USB help  (Read 4666 times)

0 Members and 1 Guest are viewing this topic.

Offline golf32Topic starter

  • Regular Contributor
  • *
  • Posts: 54
  • Country: us
PIC24F USB help
« on: July 25, 2022, 12:10:45 am »
I'm trying to get a basic USB CDC serial port working with the PIC24FJ64GU205. I have a PIC24FJ64GU205 curiosity dev board from microchip. I messed around with it for a while and couldn't get it to work. I tried loading the default demo program (https://github.com/microchip-pic-avr-examples/pic24fj64gu205-curiosity-nano-oob/) to no avail, same results as what I previously did.

What happens is that windows detects the device, but the COM port appears and disappears from the device manager randomly, and needless to say I can't talk to it. I've tried several USB cables and I know this one is good. The board knows it's connected to usb, as the LED is solid and not flashing.
 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 512
  • Country: gb
    • Woofys Place
Re: PIC24F USB help
« Reply #1 on: July 25, 2022, 11:06:53 am »
I don't know about that example but USB CDC is very easy to get up and running on a new project by using MCC (Microchip Code Configurator).
In the system Module, make sure you have the USB clock set for 48MHz.
on the USB stack page the only change I make is to include the example code (tick box at the bottom of the page)
Then just ensure you have a call to the example code in the while loop in main.c

Its a simple example that just increments each char and sends it back (so an A becomes a B, etc).
That example can then me hacked into whatever you need.

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 3953
  • Country: gb
Re: PIC24F USB help
« Reply #2 on: July 25, 2022, 11:58:00 am »
Agree with Woofy.

If for some reason you don't like the microchip code, you can try M-Stack which is also Apache licensed and is more readable IMHO. It has a CDC example.

Does the OP have a VW Golf R32  >:D
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3927
  • Country: it
Re: PIC24F USB help
« Reply #3 on: July 25, 2022, 09:17:51 pm »
Or the MLA, but you have to adapt it for the GU which was released after MCC was launched so was never added to the MLA
man how i dislike MCC

What you need to do to use the MLA: there are a couple of include files in which you just have to add the __PIC24FJ_GU__ entry to the chain of ifdefs that include the correct HAL file, then, in case you want to do crystalless usb, copy the ACT oscillator initialization for MCC because it's just not described in the datasheet

Another note, CDC is an abomination, avoid it if you can, the whole thing about USB was so whe would not use com ports anymore. and yet we still do.
 

Offline golf32Topic starter

  • Regular Contributor
  • *
  • Posts: 54
  • Country: us
Re: PIC24F USB help
« Reply #4 on: July 26, 2022, 12:48:52 am »
I don't know about that example but USB CDC is very easy to get up and running on a new project by using MCC (Microchip Code Configurator).
In the system Module, make sure you have the USB clock set for 48MHz.
on the USB stack page the only change I make is to include the example code (tick box at the bottom of the page)
Then just ensure you have a call to the example code in the while loop in main.c

Its a simple example that just increments each char and sends it back (so an A becomes a B, etc).
That example can then me hacked into whatever you need.


I tried that, same issues as what I described.

Agree with Woofy.

If for some reason you don't like the microchip code, you can try M-Stack which is also Apache licensed and is more readable IMHO. It has a CDC example.

Does the OP have a VW Golf R32  >:D

I'll give that library a try. No VW, sorry. Can't remember the origin of my username.

Or the MLA, but you have to adapt it for the GU which was released after MCC was launched so was never added to the MLA
man how i dislike MCC

What you need to do to use the MLA: there are a couple of include files in which you just have to add the __PIC24FJ_GU__ entry to the chain of ifdefs that include the correct HAL file, then, in case you want to do crystalless usb, copy the ACT oscillator initialization for MCC because it's just not described in the datasheet

Another note, CDC is an abomination, avoid it if you can, the whole thing about USB was so whe would not use com ports anymore. and yet we still do.

I got as far as defining a new entry for my chip, but I did not notice that it didn't include the wrong oscillator setup, or maybe I did.

What's a better alternative for generic low-speed data transfer instead of CDC? What makes it so bad?

Thanks all.
 

Offline golf32Topic starter

  • Regular Contributor
  • *
  • Posts: 54
  • Country: us
Re: PIC24F USB help
« Reply #5 on: July 26, 2022, 03:41:53 am »
Well, I just figured it out. If I plug in the debug USB first, and then the target USB, everything works. Both the m-stack and demo program. I can disconnect the debug USB afterwards just fine. I wonder if it's some issue with debug or power.
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 3953
  • Country: gb
Re: PIC24F USB help
« Reply #6 on: July 26, 2022, 08:05:05 am »
Hmm, you should only need the one USB connection of course, maybe check power routing on your board :-//

If your happy using CDC comports, thats fine. But if you want to tryout Windows WinUSB WCID which allows plug-n-play install with true USB communications (i.e. buffer oriented structured comms using WinUSB directly or via libusb) then this might help.
 

Offline golf32Topic starter

  • Regular Contributor
  • *
  • Posts: 54
  • Country: us
Re: PIC24F USB help
« Reply #7 on: July 26, 2022, 04:45:58 pm »
Well I would think that too, but I'm using a microchip dev board. The curiosity board with the same chip.
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 3953
  • Country: gb
Re: PIC24F USB help
« Reply #8 on: July 26, 2022, 08:14:57 pm »
Looks like there is some power muxing shenanigans on that board...so it's likely something to do with that.
I couldn't understand it in 60 seconds so I give up ;D
 

Offline golf32Topic starter

  • Regular Contributor
  • *
  • Posts: 54
  • Country: us
Re: PIC24F USB help
« Reply #9 on: July 26, 2022, 08:48:50 pm »
Yea, it's really strange. You change the power supply voltage by dragging a text file containing a string "CMD=3.3v" into a mass storage device. ATM it's configured for 3.3v, but if I wanted to I could configure for 5v and fry it(?).
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1982
  • Country: us
Re: PIC24F USB help
« Reply #10 on: July 30, 2022, 05:00:20 am »
Slightly related: A few years ago I tried getting the PIC24F USB working with Android's USB. I got it working, but discovered a flaw in the Android code that made disconnects invisible to the Android side. Once you had established a connection, if the cable was unplugged the PIC24F knew about it but Android did not. Worse, there was no way to detect nor clear the error within Android... the file handle remained open and active, and acted as a silent data sink.

I came up with various deadman/timeout schemes but the Android error was pretty effective at defeating every one. It was a very insidious bug. I got the Android group's attention and one of them submitted it as a formal bug report, but he was candid about that part of the code being very low on the priority list. A couple of years later I got a notice that the bug had STILL not been addressed. It may still be broken, I'm not sure.

I'm logging this here in case someone searches on PIC24F USB and runs into this bug. I lost several manweeks chasing it, without a fix, and had it confirmed as a valid Android bug (even had the inside guy send me his proposed fix, which as I recall was just one or two lines of error handling that should have been there in the first place).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->