Endpoint Types

The Universal Serial Bus specification defines four transfer/endpoint types,

Control Transfers

Control transfers are typically used for command and status operations. They are essential to set up a USB device with all enumeration functions being performed using control transfers. They are typically bursty, random packets which are initiated by the host and use best effort delivery. The packet length of control transfers in low speed devices must be 8 bytes, full speed devices allow a packet size of 8, 16, 32 or 64 bytes and high speed devices must have a packet size of 64 bytes.

A control transfer can have up to three stages.

Control Transfers: The bigger picture

Now how does all this fit together? Let's say for example, the Host wants to request a device descriptor during enumeration. The packets which are sent are as follows.

The host will send the Setup token telling the function that the following packet is a Setup packet. The Address field will hold the address of the device the host is requesting the descriptor from. The endpoint number should be zero, specifying the default pipe. The host will then send a DATA0 packet. This will have an 8 byte payload which is the Device Descriptor Request as outlined in Chapter 9 of the USB Specification. The USB function then acknowledges the setup packet has been read correctly with no errors. If the packet was received corrupt, the device just ignores this packet. The host will then resend the packet after a short delay.

1. Setup Token
SyncPIDADDRENDPCRC5EOP
Address & Endpoint Number
2. Data0 Packet
SyncPIDData0CRC16EOP
Device Descriptor Request
3. Ack Handshake
SyncPIDEOP
Device Acknowledge Setup Packet
The above three packets represent the first USB transaction. The USB device will now decode the 8 bytes received, and determine if it was a device descriptor request. The device will then attempt to send the Device Descriptor, which will be the next USB transaction.
1. In Token
SyncPIDADDRENDPCRC5EOP
Address & Endpoint Number
2. Data1 Packet
SyncPIDData1CRC16EOP
First 8 Bytes of 12-byte Device Descriptor
3. Ack Handshake
SyncPIDEOP
Host Acknowledges Packet
1. In Token
SyncPIDADDRENDPCRC5EOP
Address & Endpoint Number
2. Data0 Packet
SyncPIDData0CRC16EOP
Last 4 bytes
3. Ack Handshake
SyncPIDEOP
Host Acknowledges Packet
In this case, we assume that the maximum payload size is 8 bytes. The host sends the IN token, telling the device it can now send data for this endpoint. As the maximum packet size is 8 bytes, we must split up the 12 byte device descriptor into chunks to send. Each chunk must be 8 bytes except for the last transaction. The host acknowledges every data packet we send it.

Once the device descriptor is sent, a status transaction follows. If the transactions were successful, the host will send a zero length packet indicating the overall transaction was successful. The function then replies to this zero length packet indicating its status.

1. Out Token
SyncPIDADDRENDPCRC5EOP
Address & Endpoint Number
2. Data1 Packet
SyncPIDData1CRC16EOP
Zero Length Packet
3. Ack Handshake
SyncPIDEOP
Device acknowledges entire transaction

Interrupt Transfers

Any one who has had experience of interrupt requests on microcontrollers will know that interrupts are device generated. However under USB if a device requires the attention of the host, it must wait until the host polls it before it can report that it needs urgent attention!

Interrupt Transfers

Interrupt transfers are typically non-periodic, small device “initiated” communication requiring bounded latency. An Interrupt request is queued by the device until the host polls the USB device asking for data.

The above diagram shows the format of an Interrupt IN and Interrupt OUT transaction.

Isochronous Transfers

Isochronous transfers occur continuously and periodically. They typically contain time sensitive information, such as an audio or video stream. If there were a delay or retry of data in an audio stream, then you would expect some erratic audio containing glitches. The beat may no longer be in sync. However if a packet or frame was dropped every now and again, it is less likely to be noticed by the listener.

Isochronous Transfers provide

The maximum size data payload is specified in the endpoint descriptor of an Isochronous Endpoint. This can be up to a maximum of 1023 bytes for a full speed device and 1024 bytes for a high speed device. As the maximum data payload size is going to effect the bandwidth requirements of the bus, it is wise to specify a conservative payload size. If you are using a large payload, it may also be to your advantage to specify a series of alternative interfaces with varying isochronous payload sizes. If during enumeration, the host cannot enable your preferred isochronous endpoint due to bandwidth restrictions, it has something to fall back on rather than just failing completely. Data being sent on an isochronous endpoint can be less than the pre-negotiated size and may vary in length from transaction to transaction.

The above diagram shows the format of an Isochronous IN and OUT transaction. Isochronous transactions do not have a handshaking stage and cannot report errors or STALL/HALT conditions.

Bulk Transfers

Bulk transfers can be used for large bursty data. Such examples could include a print-job sent to a printer or an image generated from a scanner. Bulk transfers provide error correction in the form of a CRC16 field on the data payload and error detection/re-transmission mechanisms ensuring data is transmitted and received without error.

Bulk transfers will use spare un-allocated bandwidth on the bus after all other transactions have been allocated. If the bus is busy with isochronous and/or interrupt then bulk data may slowly trickle over the bus. As a result Bulk transfers should only be used for time insensitive communication as there is no guarantee of latency.

Bulk Transfers

Bulk transfers are only supported by full and high speed devices. For full speed endpoints, the maximum bulk packet size is either 8, 16, 32 or 64 bytes long. For high speed endpoints, the maximum packet size can be up to 512 bytes long. If the data payload falls short of the maximum packet size, it doesn't need to be padded with zeros. A bulk transfer is considered complete when it has transferred the exact amount of data requested, transferred a packet less than the maximum endpoint size, or transferred a zero-length packet.

The above diagram shows the format of a bulk IN and OUT transaction.

Possible endpoint sizes and classes

Summary of endpoint sizes and USB classes
ControlBulkInterruptIsochronousImplementable USB classes
Low Speed8-1..8-HID (0x03), Application Specific (0xFE), Vendor Specific (0xFF)
Full Speed8,16,32,648,16,32,641..641..1023All
Hi-Speed645121..5121..1024
SuperSpeed51210241..1024

Bandwidth Management

The host is responsible for managing the bandwidth of the bus. This is done at enumeration when configuring Isochronous and Interrupt Endpoints and throughout the operation of the bus. The specification places limits on the bus, allowing no more than 90% of any frame to be allocated for periodic transfers (Interrupt and Isochronous) on a full speed bus. On high speed buses this limitation gets reduced to no more than 80% of a microframe can be allocated for periodic transfers.

So you can quite quickly see that if you have a highly saturated bus with periodic transfers, the remaining 10% is left for control transfers and once those have been allocated, bulk transfers will get their slice of what is left.