Specifications

4
6263A–ATARM–10-Oct-06
Application Note
Reset
Suspend
Resume
NewRequest
•StartOfFrame
Be sure to use the same order when declaring the S_usb_callbacks structure in your code.
Since most callbacks have the same arguments, not every compiler will give an error message if
two callbacks are inverted.
This structure should be a constant to save RAM.
3.3 USB API methods
The USB API provides several methods to perform the following operations:
Changing the device state
Handling events coming from the USB controller
Modifying the behavior of an endpoint
Transferring data
Special functions
3.3.1 Controlling the Device State
Chapter 9 of the USB specification 2.0 describes the various states a device can be in. Most of
the methods of this API are used to change between those states.
3.3.1.1 USB_Init
This is the first method to call in a user application. Technically, it must occur just before entering
the Attached state. It performs the following actions:
Endpoint state initialization
D+ pull-up configuration and disabling
Init callback invocation
A USB device uses a pull-up on the D+ line to signal its connection to the host. Depending on
the USB controller present on the chip, either an internal or external pull-up is used. In both
cases, its configuration is performed directly by this method. Please refer to the documentation
of a particular controller for more information about the D+ pull-up.
The Init callback has to perform several mandatory operations at this point. Section 3.4.2 on
page 9 gives more details on this step.
3.3.1.2 USB_Attach
Whenever a device gets attached to the host, it receives a +5V signal on the VBus line for pow-
ering. Conversely, when the cable is disconnected or the host is shut down, this signal
disappears.
This function monitors the VBus status to attach or detach the device from the bus, i.e., switch
between the Attached and Powered state of the USB state machine. Whenever the device gets
powered, the USB controller is enabled to start receiving commands from the host. When the
power goes down, USB_Attach disables the peripheral.