Quantcast

usb_bulk_read returns with uncompleted read

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

usb_bulk_read returns with uncompleted read

Ekkehard
Hello,
I try to read from an bulk endpoint with usb_bulk_read. I want to read a big buffer (e.g. 256KByte) in once, but the function returns immediatly with a positive return value, but less then given buffer size. I can see, that the buffer is only partly filled.
If I use my cypress usb testkit, the function waits until the buffer is filled and returns the full length or -116 for timeout.
Also an alternative loop with usb_submit_async .. usb_reap_async dont work because the very short truncs of data does not allow a continously read.
Any idea where to search?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: usb_bulk_read returns with uncompleted read

Travis
On 12/2/2011 9:57 AM, Ekkehard wrote:
> Hello,
> I try to read from an bulk endpoint with usb_bulk_read. I want to read a big
> buffer (e.g. 256KByte) in once, but the function returns immediatly with a
> positive return value, but less then given buffer size. I can see, that the
> buffer is only partly filled.

usb_bulk_read() will always return when the device returns a short
packet.  This is expected.

libusbK has an IGNORE_SHORT_PACKETS pipe policy that works well for
this.  Functionality could be further enhanced with the stream API.

> If I use my cypress usb testkit, the function waits until the buffer is
> filled and returns the full length or -116 for timeout.

If your device is returning short packets then somewhere the cypress
codes are submitting multiple or re-submitting transfer URBs to make
this work;  similar to what you would do with the libusb-win32 async api.

> Also an alternative loop with usb_submit_async .. usb_reap_async dont work
> because the very short truncs of data does not allow a continously read.
> Any idea where to search?
>
>

I think you could create your own pipe thread and use the libusb-win32
async api to keep several request pending at once.  As the small
transfers complete, copy them into your "big buffer" and re-submit
them.  As the big buffer(s) fill up, signal a big buffer(s) ready
event/semaphore. This is more work but performance should be as high as
possible.

Regards,
Travis

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Libusb-win32-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: usb_bulk_read returns with uncompleted read

Ekkehard
> libusbK has an IGNORE_SHORT_PACKETS pipe policy that works well for
> this.  Functionality could be further enhanced with the stream API.

I will give this a try tomorrow.

> I think you could create your own pipe thread and use the libusb-win32
> async api to keep several request pending at once.  As the small
> transfers complete, copy them into your "big buffer" and re-submit
> them.

Unfortunally this does not work, since the packets are so short (sometimes <600 Bytes) that even a queue of 128 pending reads are not enough to prevent gaps in the reception.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: usb_bulk_read returns with uncompleted read

Ekkehard
I have activated the IGNORE_SHORT_PACKETS pipe policy and the received data now have the requested size. Unfortunally the received data are still corrupted, so I have to returne to the isochronous mode where such data losses not occour.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: usb_bulk_read returns with uncompleted read

Travis
On 12/3/2011 3:39 AM, Ekkehard wrote:
> I have activated the IGNORE_SHORT_PACKETS pipe policy and the received data
> now have the requested size. Unfortunally the received data are still
> corrupted, so I have to returne to the isochronous mode where such data
> losses not occour.

I don't understand why the data corruption occurs.  Did you change your
wMaxPacketSize to 512b?

If your are using the libusbK APIs for the bulk test, then you can
switch the driver to WinUSB.
If your are *not* using the libusbK dynamic driver api then you must
also change the "UsbK_" prefixed calls to "WinUsb_"
I expect the results will be the same, but if there is a problem in the
libusbK.sys driver, this would tell us.

Of-course, WinUSB does not support isochronous endpoints so it would not
work with any of the libusbK ISO specific calls.

Regards,
Travis

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Libusb-win32-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: usb_bulk_read returns with uncompleted read

Ekkehard
I expect that the device I am using, causes the trouble. Probably the bulk mode is not implemented in a way that support continous flow of data. Since everything runs fine with my alternative cypress test kit, I am sure that everything is fine with your library.

I am unsure what you mean with "libusbK dynamic driver api".
Your dll exports a lot of functions starting with UsbK_ which seems than to be also available via the KUSB_DRIVER_API struct returned by LibK_LoadDriverAPI.
I use only the direct functions exposed by the dll and not the functiones in the driver api struct.
And I have removed every call to the original libusb0 dll.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: usb_bulk_read returns with uncompleted read

Travis
On 12/4/2011 3:07 AM, Ekkehard wrote:
> I expect that the device I am using, causes the trouble. Probably the bulk
> mode is not implemented in a way that support continous flow of data. Since
> everything runs fine with my alternative cypress test kit, I am sure that
> everything is fine with your library.
>

I see.
I was unable to get my cheap cypress dev board to burn programs:
http://www.cutedigi.com/product_info.php?products_id=4515
I was hoping to run some of your codes, but it doesn't look like that
will be possible.

> I am unsure what you mean with "libusbK dynamic driver api".
> Your dll exports a lot of functions starting with UsbK_ which seems than to
> be also available via the KUSB_DRIVER_API struct returned by
> LibK_LoadDriverAPI.

That is the dynamic driver api. ;)  It is a structure of function
pointers populated by LibK_LoadDriverAPI.  It allows a code base to
support libusbK.sys, libusb0.sys, WinUSB, and future driver APIs.

> I use only the direct functions exposed by the dll and not the functiones in
> the driver api struct.

In your case, the advanced ISO functionality is only supported by
libusbK so there is little advantage.
I have many examples using these functions, but they would not be much
help for a Delphi programmer. ;)

> And I have removed every call to the original libusb0 dll.
>

Nice. :)

Regards,
Travis


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Libusb-win32-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: usb_bulk_read returns with uncompleted read

Xiaofan Chen
On Sun, Dec 4, 2011 at 9:25 PM, Travis <[hidden email]> wrote:
> I was unable to get my cheap cypress dev board to burn programs:
> http://www.cutedigi.com/product_info.php?products_id=4515
> I was hoping to run some of your codes, but it doesn't look like that
> will be possible.

Hmm, that is rather strange. If Cypress' utility fails, you can
try cycfx2prog which works with libusb-win32.
http://www.triplespark.net/elec/periph/USB-FX2/software/

--
Xiaofan

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Libusb-win32-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: usb_bulk_read returns with uncompleted read

Travis
On 12/4/2011 6:35 AM, Xiaofan Chen wrote:
> On Sun, Dec 4, 2011 at 9:25 PM, Travis<[hidden email]>  wrote:
>> I was unable to get my cheap cypress dev board to burn programs:
>> http://www.cutedigi.com/product_info.php?products_id=4515
>> I was hoping to run some of your codes, but it doesn't look like that
>> will be possible.
> Hmm, that is rather strange. If Cypress' utility fails, you can
> try cycfx2prog which works with libusb-win32.
> http://www.triplespark.net/elec/periph/USB-FX2/software/
>

I was missing the x64 win7 drivers and in the midst of all the plugging
and unplugging my host controller malfunctioned. After rebooting and
installing the newest cypress usb suite it began to work as expected.

Before I had it working with the cypress driver, I used libusb-win32
1.2.5.0 with fxload for windows like so:
fxload-libusb.exe -s Vend_Ax_Eeprom.hex -c 0xC2 -t fx2 -I .\bulksrc.hex
http://wiki.epfl.ch/cfavi/fxload-libusb
After that, the board came to life for the first time and there as hope!

Later today, I will adapt the CYStream firmware and post some results.

Regards,
Travis


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Libusb-win32-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
Loading...