December 5, 2020

USB - Basic Protocol

When you first plug in a USB device, the host sees the pullup resistors and sends a Reset to the device. My STM32 blue pill has a 4.7K pullup resistor on D+. This is wrong, it should be a 1.5K resistor, but so far this has worked out OK.

The Maple boards with the STM32F103 have a circuit that is able to switch in or out the 1.5K pull-up on D+, and this is called the "disconnect" circuit. If the pullup is removed, it is the same as if the device was unplugged.

The host only resets on device at a time (so there must be some location based addressing scheme to allow this). On being reset, the device will respond on the default address 0 to allow it to be configured.

The host now asks for the maximum packet size using "Get Descriptor". The host may then reset it again, the perform a "Set Address"

Now the host is at its leisure to service other devices, but will continue to interrogate the new device asking for various descriptors. The idea is to get enough information for the host to set up the proper device driver. Then the host will send a "Set Configuration" request.

A device may have multiple configurations, but it is not common. Only one can be set up and active at a time. Some operating systems always select the first configuration and ignore the others (Windows). A device can have multiple interfaces, each with multiple endpoints.

As near as I can tell, this whole business of the device appearing and getting set up is what is called "enumeration".

Standard Requests

These are all done via control transfers to endpoint 0. Each control transfer begins with a SETUP transaction that holds 8 bytes. These 8 bytes have 5 named fields:
bmRequestType - 1 byte (3 bit fields)
bRequest      - 1 byte selects specific request
wValue        - 2 bytes value for request
wIndex        - 2 bytes index or offset for request
wLength       - 2 bytes count of bytes in data state, if there is one.
Note the convention of "b" for a byte value and "w" for a 2 byte word.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org