View previous topic :: View next topic |
Author |
Message |
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
CDC USB SPEED |
Posted: Mon Oct 19, 2009 12:08 pm |
|
|
Hi all!
I am using the ex_usb_serial example and modified it to receive streaming data from the PC.
Code: |
while (TRUE) {
usb_task();
usb_debug_task();
if (usb_cdc_kbhit()){
c=usb_cdc_getc();
}
}
|
With this way I am waiting for a byte to be sent by the pc and then read it.
From the pc side there is a visual basic program which opens a file in binary mode and sends it byte by byte to the CDC serial port.
All this is working but it takes about 100 seconds for a 100KB file.
Maybe I got this all wrong? Is usb_cdc_kbhit() and usb_cdc_getc() supposed to be only for characters and not for streaming bytes?
In the "usb_desk_cdc.h" file it says:
==============================
Version History:
10/28/05:
Bulk endpoint sizes updated to allow more than 255 byte
packets.
Changed device to USB 1.10
==============================
Finally is this USB 1.1 or USB 2? How can I be sure about the speed?
Any help appreciated. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Oct 19, 2009 12:46 pm |
|
|
Quote: | Is usb_cdc_kbhit() and usb_cdc_getc() supposed to be only for characters and not for streaming bytes? | Yes, I think so. View the code for usb_cdc_putc() to understand why. Or trace the cdc driver operation with an USB software monitor. Because usb_cdc_putc() calls usb_cdc_flush_out_buffer(), the characters are sent one-by-one.
To increase the throughput, the send buffer must be completely filled before flushing it. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Mon Oct 19, 2009 1:03 pm |
|
|
thanks for that! I see what you mean..
So, how can I fill the buffer before sending it? Add the bytes on a long string? and how long can this be?
Is there some other method that is more suitable for this job?
Keep in mind that I want to send data from the pc to the pic at higher speed and not the opposite.
I just saw "usb_put_packet" command but I cannot find any documentaion.
Please help. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Oct 19, 2009 2:37 pm |
|
|
Basically you can add data to usb_cdc_put_buffer without flushing it, as long there's still room. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Mon Oct 19, 2009 2:55 pm |
|
|
Thank you for the support.
Can you please show me an example of how to receive streaming data with usb_get_packet? Where is the packet stored? In some type of variable int8[10] or something?
What do you mean flushing?
Is usb_get_packet supposed to work with cdc?
I guess that I have it correct from the pc side. I will keep sending a stream of bytes over the virtual com port.
Finally what is the best method to send large files to my pic at full speed?
CDC? HID? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Oct 19, 2009 4:11 pm |
|
|
I don't think, that usb_get_packet() can be used with cdc, or at least not easily. There should be no throughput problem with usb_cdc_getc(). I know, that cdc can be used near to the maximum USB full speed throughput, but I didn't yet try with the CCS cdc driver.
Also HID performance isn't worse. Both are often preferred, because they use built-in drivers at the PC side, HID even without any *.inf file for installation. But a user bulk mode driver can further reduce the overhead on the PC side. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Tue Oct 20, 2009 9:41 am |
|
|
Thanks for the help FvM.
So is there anyone who can help me send a file to the PIC at full speed? |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Tue Oct 20, 2009 11:26 am |
|
|
georpo:
What exactly are you working on? USB-CDC isn't really great for fast communications. As mentioned by FvM, raw bulk mode is faster. The CDC class uses bulk mode, but it carries with it a lot of overheads. This apart, I have found that CDC causes several different terminal programs to sometimes gag. Even a GUI written in VB hung when the CDC data rate was increased.
I've written a simple program which uses raw bulk mode. It's based on the oscope demo provided in the CCS examples folder. I haven't measured exactly, but the raw mode certainly allows for much higher transport speeds, and this increase is viewable 'visually' through my GUI (don't really know how accurate this is - I don't know absolute speeds, but relative to CDC, the raw mode is about 5-6 times faster).
My GUI was first written in VB, and later in LabVIEW. I'm willing to share test implementations of both, the CCS code and the LabVIEW vi. Send me a private message with your email if you'd like them.
Rohit |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Wed Oct 21, 2009 8:03 am |
|
|
Well, here is what I have:
I want to send wav files to my pic board through USB. so, I used the ex_usb_serial example to receive data.
From the PC side I have a VB program which reads the file and sends it to the USB with the CDC virtual com port using the mscomm control.
Yesterday I tried to first fill a byte array with 512 bytes and then send this array to the CDC port. This speeds up things a lot. Now, I can transfer 5MBytes in about 45 seconds but this is still too slow for full 12Mbps speed . Right?
I am afraid that this :c=usb_cdc_getc(); gives me the bytes one by one because it is supposed to receive characters and not sreaming data but I am not sure.
As about bulk mode I am not really an expert in USB actually this is the first time I try this and I can definitely not write a USB driver or something like that for the PC. I have to stick with the working examples of CDC.
If you have a better idea please share with me.
p.s (is 512 bytes the right buffer size for CDC?)
Many thanks to everybody!
[email protected] |
|
|
|