Datasheet

Migrating from EZ-USB
®
FX2LP™ Based Design to EZ-USB FX3 Based Design
www.cypress.com Document No. 001-76348 Rev. ** 10
Application Initialization
The application initialization consists of the following
steps:
USB Initialization
The USB stack in the FX3 library is first initialized. The
initialization is done by invoking the USB
Start function.
/* Start the USB functionality */
apiRetStatus = CyU3PUsbStart();
The fast enumeration is the easiest way to setup a
USB connection, where all enumeration phase is
handled by the library. Only the class / vendor
requests need to be handled by the application. In
case of FX2LP, this enumeration part is handled in the
function SetupCommand(void) in fw.c.
The next step is to register for callbacks. In this
example, callbacks are registered for USB Setup
requests and USB Events.
CyU3PUsbRegisterSetupCallback(CyFxBulkLp
ApplnUSBSetupCB, CyTrue);
/* Setup the callback to handle the
USB events. */
CyU3PUsbRegisterEventCallback(CyFxBulkLp
ApplnUSBEventCB);
The callback functions and the callback handling are
described in later sections.
The USB descriptors are set and this is done by
invoking the USB set descriptor call for each
descriptor.
/* Set the USB Enumeration descriptors
*/
/* Device Descriptor */
apiRetStatus =
CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_DEVICE
_DESCR, NULL,
(uint8_t *)CyFxUSB20DeviceDscr);
The previous code snippet is for setting the Device
Descriptor. The other descriptors set in the example
are Device Qualifier, Other Speed, Configuration,
BOS (for Super Speed), and String Descriptors.
The USB pins are connected. The FX3 USB device is
visible to the host only after this action.
Hence it is important that all setup is completed before
the USB pins are connected.
/* Connect the USB Pins */
/* Enable Super Speed operation */
apiRetStatus = CyU3PConnectState(CyTrue,
CyTrue);
USB Setup Callback
Since the fast enumeration model is used, only vendor
and class specific requests are received by the
application. Standard requests are handled by the
firmware library. Since there is no vendor or class specific
requests to be handled, the callback just returns CyFalse.
/* Callback to handle the USB setup
requests. */
CyBool_t
CyFxBulkLpApplnUSBSetupCB (
uint32_t setupdat0, /* SETUP Data 0
*/
uint32_t setupdat1 /* SETUP Data 1
*/
)
{
/* Fast enumeration is used. Only
class, vendor and unknown requests
* are received by this function. These
are not handled in this
* application. Hence return CyFalse.
*/
return CyFalse;
}
USB Event Callback
The USB events of interest are: Set Configuration, Reset,
and Disconnect. The bulkloop is started on receiving a
SETCONF event and is stopped on a USB reset or USB
disconnect.
/* This is the callback function to handle
the USB events. */
void
CyFxBulkLpApplnUSBEventCB (
CyU3PUsbEventType_t evtype, /* Event
type */
uint16_t evdata /* Event
data */
)
{
switch (evtype)
{
case CY_U3P_USB_EVENT_SETCONF:
/* Stop the application before re-
starting. */
if (glIsApplnActive)
{
CyFxBulkLpApplnStop ();
}
/* Start the loop back function. */
CyFxBulkLpApplnStart ();
break;
case CY_U3P_USB_EVENT_RESET:
case CY_U3P_USB_EVENT_DISCONNECT:
/* Stop the loop back function. */
if (glIsApplnActive)
{