Specifications

5
6263A–ATARM–10-Oct-06
Application Note
This function triggers the Resume and the Suspend callbacks upon attachment/detachment.
Those callbacks are used to put the device into low-power mode if needed. More information is
given in Section 3.4.4 and Section 3.4.5 on page 10.
Note that if the device is bus-powered, i.e., its only power source is VBus, then this function
should be called once to power up the peripheral. Otherwise, it should be tied to a VBus monitor-
ing routine. Most of the time, there will be a pin connected to VBus; a PIO interrupt can be used
to signal a state change and call the USB_Attach method.
3.3.1.3 USB_Connect, USB_Disconnect
These two methods control the state of the D+ pull-up. This makes it possible to connect or dis-
connect the device by software when needed. USB_Connect changes the device state from
Powered to Default, while USB_Disconnect changes from either Default, Address or Configured
to Powered.
Strictly speaking, the USB_Attach method should be called first to go from Attached to Powered,
then the software can call USB_Connect to enter the Default state. This makes no difference in
practice.
3.3.1.4 USB_SetAddress
USB_SetAddress extracts the information from the last received SETUP packet to either change
the device state from Default to Address or from Address to Default. The difference is made
depending on the value of the wValue field of the request.
This method must only be called right after the SET_ADDRESS request is received.
3.3.1.5 USB_SetConfiguration
This function operates in a way similar to USB_SetAddress. When the SETUP packet containing
a SET_CONFIGURATION request is received, USB_SetConfiguration should be called to
extract the new configuration value to adopt. If the wValue field of the request is non-zero, then
the device must adopt the new configuration and enter the Configuration state; otherwise, it
returns (or stays) in the Address state.
3.3.1.6 USB_GetState
As its name implies, this method simply returns the current state of the USB driver. The first six
bits of the returned value each indicate if a particular state is active:
USB_STATE_ATTACHED (bit 0): Always set, since physical attachment or detachment from
the bus cannot be detected.
USB_STATE_POWERED (bit 1): Set when VBus is present. Cleared when VBus is
disconnected.
USB_STATE_DEFAULT (bit 2): Set when an End of bus reset operation completes. Cleared
when USB_Disconnect is called.
USB_STATE_ADDRESS (bit 3): Set when a SET_ADDRESS request with a non-null
wValue field is received. Cleared when a SET_ADDRESS request with a null wValue field is
received.
USB_STATE_CONFIGURED (bit 4): Set when a SET_CONFIGURATION request with a
non-null wValue field is received. Cleared when a SET_CONFIGURATION request with a null
wValue field is received.
USB_STATE_SUSPENDED (bit 5): Set when the bus is idle. Cleared when the bus becomes
active again. The other bits indicate the state the device was in before being suspended.