cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with CDC USB lenght of sent string == 64 128 ...

antonio239955
Associate II
Posted on February 20, 2011 at 20:52

Trouble with CDC USB lenght of sent string == 64 128 ...

4 REPLIES 4
Fleck
Associate II
Posted on May 17, 2011 at 14:25

I'm not a USB expert, but from what I understood this is happening here:

USB Bulk Transport (which the CDC example uses) uses the following mechanism to determine when a ''bulk'' of data is complete:

When a ''short packet'', i.e. a packet containing less bytes than the max. endpoint size, is received, the Windows CDC driver (usbser.sys) considers the transfer complete and sends the data to the application (Hyperterminal or others). Whenever a completely full packet is received (64 Bytes) it expects more data to come and polls the device for more data as fast as it can.

To get the Windows driver to consider the transfer as ''finished'', you need to send a zero-length packet after sending a 64-Byte packet. USB_Sil_Write('''',0);

That is actually specified in the USB specification, chapter 5.8.3:

When a bulk IRP involves more data than can fit in one maximum-sized

data payload, all data payloads are required to be maximum size except for the last data payload, which will

contain the remaining data. A bulk transfer is complete when the endpoint does one of the following:

• Has transferred exactly the amount of data expected

• Transfers a packet with a payload size less than wMaxPacketSize or transfers a zero-length packet

Hope this helps.

Jens

antonio239955
Associate II
Posted on May 17, 2011 at 14:25

tsuneo
Senior
Posted on May 17, 2011 at 14:25

jeans, excellent answer. Just one point to add.

usbser.sys request 4K bytes transfer to PC host controller for bulk IN pipe (*1).

The host controller doesn't report transfer completion to usbser.sys until it gets short packet (including ZLP), or until the requested size is satisfied.

(*1) The request size may change depending on PCI bus configuration. 4K bytes is the page memory size of PCI bus.

Tsuneo

Andrew Neil
Evangelist III
Posted on May 17, 2011 at 14:25

''I really much believe in IAR''

 

So have you actually contacted them about this?

It seems that IARs ''example'' (sic)  code is not always all that it should be:

http://embeddedgurus.com/stack-overflow/2010/08/setting-a-bad-example-part-1/

Unfortuantely, they are not alone in this: 

http://www.8052.com/forumchat/read/181034