Difference between revisions of "USB notes"

From Helpful
Jump to: navigation, search
m (So what is USB-C precisely?)
m (So what is USB-C precisely?)
Line 449: Line 449:
* https://superuser.com/questions/1181268/is-it-important-for-a-usb-3-0-hub-to-be-powered
* https://superuser.com/questions/1181268/is-it-important-for-a-usb-3-0-hub-to-be-powered
=So what is USB-C precisely?=
USB-C is more a connector than anything else.
It is intentionally protocol-agnostic.
Any one physical port may be give you
: USB3.1 (5 or 10GBps)
: USB2 (0.48GBps)
: Thunderbolt 3 (10GBps)
: USB Power Delivery
: just a video out
Which ones it does is context-dependent.
Thunderbolt, in most contexts, can be seen as an extension of USB3.{{verify}}

Revision as of 20:12, 20 May 2020

Hardware variants

PC controllers will be one of

  • OHCI (Open Host Controller Interface)
    • USB 1
    • Open standard
  • UHCI (Universal Host Controller Interface)
    • USB 1
    • Proprietary standard
    • Intel and VIA are usually UHCI
  • EHCI (Enhanced Host Controller Interface)
    • USB 2
    • public (open?) standard
  • XHCI (eXtensible Host Controller Interface)
    • USB 3
    • in theory replaces OHCI, UHCI, and EHCI

See also:


  • USB1 "Low speed"
    • ~178KByte/s (1.5 Mbit/s) of wire speed, max max ~120KByte/s of carried data due to 8b/10b coding (not yet accounting for protocol overhead)
    • Meant for devices that will never need much speed, such as keyboards
  • USB1 "Full speed"
    • 1.5MByte/s (12 Mbit/s) wire speed, ~1.2MByte/s of carried data
  • USB2 "High speed"
    • 60MByte/s (=480Mbit/s) wire speed, ~48MByte/s carried data
    • expect no more than 30MByte/s, and 25MB/s is more common (apparently because of offloading(verify))
  • USB3 "Superspeed+"
    • 625MByte/s (5Gbps) of wire speed, ~500MByte/s (4Gbps) carried data
    • Note: May do USB2 devices a little faster (as in, may reach 30-40MByte/s where many USB2 controller may stop at ~25MByte/s) (verify)
    • expect no more than ~400MB/s usually
  • USB3.1 "Superspeed+"
    • 1250MByte/s (10Gbps) of wire speed, before 128b/132b coding, ~1200MByte/s (~9Gbps) carried
    • expect no more than ~900MByte/s usually


  • Multiple ports on a hub must share their speed to the shared controller.
This means e.g. copying between two adjacent ports may happen at half the speed you expected.
(at least up to USB2.0 - USB3 became smarter about a few cases(verify))
  • USB3 modes are full-duplex, everything before was half-duplex

Related to use

Unplugging USB

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

Do you need to 'Safely Remove Hardware'?

At an electric and protocol level, USB was made to be hot-pluggable, and as a result, almost all drivers for USB hardware are as well (though not all).

More to the point, an API on top of this may not like it at all, fundamentally, or because it likes to make certain assumptions.

Case in point are USB Storage devices (memory sticks, external hard drives, connected cameras in some modes)

In particular, filesystem APIs assume that a file stays open and available until the program that openend it says it is done.

Yanking while reading from a external storage will almost certainly make the reading program unhappy, though in most cases have no effect on the storage itself.

However, yanking while writing is usually bad.

Most filesystems write file data in-place (so cannot implement a guaranteed recovery)
A number of filesystems are a little more robust about filesystem metadata - but you shouldn't assume it

There are further notes to writing.

  • Internal hard drives tend to keep "stuff to be written" in memory for maybe a second (writeback cache)
it lets the system say "okay program I will do that for you (soon)" instead of making the program wait until it has done it
there are often optimizations. Programs can do things like "write 1K, write 1K, write 1K, write 1K" and the system can often do cleverness like make that a single "write 4K".
  • more easily disconnected drives are often written to as soon as possible (writethrough).
Less efficient but safer, because data doesn't hang around that system buffer
OSes usually opt for the safer-and-slower writethrough for external storage devices, but not always, and you can override this.
this is roughly why "if the USB stick it's no longer blinking it's probably safe to yank" (in that it's probably in a consistent state. The filesystem may still record that you didn't unmount it and be cautious when plugged in next)
  • USB flash drives can corrupt a little more easily when pulled during a write, because writing small pieces of data to flash memory involves a read-erase-write cycle, leaving time in which the data is not on storage, and a non-obvious state to recover (SSDs are smarter about this than most USB sticks)

USB Device Not Recognized / Device has malfunctioned

Shown in a balloon near the task bar, with the addition that "One of the USB devices attached to this computer has malfunctioned, and windows does not recognize it."

(In some cases, if the balloon message is disabled, the device only shows up as an "Unknown Device" in the device manager.)(verify)

My summary so far is that there are many possible causes, it's hard to say which one it is, and most solutions are not very clearly good ones. Reinstalling usually won't help.

Possible problems/solutions

Things you can check easily enough:

  • broken device
    • test: try in other computers - and to be sure, also with varying OSes (some devices don't have drivers for older/specific OSes)
  • broken cable (cables get stepped, yanked, etc.)
    • if it's interchangeable, try another one.
    • If it's not interchangeable, try wiggling it to see if it accidentally makes a good contact. It's not a very good test in that it not working means nothing, but if it turns up temporarily, you know that a bit of DIYing may well fix the problem.
  • broken USB port
    • Test: Try other things in the same port, and this device in others
    • Note: each pair of ports is usually the same internal hub, so only trying the one right next to it is not the best test.
    • Simple mice are the most useful test devices, as they are low-power and do not require drivers to work
  • USB port in a weird state (often a currently blocking polyfuse, but there is another reason or two)
    • (some are more sensitive/careful than others. Macbooks's polyfuses seem to be a little notorious for triggering quickly)
    • Test/fix: Turn computer off completely (and then leave the power cord/battery out for a few minutes - not always necessary, but sometimes it is) for a few minutes.
  • crossing the power limit (particularly on a non-powered hub)
    • ...which means the device will be refused on that hub
    • Test: try plugging the device into the computer itself (or into a powered hub that has no high-powered devices)
      • Front ports may sometimes be non-powered hubs, so a back (motherboard) port is a better test.
    • Test: try a mouse in the same port - it's low-power and so very likely to work if the port's not broken.

Harder to check well:

  • stupid/missing driver for the particular device
    • Test: Try again after a restart, try with different OS, try with a different driver,
  • stupid power management bug (happens on some hardware)
    • There is/was a bug in XP(/Vista?) where power-suspended USB ports are not re-enabled properly, and there were mixed reports about Microsoft's patches (verify). Some people report that disable this port suspending feature helps.
  • windows USB driver set/setup got wonky.
    • Bit of a last resort thing to check
    • Test/fix: Uninstall as many related drivers as you can before plugging the devices back in.

It seems that certain devices are likelier to trigger this problem.

Note that there is a power limit per port (500mA for USB and USB2, 900mA for USB3). Also, motherboards may have a maximum they spend on USB. While this doesn't often lead to problems, it can mean that even if you have powered ports and USB's power management thinks they can give full power, it may be that your power-hungry device's power needs cannot be met by a particular port, or by the motherboard given the bulk of USB devices you've got plugged in.

In a few cases using a different set of ports helps. A better solution to this problem is to get an external powered hub to run such devices.

It seems that Windows's collection of drivers for USB devices (one or more) can get wonky. It may be that reinstalling all of these can help. Remove controllers drives last, so peripherals drivers first. Then rebooting and let it re-detect and re-install everything.

See also

Do hubs, shared cables, etc. affect speed?

Notes on slow USB3

On USB power and charging

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)



  • wallwart / powerbank: many things draw 1A, some may increase up to ~2A
  • On a PC:
USB1+USB2 guarantees 100mA and may supply up to 500mA after negotiation
USB3 guarantees 150mA and may supply up to 900mA after negotiation
'may', because may be denied in the PC knows there isn't enough power for it
  • later wallplug chargers, power banks, some PCs may support standardized Battery Charging (for up to 1.5A) or something proprietary
Battery Charging came relatively late, so mostly seen on USB3 or otherwise recent chargers
no specific logo, either labeled or you have to know(verify)
proprietary is often specific to brands
...so don't bet much on getting more than 1A


  • in practice stays below 3A for practical reasons (verify) (in theory can carry 5A)
  • various things may choose to charge slower


Related to coding

on libusb and platforms

A primer, some terminology