CY_U3P_ERROR_INVALID_SEQUENCE of CyU3PUsbHostEpSetXfer function

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

cross mob
rokw_4712521
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

Hello,

I have constructed data receiving module quote from the USBHost example, which is shown below.

In my test, first few minutes, it worked okay but it ends up with "CY_U3P_ERROR_INVALID_SEQUENCE" error which caused by CyU3PUsbHostEpSetXfer function.

FX3 API Guide says the error means "The endpoint is already active" but this is not enough for me.

Can you please explain in more detail in what case, does this error breakout?

CyU3PReturnStatus_t

CyFxMscRecvBuffer (

        uint8_t *buffer,

        uint16_t count)

{

    CyU3PDmaBuffer_t buf_p;

    CyU3PUsbHostEpStatus_t epStatus;

    CyU3PReturnStatus_t status = CY_U3P_SUCCESS;

    /* Setup the DMA for transfer. */

    buf_p.buffer = buffer;

    buf_p.count  = 0;

    buf_p.size   = ((count + 0x0F) & ~0x0F);

    buf_p.status = 0;

    status = CyU3PDmaChannelSetupRecvBuffer (&glMscInCh, &buf_p);

    if (status == CY_U3P_SUCCESS)

    {

        status = CyU3PUsbHostEpSetXfer (glMscInEp,

                CY_U3P_USB_HOST_EPXFER_NORMAL, count);

    }

    if (status == CY_U3P_SUCCESS)

    {

        status = CyU3PUsbHostEpWaitForCompletion (glMscInEp, &epStatus,

                CY_FX_MSC_WAIT_TIMEOUT);

    }

    if (status == CY_U3P_SUCCESS)

    {

        status = CyU3PDmaChannelWaitForCompletion (&glMscInCh, CYU3P_NO_WAIT);

    }

    if (status != CY_U3P_SUCCESS)

    {

        CyFxMscErrorRecovery ();

    }

    return status;

}

0 Likes
9 Replies
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

Can I know if you are sure that CY_U3P_ERROR_INVALID_SEQUENCE is caused by CyU3PUsbHostEpSetXfer?

If yes, can you please let me know if you tried calling CyFxMscRecvBuffer() before another call to the same API returned? That is, once CyFxMscRecvBuffer() is called, the API returns if the transfer was successful or CY_FX_MSC_WAIT_TIMEOUT is finished. Before this happens, if you call CyFxMscRecvBuffer() once more, there is a possibility of CY_U3P_ERROR_INVALID_SEQUENCE to occur.

Regards,

Hemanth

Hemanth
0 Likes
Can I know if you are sure that CY_U3P_ERROR_INVALID_SEQUENCE is caused by CyU3PUsbHostEpSetXfer?

Yes I printed out log which caused the error and so I can sure that it was CyU3PUsbHostEpSetXfer.

If yes, can you please let me know if you tried calling CyFxMscRecvBuffer() before another call to the same API returned? That is, once CyFxMscRecvBuffer() is called, the API returns if the transfer was successful or CY_FX_MSC_WAIT_TIMEOUT is finished. Before this happens, if you call CyFxMscRecvBuffer() once more, there is a possibility of CY_U3P_ERROR_INVALID_SEQUENCE to occur.

CyFxMscRecvBuffer() is called only in the loop of a thread and never called elsewhere.

So when CyFxMscRecvBuffer() is under processing, there's no chance that it can be called once more, I think.

The case you told me is quite reasonable but I don't think I called it again.

Thank you for your explanation.

0 Likes
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

This can also happen when CyU3PUsbHostEpAbort() was not successful in CyFxMscErrorRecovery() which might have been called in the previous call to CyFxMscRecvBuffer()

OR

If EP interrupt is missed. I hope you have explored this angle, referring to thread: Can't find any information on how to interpret epStatus

Regards,

Hemanth

Hemanth
0 Likes

There's no chance for the CyFxMscRecvBuffer() to be called in other threads. 

My fx3 reads data, i.e. music streaming from Android phone through USB connection .

Due to the difference in the data processing speed between the phone and fx3, sometimes fx3 produces INVALID_SEQUENCE error and probably there could be multiple threads in reading the usb data  , I think.

In AN75779, it treated this error just by restarting the application but quite disappointing that I have to lose data during that period.

Hope this could be seriously handled by Cypress.

0 Likes
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

I am further looking into it.

From your last post, I understand that, FX3 is acting as a Host which requests data from Android phone, which is acting as device. I also note that CyFxMscRecvBuffer() is not called in multiple threads.


 This can also happen when CyU3PUsbHostEpAbort() was not successful in CyFxMscErrorRecovery() which might have been called in the previous call to CyFxMscRecvBuffer()

 Can you please my above comment? Is it possible to attach your firmware?

Regards,

Hemanth
0 Likes
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

Just before CyU3PUsbHostEpSetXfer() returned Invalid sequence error, please check if CyFxMscErrorRecovery() was called for the EP used. In CyFxMscErrorRecovery(), obtain status for every API called and check if any one failed. Also at the end check if CyFxMscErrorRecovery() was success or not - this is not done in USBHost example of FX3 SDK.

Regards,

Hemanth
0 Likes
lock attach
Attachments are accessible only for community members.

I attached some of the files of my firmware which is related to this error and some logs from my test.

As you can see, I modified a bit to clarify the cause of the error and CyFxMscErrorRecovery() was never used anywhere.(see attached)

Followings are the log when the error breaks out.

984 [Z->P] Rcv(o:24904 x:0) Snd(o:24904 x:0) | [P->Z] Rcv(o:406490 x:0) Snd(o:406490 x:0)
985 [Z->P] Rcv(o:24936 x:0) Snd(o:24936 x:0) | [P->Z] Rcv(o:406938 x:0) Snd(o:406938 x:0)
986 [Z->P] Rcv(o:24960 x:0) Snd(o:24960 x:0) | [P->Z] Rcv(o:407346 x:0) Snd(o:407346 x:0)
987 [Z->P] Rcv(o:24984 x:0) Snd(o:24984 x:0) | [P->Z] Rcv(o:407754 x:0) Snd(o:407754 x:0)
988 [Z->P] Rcv(o:25008 x:0) Snd(o:25008 x:0) | [P->Z] Rcv(o:408162 x:0) Snd(o:408162 x:0)
989 [Z->P] Rcv(o:25032 x:0) Snd(o:25032 x:0) | [P->Z] Rcv(o:408570 x:0) Snd(o:408570 x:0)
990 [Z->P] Rcv(o:25056 x:0) Snd(o:25056 x:0) | [P->Z] Rcv(o:408978 x:0) Snd(o:408978 x:0)
[CyFxRecvBuffer] CyU3PUsbHostEpSetXfer error=0x47, ep=0x81,count=512
[P-Z] receiving from PhoneDataIn failed error(0x47),EP=0x81 % @ JB { b B1%BZ L k + (JiJ iZJBsr
V mJ K ZV# c Cd l( 5@ J JL J T @ ^O}FJ!V( Z I ZxFJJB) BJ Z @F! s )jzQ B
` )sJ G )J@l ^ BK{(Cc b)J s Hk $L CVJ y sZ[)c }J B JNB)Ij 1;B(N HF) O$K M!} RbK B B Kb
JB @@GI KiHKzK j ,B# * C N{ h!kI@B JL hZZJJfBcc F ZBJ -{B B BM !J{Z 1)JJbJN WC%'!F R B BRJJ
jCcF#IR J C (% )JJ KZ( B KO k K[ B Q !) PkJH BR-J
BBGJB$Ha
G! j N JG b- ) ; PN d@!& g + k 9 - R BV^ JRB HC JB kB
-B( ^^F5Q J@ B
HB BJ (UsbOtg Example`RJ F( jBb #-JBjNBER K N -cCBB+K ^IB B ^
Assuming that driving CTL4 high turns VBus output ONJ [SR z%JVBB+I!)s G*% M(@ RV FX%!-V ZBc
[Phone] Setup GPIO OK
[Phone] I2C Init OK
[Phone] PIB Init OK

 

0 Likes
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

Here are few thoughts:

In each call to CyFxRecvBuffer(), first CyU3PUsbHostEpSetXfer() is called followed by CyU3PUsbHostEpWaitForCompletion() - this has waitoption as CYU3P_WAIT_FOREVER.

CyU3PUsbHostEpWaitForCompletion() returns only when endpoint interrupt (EP_INTR) is raised. In your case CyU3PUsbHostEpWaitForCompletion() never failed.

So, if EP_INTR came for the corresponding endpoint, then next call to CyU3PUsbHostEpSetXfer() cannot fail with Invalid sequence error, because, Invalid sequence error in this API is returned when the endpoint is already active OR some transfer is pending on that endpoint - whereas both are not true when interrupt for that endpoint already occurred.

I would look more into it. Is it possible for you to attach your entire firmware? (Also, the debug logs attached above, does not exactly match with the statements in the src file attached. But I believed that there was no error logged before CyU3PUsbHostEpSetXfer failure)

Regards,

Hemanth
0 Likes

The log tells during the process, INVALID_SEQUENCE error from CyU3PUsbHostEpSetXfer found but no other errors were found. (see uhbuf.c)

Before I can share the full source code, somethings must be clear because the FW belongs to my company asset.
The company I work for has an NDA with Cypress.

Therefore, if you are an employee of Cypress, I can send you my FW under the NDA to your company email.

0 Likes