Description
device.dir::USBD Standard Request Handler
Standard Request Handler
Chapter 9 of the USB specification 2.0 defines a set of standard requests which have to be implemented by all devices. Since most class
drivers treat those requests in the standard way, the USB framework provides a way to easily do that.
USBDDriver_RequestHandler
USBDDriver_RequestHandler handles the standard requests in an appropriate way. It
can answer the following commands:
- GET_DESCRIPTOR
- SET_ADDRESS
- SET_CONFIGURATION
- GET_CONFIGURATION
- CLEAR_FEATURE
- SET_FEATURE
- GET_STATUS
Simply using this standard request handler enables a device to be enumerated correctly.
Get Descriptor
The GET_DESCRIPTOR request is used by the host to retrieve information about the device by means of several descriptors.
The standard request handler simply sends the corresponding descriptor to the host. How these descriptors are provided to the function is discussed in Structures.
Set Address
Whenever the host wants to change the device
state from Default to Address, or vice-versa, it sends a SET_ADDRESS request. The wValue field contains the new address of the device; if it is null, then the device returns to the Default
state.
The
USBD_SetAddress function is called to perform this operation. Note that a zero-length packet must be sent prior to doing that, to acknowledge the SETUP transfer.
Set Configuration & GetConfiguration
The SET_CONFIGURATION request makes it possible for the host to select between one or more configurations for the device. GET_CONFIGURATION is used to retrieve the currently selected one.
Those two requests are handled in a very basic way by
USBDDriver_RequestHandler: it assumes that the device has only one configuration. Therefore, the SET_CONFIGURATION request is simply acknowledged with a zero-length packet, and GET_CONFIGURATION is answered with either 0 or 1. If the user application needs more than one configuration, it will be the duty of the class driver handler to service those requests.
In addition, when the SET_CONFIGURATION request causes the device to enter the Configured
state, the standard request handler calls the
USBD_ConfigureEndpoint method for each endpoint used by the device;
Clear Feature, Set Feature & Get Status
Several features of a device
can either be activated or deactivated by the USB host:
- Remote wakeup
- Endpoint Halt state Three requests can be used to either set, clear or get the status of these two features: SET_FEATURE, CLEAR_FEATURE and GET_STATUS.
Structures
Several pieces of information must be known to the
USBDDriver_RequestHandler to be able to process some SETUP commands. For example, all the descriptors (configuration, etc.) used by the device are needed since they must be sent to the host when a GET_DESCRIPTOR is received.
Usage
The NewRequest callback is used to notify the user application that a new SETUP request has been received. SETUP request
can either be class-specific or standard.
The correct way to handle incoming requests is to first process class-specific requests using a class handler. For example, a Mass Storage implementation will define the NewRequest callback to call
MSDDriver_RequestHandler. This function will handle the necessary requests, and forward the rest to
USBDDriver_RequestHandler.
Source
The documentation for this Page was generated from the following file:
device.dir