Author Topic: Questions on USB protocol  (Read 7061 times)

0 Members and 1 Guest are viewing this topic.

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 823
  • Country: es
Re: Questions on USB protocol
« Reply #25 on: October 18, 2021, 10:26:08 am »
> How do I locate the SOFs or microframe boundaries
You need to tick the "Show/Hide SOFs" button. Switching the grouping to "Group transactions" also helps to see lower level details. See the screenshot.
 
The following users thanked this post: promach

Offline promachTopic starter

  • Frequent Contributor
  • **
  • Posts: 875
  • Country: us
Re: Questions on USB protocol
« Reply #26 on: October 18, 2021, 10:49:27 am »
Thanks for the tips on Ellisys USB analyzer software.

May I know if it is possible at all to automatically export/transform the series tabular information about the USB transactions into parallel waveform signals for easier visual observation ?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #27 on: October 18, 2021, 02:21:59 pm »
Quote
DATA stage of the control transfer would always start with DATA1, and setup stage with DATA0.
According to https://www.beyondlogic.org/usbnutshell/usb3.shtml#USBPacketTypes , it seems that setup token packet is used to begin control transfers, and your quoted sentence above contradicts with the specification ?
SETUP token is used to start the control transfer, but the token itself does not carry any data. Control transfer has setup and data stages. Setup stage is the SETUP+DATA0+ACK tokens/packets. Then the data stage is zero or more DATAx packets. This sequence would start with DATA1.

All this is shown in the section of the standard I mentioned earlier.

The terminology of USB is very confusing and in casual conversation is not easy to always get right without a lot of additional words. You have to read the standard to understand what all those terms mean and how they all relate.
« Last Edit: October 18, 2021, 02:27:39 pm by ataradov »
Alex
 
The following users thanked this post: promach

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #28 on: October 18, 2021, 02:25:42 pm »
May I know if it is possible at all to automatically export/transform the series tabular information about the USB transactions into parallel waveform signals for easier visual observation ?
You mean export into something like your logic analyzer traces? I don't think it is possible with any of those tools. It is not easier. Once you start looking at high level protocols, that logic analyzer view will turn into a complete mess.

The way USB analyzers represent things today is not bad for practical uses.
Alex
 

Offline promachTopic starter

  • Frequent Contributor
  • **
  • Posts: 875
  • Country: us
Re: Questions on USB protocol
« Reply #29 on: October 18, 2021, 02:30:15 pm »
I already checked section 8.6 , but where did you locate This sequence would start with DATA1. exactly ?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #30 on: October 18, 2021, 02:39:20 pm »
There is a picture in the section 8.6.1 "Initialization via SETUP Token". And in the followup pictures.

With words and even more pictures it is explained in details in the section 8.5.3 "Control Transfers".

Also, it looks like the status stage (last stage in the transfer) always uses DATA1 regardless of the state of the toggle bit:
Quote
A Status stage is delineated by a change in direction of data flow from the previous stage and always uses a DATA1 PID. If, for example, the Data stage consists of OUTs, the status is a single IN transaction. If the control sequence has no Data stage, then it consists of a Setup stage followed by a Status stage consisting of an IN transaction.

I this is actually makes it consistent with regular (non-control IN/OUT) endpoints.
« Last Edit: October 18, 2021, 02:43:23 pm by ataradov »
Alex
 
The following users thanked this post: promach

Offline promachTopic starter

  • Frequent Contributor
  • **
  • Posts: 875
  • Country: us
Re: Questions on USB protocol
« Reply #31 on: October 22, 2021, 03:18:36 am »
How is USB_REQUEST_PAYLOAD_DATA inside setup stage different from PAYLOAD_DATA inside data stage ?

 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #32 on: October 22, 2021, 04:24:00 am »
Yes, it is different. SETUP stage has a fixed format that contains a request type. This part is always 8 bytes in size. This for example can be a string descriptor request that includes the string index. The data stage is the actual data that was requested - in this example the string value. This part is variable in length (including 0 bytes). This part can also span multiple frames. Maximum control endpoint transfer size is 64 bytes, and device descriptors for complex device can easily be bigger than this.

Format of the setup stage request is this:

  uint8_t   bmRequestType;
  uint8_t   bRequest;
  uint16_t  wValue;
  uint16_t  wIndex;
  uint16_t  wLength;

You will see it everywhere, as this is the first thing you face when dealing with USB on a software level.
« Last Edit: October 22, 2021, 04:27:50 am by ataradov »
Alex
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: Questions on USB protocol
« Reply #33 on: October 22, 2021, 04:38:40 am »
How is USB_REQUEST_PAYLOAD_DATA inside setup stage different from PAYLOAD_DATA inside data stage ?



Read more of that document ;)

SETUP packets are used in control transactions on Endpoint 0. It's how USB requests are sent from the host to the device. A SETUP transfer might be able to send all of the necessary information for the control transfer in the 8-byte payload for the SETUP.  If necessary then more data can be sent in a DATA state for the SETUP transfer.

The other endpoints don't have a SETUP stage, but they do have DATA packets.

In the end, what happens is that your micro gets an interrupt saying "you have data" and you have to figure out what endpoint interrupted you so you know what to do with your data.
 
The following users thanked this post: promach

Offline promachTopic starter

  • Frequent Contributor
  • **
  • Posts: 875
  • Country: us
Re: Questions on USB protocol
« Reply #34 on: October 22, 2021, 08:22:25 am »
In section 5.9.2 High Bandwidth Isochronous Endpoints , what does it exactly mean by the sentence: For isochronous transactions, if an IN endpoint provides less than a maximum data payload as specified by its endpoint descriptor, the host must not issue further transactions for that endpoint for that microframe. ?

The first part of the sentence seems to contradict with the later part of the sentence ?
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 823
  • Country: es
Re: Questions on USB protocol
« Reply #35 on: October 22, 2021, 09:10:58 am »
Each EP has a maximum packet size (advertised in config descriptor, so host knows it). If in response to an IN token the device sends less than that maximum - it indicates to host that device has no more data ready to send right now. Looks logical - if you have more data than MaxPacketSize - send the maximum, and if you are sending less than maximum - you have less than maximum and it is useless to ask you to send more immediately, see you in the next frame.

The same mechanism is used on bulk endpoints to indicate end of transfer - the last packet is either short (less than EP.MaxPacketSize) or a ZLP (zero-lenght packet) if the total transfer size is a multiple of MaxPacketSize.
 
The following users thanked this post: promach

Offline promachTopic starter

  • Frequent Contributor
  • **
  • Posts: 875
  • Country: us
Re: Questions on USB protocol
« Reply #36 on: October 22, 2021, 11:31:07 am »
May I know why isochronous OUT endpoint is using MDATA instead of DATA2 and DATA1 ?



 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #37 on: October 22, 2021, 03:36:00 pm »
For the IN transfer the first packet indicates how many more to follow. If the host receives DATA2, it knows it has to issue two more IN tokens.

For the OUT transfers DATAx indicates end of transfer. The device must count how many MDATA packets were received to check the whole transaction.

This is basically due to asymmetrical nature of the USB - host always drives the communication.
Alex
 
The following users thanked this post: promach

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 823
  • Country: es
Re: Questions on USB protocol
« Reply #38 on: October 22, 2021, 04:02:36 pm »
But why OUT is not the same principle as for IN (DATA2, DATA1, DATA0) ?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #39 on: October 22, 2021, 04:31:31 pm »
Because now if device receives DATA2 right away it will discard that packet, since there were no 2 MDATA packets before that, so the whole transaction is invalid.

If you start with DATA2, you will not have this control.

The goal here is to ensure that all 3 packets are received, and if one is missing, then the remaining should be discarded too.

In both cases highest DATAx indicates how many packets were supposed to be in the transfer.
« Last Edit: October 22, 2021, 04:33:20 pm by ataradov »
Alex
 
The following users thanked this post: abyrvalg

Offline promachTopic starter

  • Frequent Contributor
  • **
  • Posts: 875
  • Country: us
Re: Questions on USB protocol
« Reply #40 on: October 22, 2021, 04:37:35 pm »
but there is no way to determine which of the two MDATA transactions was lost
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #41 on: October 22, 2021, 04:39:26 pm »
but there is no way to determine which of the two MDATA transactions was lost
It does not matter. It is isochronous transfer - if things are lost, they are lost. There is no retry mechanism anyway, so knowing what specifically is lost would not help.

The goal is to lose the whole transaction and not just one packet, as higher level protocols may rely on that property. But those protocols would be tolerant to the loss of the whole transaction.
« Last Edit: October 22, 2021, 04:41:58 pm by ataradov »
Alex
 

Offline promachTopic starter

  • Frequent Contributor
  • **
  • Posts: 875
  • Country: us
Re: Questions on USB protocol
« Reply #42 on: October 22, 2021, 04:46:40 pm »
it does not make sense to lose the whole transaction
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #43 on: October 22, 2021, 05:01:29 pm »
It does. Higher level protocols rely on that. They may put a single video frame header in the first packet and raw frame data in the rest of them. If you lose the first one your whole protocol will be de-synchronized. If you lose all 3, then all you've lost is a single frame of video. This is just a very trivial example where losing the whole thing is better than losing just one part.

People that designed USB are not stupid, they knew what they were doing. So a better approach is to try to understand why something was done one way or the other instead of criticizing it.
Alex
 
The following users thanked this post: Bassman59, promach

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: Questions on USB protocol
« Reply #44 on: October 22, 2021, 07:22:52 pm »
it does not make sense to lose the whole transaction

If your system design allows for it, you can use bulk or interrupt transfers instead of isochronous. Those two transfers allow for retries in the event that those host "loses" something.

Although I don't know what would cause the host to lose data in a way it can manage. USB uses a host-to-device direct connection (maybe a hub in between) and the host "knows" what bandwidth is available. It won't allow transfers if it can't handle them. The usual failure mode is a bad cable, and no protocol overhead in the world can work around that.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14297
  • Country: fr
Re: Questions on USB protocol
« Reply #45 on: October 22, 2021, 07:38:21 pm »
Yes. As a note, do NOT use isochronous transfers unless you really really really... have to. They're usually a waste of bandwidth and as said above, there is no guarantee of data delivery.

A number of "streaming"-like applications can successfully use bulk transfers as long as you buffer data properly.
 

Offline promachTopic starter

  • Frequent Contributor
  • **
  • Posts: 875
  • Country: us
Re: Questions on USB protocol
« Reply #46 on: October 28, 2021, 01:26:11 pm »
Why do we need BMC codec ?

I tried to read USB PD 3.0 new BMC decoding circuit article, but I am getting more confused.

 

Online voltsandjolts

  • Supporter
  • ****
  • Posts: 2277
  • Country: gb
Re: Questions on USB protocol
« Reply #47 on: October 28, 2021, 01:38:06 pm »
Well, part of the answer is in the picture you just posted.
What would you prefer for fast serial transfer with clock recovery?
 
The following users thanked this post: promach

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Questions on USB protocol
« Reply #48 on: October 28, 2021, 04:06:48 pm »
Clock recovery is the primary goal. For reliable communication at fast speeds you either need a separate clock or a highly accurate clock source on both sides. Or you can use protocol with encoding that allows for clock recovery.

Manchester code is one of the earlier examples of such encoding. Even in regular USB communication you see bit stuffing (prevention of long runs of 1s or 0s), which lets devices recover the bit timing.

PD is oriented at low cost implementations, so Manchester code is a good idea.
« Last Edit: October 28, 2021, 04:22:05 pm by ataradov »
Alex
 
The following users thanked this post: promach

Offline asmi

  • Super Contributor
  • ***
  • Posts: 2728
  • Country: ca
Re: Questions on USB protocol
« Reply #49 on: October 28, 2021, 04:12:25 pm »
Yes. As a note, do NOT use isochronous transfers unless you really really really... have to. They're usually a waste of bandwidth and as said above, there is no guarantee of data delivery.
Actually pretty much all applications which need to work with real-time data will have to deal with situation when there is a snag with input data delivery for whatever reason. And buffering is not always an option - for example if latency is critical. Isochronous transfers guarantee bandwidth allocation as they are always executed first in the (micro-)frame.

A number of "streaming"-like applications can successfully use bulk transfers as long as you buffer data properly.
Like I said above, buffering is not always an option. And it's not that hard to use isochronous transfers, but you will have to understand how it works. Like the video example above, in many cases you can interpolate or just guess what missing data was, and design your application around that.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf