Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Knowledge Base Articles

Handling CYU3P_USBEP_SS_RESET_EVT event in FX3 - KBA226725

MohammedA_41
Community Manager
Community Manager First like received First like given First solution authored
Community Manager

Handling CYU3P_USBEP_SS_RESET_EVT event in FX3 - KBA226725

Version: **

This document describes how to handle the CYU3P_USBEP_SS_RESET_EVT in EZ-USB FX3 firmware.

This event can occur only for an IN endpoint when many USB 3 protocol-level retries occur on the bus due to a bad cable or bad testing/running environment (where there can be protocol-level CRC errors).

Do the following to handle the event:

Step 1:

Register the endpoint event callback in the firmware to check if this event is triggered. Use the CyU3PUsbRegisterEpEvtCallback()API to register the endpoint callback.

Usage:

CyU3PUsbRegisterEpEvtCallback (CyU3PUsbEpEvtCb_t cbFunc, uint32_t eventMask, uint16_t outEpMask, uint16_t inEpMask);
cbFunc     : Callback function pointer

eventMask: The enumeration of different endpoint events are as follows:

MohammedA_41_0-1652434845606.png

To generate the callback for CYU3P_USBEP_SS_RESET_EVT, set the eventMask as 0x0100. To generate the callback for both CYU3P_USBEP_SS_RESET_EVT and CYU3P_USBEP_SS_RETRY_EVT, set the eventMask as 0x0110.

outEpMask: Bitmap variable representing the OUT endpoints whose events are to be enabled. Bit 1 represents EP 1-OUT, 2 represents EP 2-OUT, and so on.

inEpMask: Bitmap variable representing the IN endpoints whose events are to be enabled. Bit 1 represents EP 1-IN, 2 represents EP 2-IN, and so on.

Note: See the example in the following path of the FX3 SDK where this callback is registered and the event is handled for two IN Endpoints:

[FX3_Installation_Path]\EZ-USB FX3 SDK\1.3\firmware\basic_examples\cyfxgpiftousb

Step 2:

This event is endpoint-specific. When this event occurs for an endpoint, the specific IN endpoint must be stalled. See the following code snippet:

if (evtype == CYU3P_USBEP_SS_RESET_EVT)
    {
        if (epNum == CY_FX_EP_CONSUMER)
        {
            CyU3PDebugPrint (2, "Halting USB Streaming EP: %d\r\n", BulkRstCnt++);
            CyU3PUsbStall (CY_FX_EP_CONSUMER, CyTrue, CyFalse);
        }
        if (epNum == CY_FX_EP_LOOP_IN)
        {
            CyU3PDebugPrint (2, "Halting USB Loopback EP: %d\r\n", LoopRstCnt++);
            CyU3PUsbStall (CY_FX_EP_LOOP_IN, CyTrue, CyFalse);
        }
    }

Step 3:

When the IN endpoint is stalled, the API in the host application that requests the data on this endpoint fails; the error code indicates Endpoint Stall.

In that case, the host application should send a CLEAR_FEATURE request targeting this specific IN endpoint (for which the data request failed).

When CLEAR_FEATURE is received, the FX3 firmware should have the following handler:

if ((bTarget == CY_U3P_USB_TARGET_ENDPT) && (bRequest == CY_U3P_USB_SC_CLEAR_FEATURE)
                && (wValue == CY_U3P_USBX_FS_EP_HALT))
        {
            if (glIsApplnActive)
            {
                if (wIndex == CY_FX_EP_CONSUMER)
                {
                    CyU3PUsbSetEpNak (CY_FX_EP_CONSUMER, CyTrue);
                    CyU3PBusyWait (125);

                    CyU3PDmaChannelReset (&glDmaChHandle);
                    CyU3PUsbFlushEp(CY_FX_EP_CONSUMER);
                    CyU3PUsbResetEp (CY_FX_EP_CONSUMER);
                    CyU3PDmaChannelSetXfer (&glDmaChHandle, CY_FX_GPIFTOUSB_DMA_TX_SIZE);
                    CyU3PUsbStall (wIndex, CyFalse, CyTrue);

                    CyU3PUsbSetEpNak (CY_FX_EP_CONSUMER, CyFalse);
                    isHandled = CyTrue;
                    CyU3PUsbAckSetup ();
                }

Both these code snippets are implemented in the gpiftousb example ([FX3_Installation_Path]\EZ-USB FX3 SDK\1.3\firmware\basic_examples\cyfxgpiftousb)

Note: See also Section 2.3.IV of the FX3 SDK troubleshooting guide in addition to this article:
[FX3_Installation_Path]\EZ-USB FX3 SDK\1.3\doc\firmware\ FX3_SDK_TroubleShooting_Guide.pdf

 

0 Likes
Version history
Revision #:
2 of 2
Last update:
‎May 13, 2022 02:53 AM
Updated by: