USB – How to Detect if a Device Is Connected to USB 2.0 or USB 3.0 Port

powerusb

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.

Best Answer

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.