Author Topic: Multi data packet in Data Stage (control transfers)  (Read 10590 times)

gikubik

  • Member
  • ***
  • Posts: 8
Multi data packet in Data Stage (control transfers)
« on: September 20, 2013, 06:56:14 am »
Hello from Spain,

I have a small doubt about control transfers. Maybe you think I should read more carefully the USB specs but unfortunately my English is not always good enough to understand everything in those technnical documents so I decided to ask for help here. Sorry in advanced if my doubt is too much easy.

I'm developing a USB device with a PIC (USB 2.0 compatible). By now I only need to transfer up to 33 bytes to the host so using Full Speed I suppose I will be able to send this information as a reply from a vendor request (with max_packet_size=64) using a control transfer. These are my plans (I hope to be right!). My questions:

1) The host will see a packet with up to 33 bytes and automatically will understand there are no more data packets within the data stage? (I mean, because max_packet_size is 64) or I have to indicate that nothing else is coming some way?

2) Let's imagine I need to exchange (in any direction) 64 bytes exactly. In this case the host/device can have the doubt about if there's still more data to arrive. Is there any special process to signal that no more that is coming?

3) Finally, let's imagine I need to exchange (in any direction) more than 64 bytes. First data packet will have of course 64 bytes, next packets 64 or less. Again, how the host/device know more than one packet are coming and wich is the last one?

Thanks!
Xavi

sudheerg_

  • Member
  • ***
  • Posts: 18
Re: Multi data packet in Data Stage (control transfers)
« Reply #1 on: September 20, 2013, 07:38:13 am »
Hello Xavi,

In case of control transfers the length of data that is requested by host can be specified in wLength field. Please see the following URL:http://www.beyondlogic.org/usbnutshell/usb6.shtml

The device shall not send data more than host has requested.

1. In first case if endpoint zero supports 64-bytes is maximum packet length that it can support, if the host has requested for 64 and the device responds with 33 bytes then the host assumes there won't be any more data from device.

2. If you send exactly 64-Bytes then the device has respond with Zero Packet length for the next packet.

3. First you have to tell what is the Maximum packet length that can be transferred from EP0 in Get Device Descriptor response. Then host driver knows what is the maximum EP0 packet that can be sent by device. Say for example if your device EP0 maximum packet length is 8-bytes, if your host need to get 9-bytes configuration descriptor then it will send two IN tokens to get the configuration descriptor.

Hope you understand what I am saying.

Thank You & Regards,
GSR

gikubik

  • Member
  • ***
  • Posts: 8
Re: Multi data packet in Data Stage (control transfers)
« Reply #2 on: September 20, 2013, 10:56:43 am »
I understood you perfectly!

As you see I had a wrong idea about the process. Now it's really clear.

I'm really grateful! Thank you very much!
Xavi

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: Multi data packet in Data Stage (control transfers)
« Reply #3 on: September 20, 2013, 04:48:21 pm »
Control transfers are special because the transfer size is known ahead of the transfer. The transfer size is specified in wLen of the setup packet. So the host and device know more about them than usual.

For transfers in general, the host will think a transfer is over when the request is exactly satisfied, or a short packet is received. (A short packet is a packet size less than the max packet size.) (It is also an error to send more data than the host is expecting.)

For case 1, the request is exactly satisfied and there is a short packet. So either way, the transfer is over.

For case 2, for a setup transaction, if 64 bytes was asked for, the request will be exactly satisfied, so the transfer will be over after the first packet. If more than 64 bytes was asked for, the device needs to send a short packet. As its already sent all the data it has, it can send a zero length packet. A zero length packet is always an end of transfer and doesn't add to the data transferred.

For case 3, once the device sends a packet less than max packet size, the transfer is over.


As a further note, I said its an error for the device to send more than the host is expecting. In general (apart from setup transactions), the device doesn't know how many bytes the host is expecting. A smart host will alway expect data in multiples of maxpacket. That way it will always get the data the device sends, even if its more than it really wants. Not all hosts are smart, and the device can not worry about whether the host is smart of not, the device should just do what its told.