next up previous contents
Next: 9.2 Performing Control Transfers Up: 9. USB Control Transfers Previous: 9. USB Control Transfers   Contents


9.1 USB Control Transfers Overview

9.1.1 USB Data Exchange

The USB standard supports two kinds of data exchange between the host and the device:

Functional data exchange
is used to move data to and from the device. There are three types of data transfers: Bulk, Interrupt, and Isochronous transfers.

Control exchange
is used to configure a device when it is first attached and can also be used for other device-specific purposes, including control of other pipes on the device. Control exchange takes place via a control pipe, mainly the default Pipe 0, which always exists.

Figure 9.1: USB Data Exchange
Image wiz_usb_data_exchange

9.1.2 More About the Control Transfer

The control transaction always begins with a setup stage. The setup stage is followed by zero or more control data transactions (data stage) that carry the specific information for the requested operation, and finally a status transaction completes the control transfer by returning the status to the host.

During the setup stage, an 8-byte setup packet is used to transmit information to the control endpoint of the device. The setup packet's format is defined by the USB specification.

A control transfer can be a read transaction or a write transaction. In a read transaction the setup packet indicates the characteristics and amount of data to be read from the device. In a write transaction the setup packet contains the command sent (written) to the device and the number of control data bytes that will be sent to the device in the data stage.

Refer to Figure 9.2 (taken from the USB specification) for a sequence of read and write transactions.
`(in)' indicates data flow from the device to the host.
`(out)' indicates data flow from the host to the device.

Figure 9.2: USB Read and Write
Image usb_read_write

9.1.3 The Setup Packet

The setup packets (combined with the control data stage and the status stage) are used to configure and send commands to the device. Chapter 9 of the USB specification defines standard device requests. USB requests such as these are sent from the host to the device, using setup packets. The USB device is required to respond properly to these requests. In addition, each vendor may define device-specific setup packets to perform device-specific operations. The standard setup packets (standard USB device requests) are detailed below. The vendor's device-specific setup packets are detailed in the vendor's data book for each USB device.

9.1.4 USB Setup Packet Format

The table below shows the format of the USB setup packet. For more information, please refer to the USB specification at

Byte Field Description
0 bmRequest Type Bit 7: Request direction (0=Host to device - Out, 1=Device to host - In).
Bits 5-6: Request type (0=standard, 1=class, 2=vendor, 3=reserved).
Bits 0-4: Recipient (0=device, 1=interface, 2=endpoint,3=other).
1 bRequest The actual request (see the Standard Device Request Codes table [9.1.5]).
2 wValueL A word-size value that varies according to the request. For example, in the CLEAR_FEATURE request the value is used to select the feature, in the GET_DESCRIPTOR request the value indicates the descriptor type and in the SET_ADDRESS request the value contains the device address.
3 wValueH The upper byte of the Value word.
4 wIndexL A word-size value that varies according to the request. The index is generally used to specify an endpoint or an interface.
5 wIndexH The upper byte of the Index word.
6 wLengthL A word-size value that indicates the number of bytes to be transferred if there is a data stage.
7 wLengthH The upper byte of the Length word.

9.1.5 Standard Device Request Codes

The table below shows the standard device request codes.

bRequest Value
Reserved for future use 2
Reserved for future use 4

9.1.6 Setup Packet Example

This example of a standard USB device request illustrates the setup packet format and its fields. The setup packet is in Hex format.

The following setup packet is for a control read transaction that retrieves the device descriptor from the USB device. The device descriptor includes information such as USB standard revision, vendor ID and product ID.

GET_DESCRIPTOR (Device) Setup Packet

80 06 00 01 00 00 12 00

Setup packet meaning:

Byte Field Value Description
0 BmRequest Type 80 8h=1000b

bit 7=1 -> direction of data is from device to host.


bits 0..1=00 -> the recipient is the device.
1 bRequest 06 The Request is GET_DESCRIPTOR.
2 wValueL 00  
3 wValueH 01 The descriptor type is device (values defined in USB spec).
4 wIndexL 00 The index is not relevant in this setup packet since there is only one device descriptor.
5 wIndexH 00  
6 wLengthL 12 Length of the data to be retrieved: 18(12h) bytes (this is the length of the device descriptor).
7 wLengthH 00  

In response, the device sends the device descriptor data. A device descriptor of Cypress EZ-USB Integrated Circuit is provided as an example:

Byte No. 0 1 2 3 4 5 6 7 8 9 10
Content 12 01 00 01 ff ff ff 40 47 05 80

Byte No. 11 12 13 14 15 16 17
Content 00 01 00 00 00 00 01

As defined in the USB specification, byte 0 indicates the length of the descriptor, bytes 2-3 contain the USB specification release number, byte 7 is the maximum packet size for endpoint 00, bytes 8-9 are the Vendor ID, bytes 10-11 are the Product ID, etc.

next up previous contents
Next: 9.2 Performing Control Transfers Up: 9. USB Control Transfers Previous: 9. USB Control Transfers   Contents