PIC24F USB help - Page 1
Forum section: electronics / general

author: golf32
author_rank: Regular Contributor
timestamp: July 25, 2022, 12:10:45 am
content: 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.

author: woofy
author_rank: Frequent Contributor
timestamp: July 25, 2022, 11:06:53 am
content: 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.cIts 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.

author: voltsandjolts
author_rank: Unknown
timestamp: July 25, 2022, 11:58:00 am
content: Agree with Woofy.If for some reason you don't like the microchip code, you can tryM-Stackwhich is also Apache licensed and is more readable IMHO. It has a CDC example.Does the OP have a VW Golf R32

author: JPortici
author_rank: Super Contributor
timestamp: July 25, 2022, 09:17:51 pm
content: 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 MLAman how i dislike MCCWhat 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 datasheetAnother 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.

author: golf32
author_rank: Regular Contributor
timestamp: July 26, 2022, 12:48:52 am
content: Quote from: woofy on July 25, 2022, 11:06:53 amI tried that, same issues as what I described.Quote from: voltsandjolts on July 25, 2022, 11:58:00 amI'll give that library a try. No VW, sorry. Can't remember the origin of my username.Quote from: JPortici on July 25, 2022, 09:17:51 pmI 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.

author: golf32
author_rank: Regular Contributor
timestamp: July 26, 2022, 03:41:53 am
content: 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.

author: voltsandjolts
author_rank: Unknown
timestamp: July 26, 2022, 08:05:05 am
content: Hmm, you should only need the one USB connection of course, maybe check power routing on your boardIf 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 thismight help.

author: golf32
author_rank: Regular Contributor
timestamp: July 26, 2022, 04:45:58 pm
content: Well I would think that too, but I'm using a microchip dev board. The curiosity board with the same chip.

author: voltsandjolts
author_rank: Unknown
timestamp: July 26, 2022, 08:14:57 pm
content: 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

author: golf32
author_rank: Regular Contributor
timestamp: July 26, 2022, 08:48:50 pm
content: 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(?).

author: IDEngineer
author_rank: Super Contributor
timestamp: July 30, 2022, 05:00:20 am
content: 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).