Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


USB: 64 byte packet read limit = Poor Performance ! But larger size does not work

OSR_Community_UserOSR_Community_User Member Posts: 110,217
I have developed a simple USB device driver that has a Bulk IN and Bulk
Out pipe to communicate with a camera. The driver works fine at this
point, I can send and recieve data over the pipes reliably.

When I first started working on the driver, I noticed that I had
problems reading data from the device in anything other than 64 byte
chunks. So as a temporary fix, I put code in the application to only
read data from the driver in 64 byte chunks.

Now I want to increase this to something that will speed things up. It
seems that no matter what value I use (Other than 64) I get very strange
results. Most of the time I will be able to read almost all of the data
I am expecting, and then when I attempt to make a final read on the
remainer by read never returns.

So for example:

My protocol requires me to do an initial read of 64 bytes, which the
first 4 are the total size of the transfer (And I buffer the other 60
bytes).

So my read sequence is as follows


1. Read 64 bytes, figure out size of the entire transfer (Have to read
entire 64 byte packet, cant just read 4 bytes). Save the 64 byte packet,
being sure to account for the fact that the first 64 bytes of the
transfer have been read already.

2. Loop, reading from the driver in specified 2048 byte chunks until
there is less than 2048 bytes left to read. This leftover is
pre-computed and is the remainder.

3. Read the remainder bytes (< 2048).


Now -

When I read the remainer, I never complete the read. My driver sends the
URB down to the bus driver, and it never gets back.


If I apply the above algorithm, but use 64 byte chunks instead of 2048
byte chunks it works perfectly.

Any Ideas ??


Also
Are there any tools that I can run on the host to really take a good
close look at what is going on with my IN pipe, and what my device is
sending me and what the Microsoft USBDI is doing with my requests ! I'd
really like to be able to do the math as to what I think I should be
reading, what I have read so far and what the USB device has send me so
far for a given I/O transaction.

Thanks in advance !

-chris
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 26 Feb - 1 Mar 2024 Live, Online