0
\$\begingroup\$

I was reading on how USB hubs work and since there is only 1 master, master sends a command to an endpoint. However, how does a USB hub work when there are 2 same devices plugged into a USB hub? How does the device know which is being addressed?

\$\endgroup\$
1
  • \$\begingroup\$ First come, first identity springs to mind \$\endgroup\$
    – Solar Mike
    Jun 15 '18 at 15:47
1
\$\begingroup\$

USB has a process called “enumeration” where each device, including hubs, is assigned an 7-bit number used to identify it to the host. When a hub is attached, it is enumerated and then each device downstream is enumerated.

This is the reason that no more than 127 devices may be attached at any time.

Therefore, each of your identical devices receives a different number. Which one gets what number depends on the order they are enumerated.

If you need to programmatically tell the difference, you must use the devices’ serial numbers, if they have them.

\$\endgroup\$
2
\$\begingroup\$

You can distinguish them by the port they are connected to, otherwise they will appear identical. The way we distinguish between two devices is with a serial number in the embedded software, if the embedded software has no distinguishing fields you can read, then you can only distinguish them by port.

Reading the port is dependent on the software of the operating system you are using.

\$\endgroup\$
4
  • \$\begingroup\$ By port do you mean the port on the USB hub? I thought the USB hub was transparent \$\endgroup\$
    – loader
    Jun 15 '18 at 16:58
  • \$\begingroup\$ When you load the driver it should be able to detect it, see this: stackoverflow.com/questions/6416931/… \$\endgroup\$
    – Voltage Spike
    Jun 15 '18 at 18:36
  • \$\begingroup\$ @loader, no, USB hub is not "transparent" to the degree you think. Each hub has an individual address, and every enumerated hub has status pipe that report status of every port within that hub. Host can selectively suspend any hub's port, can individually reset them and re-enumerate the connected device, and can/must monitor disconnect and connect status. And HS transaction translators operate on individual hub ports as well. So there is precise addressability based each hub port. \$\endgroup\$ Jun 16 '18 at 1:26
  • \$\begingroup\$ @AliChen I forgot to mention that, we use that in some of our products with USB hubs in them to keep track of devices \$\endgroup\$
    – Voltage Spike
    Jun 16 '18 at 5:28
0
\$\begingroup\$

I think the question comes from not very-well described behavior of USB hubs when various devices are connected to its downstream ports. The process is as follows:

  1. Initially the hub is in reset state and all downstream (DFP, downstream facing port) ports are disabled. So any traffic coming to upstream port of the hub from host (most packets in HS hubs are broadcasted, and can be visible on all root ports) is initially blocked to DFPs, and no device sees any activity. Then the hub gets "enumerated" by receiving its own unique device address. The DFPs are still disabled.

  2. Each DFP however has a hardwired ability to detect connect event (D+ or D- gets pulled up by device). The connect status gets reported to USB host via a dedicated hub control pipe (the hub is already enumerated and has an assigned address). So the host knows that something is connected, but it doesn't know yet what it is.

  3. Upon getting hub status, the host enables only one DFP at a time, starting in arbitrary order (usually the lowest port that reports new connection).

  4. Then the host starts to communicate with the connected device using so-called "default control pipe", at endpoint 0 address 0. Every device must have one ready after power-up or reset. Since there is only one new port enabled, only one device will be responding. All other devices already would have individual addresses assigned to them, and therefore wouldn't respond to this default (0,0) pipe.

  5. In the process of enumeration this device receives new available device address, and will stop responding to default pipe. All communication with this particular device will go to this new address.

  6. The Host then enables the next port that reports the connected status, and repeats steps (4 - 5).

  7. The host repeats step (6) until all ports with connect status are enabled and all devices behind them are enumerated (got individual device addresses), so the host can address their pipes individually.

This concludes the device enumeration behind hub's DFPs. In the process each device ends up with unique device address, and host knows who is who and where to address it, even if the devices are physically identical.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.