Reading the USB EP0 messages

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

cross mob
FrPo_1282226
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Hello there,

I need to use the EP0 for compatibility reason, to control some equipment.

I have followed the suggestion here: Example on how to use the USB control EndPoint EP0

and I had almost working:

I defined

      #define USB_EP_0_ISR_EXIT_CALLBACK

     void USB_EP_0_ISR_ExitCallback();

in cyapicallback.h

and I wrote this function:

void USB_EP_0_ISR_ExitCallback(){

    int length = USB_currentTD.count; 

         if (length == 😎

             for (int i = 0; i< length; i++)

             {

                    Message = USB_currentTD.pData;

             }

}

Which reads the data from the USB_cirrentTD.pData.

The issue is that the data seems to be from be one message late. (I have proved this with a USB analyzer).

Let say I'm sending the messages :

[0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

[0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

[0x52,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

[0x53,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

[0x54,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

What the PSoc see is this :

[0x49,x00,0x00,0x00,0x00,0x00,0x00,0x00] 

[0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

[0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

[0x52,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

[0x53,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

For some reason, it seems that there is a delay of one message, and the message is queued in the USB_EP0_DR_BASE  structure and in the USB_currentTD.pData I read old data.

I proved the above with an USB analyzer, and running the debug in parallel... for example (continuing the example above) I see the message [0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00] on the USB wire, and with the debugger I see that USB_currentTD.pData[0] = 0x49

After the PSoC reset, the first message is always wrong, then the message are consistent, but delayed of one USB message.

Any idea what could be wrong?

do you think the following code is incorrect?

void USB_EP_0_ISR_ExitCallback(){

    int length = USB_currentTD.count; 

         if (length == 😎

             for (int i = 0; i< length; i++)

             {

                    Message = USB_currentTD.pData;

             }

}

Do you think there is something else wrong?

Thank you,

Francesco

0 Likes
1 Reply
Aashita_R
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi Francesco,

1. Can you please let us know if you are trying to send data to the control end point of the device?

2. Can you please attach your project as well as USB Trace? This will help us to understand the issue more properly.

3. Also, how is the data being transferred to the control end point?

We are trying to look into the issue.

Thanks and Regards,

Aashita

0 Likes