1
\$\begingroup\$

Is there a way for a USB 2.0 Device to detect if it is connected to a USB 2.0 or USB 3.X host port? I need this to figure out the maximum current the device can safely take.

Some more details about the project:

I'm designing a gaming controller that have addressable RGB lights. Those currently use an external 5V supply (a standard DC barrel jack wall supply + USB cable for data). I would like to have a single USB cable powering the device and the lights but those can take more than 500mA sometimes.

If there is a way to check if the device can or cannot draw more than 500mA I would design it to run into two different power modes based on the host port.

The MCU I use is an STM32F103C8 which only support USB 2.0 FS.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Hello and welcome. Your LEDs in a controller take more than 500 mA? They sound pretty bright! Or is there more circuitry? \$\endgroup\$
    – jonathanjo
    Commented Sep 25, 2023 at 16:33
  • \$\begingroup\$ It is a dancing game platform so it is a pretty big device. Not a standard controller. Anyway it stays below 800mA of maximum power consumption, but usually it takes 400mA. \$\endgroup\$
    – Flood2d
    Commented Sep 25, 2023 at 16:35
  • 2
    \$\begingroup\$ @Flood2d Consider investigating the USB Power Delivery Protocol as a segue. \$\endgroup\$ Commented Sep 25, 2023 at 16:39
  • 1
    \$\begingroup\$ @periblepsis Thanks I'll look into that. \$\endgroup\$
    – Flood2d
    Commented Sep 25, 2023 at 16:41
  • 1
    \$\begingroup\$ Depending on your circuit, if on average you're under 500 mA, you could consider some variety of battery/capacitor for the peaks. \$\endgroup\$
    – jonathanjo
    Commented Sep 25, 2023 at 16:55

2 Answers 2

2
\$\begingroup\$

No, not possible. Your device must adhere to the limits defined by the specs, or it may damage something.

And when enumerating with the host, you need to request how much current your device needs before the host allows your device to start consuming that amount.

Now, what happens if you request some amount of current and host stops the emumeration is up to you. You can try to re-enumerate with less current and make sure in STM32 software to limit the brightness so the enumerated current is not exceeded.

The USB3 lines can't be used, they are activated only after USB2 enumeration says the device supports USB3 and host sees this and tries to enumerate USB3.

You also can't use USB PD as it is only relevant if both your device and PC have Type-C connection and both support USB PD. And then you still need to work without USB PD if someone uses a USB-A to Type-C cable on USB2 port.

Edit: Actually USB3 is probed first, but the process needs both sides to handshake in few hundred milliseconds or they both fall back to starting USB2 enumeration.

\$\endgroup\$
3
  • \$\begingroup\$ Checking that the current consumption is below 500mA is fairly easy and I can then shut-off or regulate to stay below the maximum rating of the spec. \$\endgroup\$
    – Flood2d
    Commented Sep 25, 2023 at 16:43
  • \$\begingroup\$ That is why I wanted to know if there is a way to check if the host port is 3.0 even if the device is 2.0 since it can take more power in that scenario. When the port is 2.0 I will protect against overcurrent anyway. \$\endgroup\$
    – Flood2d
    Commented Sep 25, 2023 at 16:43
  • \$\begingroup\$ I accepted your answer. I think I will use an STM32G4 that has built-in USB3 support with USB PD since the price is fairly similar. Thanks! \$\endgroup\$
    – Flood2d
    Commented Sep 25, 2023 at 17:12
0
\$\begingroup\$

You can use USB3 connector and check for Rx_Detect pulses that every USB3 host port must continuously emit in order to detect USB3 partner. If there is no pulses, then the port is USB2 only. I don't recall anything in USB2 or PD or USB-C specifications that would prohibit this approach.

Also, with rapid proliferation of Type-C connectors, I would suggest to catch the trend. In case of Type-C you don't need the PD and just use the basic resistor-based method of detection of port power capability, 500/900 or 1.5A or 3A. Still the USB2/3 detection will be needed. In most cases it will be 5V3A.

And yes, for USB compliance, you need to obey the "device-side-rule" of not starting to consume full power until the host finishes device enumeration and sets "device configuration".

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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