Back-to-back USB Commands

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

cross mob
GrSe_4664521
Level 2
Level 2

I have an application which sets register values in an FPGA using the SPI out of the FX3.  Those register writes are initiated by the PC application over the USB interface to a control endpoint.  After writing the register (which starts a DMA in to the GPIF port) I initiate a bulk read over a different endpoint to get the image data.  If I don't insert a delay after the register write the bulk read to the image endpoint fails with WinUSB setting an error in the overlapped read request.  I have two questions:

     1) What happens to a USB request if a previous request is still being processed?  Is the callback delayed or does it execute but necessarily fail?

     2) Other than inserting a delay in the application after performing the register write how can I tell if the FX3 is ready to accept a USB command?

Thanks,

Greg

0 Likes
1 Solution

Hello,

Please let me know which vendor command of USBBulkSrcSink are you referring to. In your case, the data coming from the host application through control endpoint is to be written to FPGA through SPI interface. This will take some delay. So, you should not perform this operation in the callback function.Alternatively, you can set an event when a write command is received. Then you can store the data to be written to the FPGA in a global buffer. You can get the event in the infinite for loop and then send the buffer to the FPGA through SPI. After this process is complete only, FX3 receives data from the FPGA. So, you can use any of the methods mentioned in my previous response to inform the host that FX3 has completed the write to FPGA.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

0 Likes
5 Replies
JayakrishnaT_76
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hello,

Please find my comments below:

1. If a USB request is issued from the host when a previous request is being handled, then it will queue up in the bus until the first request is processed completely. This can delay the callback for the second USB request. The second request will be executed and may or may not fail depending on the request.

2. According to my understanding, the FPGA will send out data only after the SPI writes are complete. Due to this, you should need a delay between SPI write control transfer and the Bulk Read request. Other than adding a delay you can try the following:

a. Increase the timeout for IN transfer. While performing this, make sure that the LPM is disabled throughout the project.

b. Continuously polling the device using a vendor command to check if the flash write is complete or not., If the flash write is complete, the device can return one value to the host and if the flash write is not successful, then the device can return another value to the host. This returned value can be checked in the application. When the flash write is successful, you can send the Bulk read requests to the device.

Please try this and let us know the result.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

The register write to the FPGA initiates the DMA but the bulk read, i.e., WinUSB_ReadPipe(), is performed with a pointer to an OVERLAP structure so it is an asyncrhonous operation which completes later.  The event is triggered that it has completed but with an error code indicating that the operation was not valid.  The operation is actually valid which implies that the FX3 responded that it could not perform the operation.  With the delay this does not happen.  It seems like the FX3 is in the middle of completing the FPGA register write (which occurs on the SPI port of the FX3) and responds with an error code to the bulk read command.  The code example being used is cyfxbulksrcsink which responds to USB vendor commands from within a callback.  Is that the problem?  Should this processing be done outside the callback?  I have heard from others that performing processing in the callback can be problematic.  If that is the case why would the example do the processing from the callback when real applications cannot do it that way?  The examples are the only thing that designers have to go on, there is no actual documentation for the FX3 that explains things.  Searching this forum it seems that almost all answers refer to an example to use.

0 Likes

Hello,

Please let me know which vendor command of USBBulkSrcSink are you referring to. In your case, the data coming from the host application through control endpoint is to be written to FPGA through SPI interface. This will take some delay. So, you should not perform this operation in the callback function.Alternatively, you can set an event when a write command is received. Then you can store the data to be written to the FPGA in a global buffer. You can get the event in the infinite for loop and then send the buffer to the FPGA through SPI. After this process is complete only, FX3 receives data from the FPGA. So, you can use any of the methods mentioned in my previous response to inform the host that FX3 has completed the write to FPGA.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes

Ok, moving everything out of the callback is a lot of work.  I'm still at a loss as to why the published examples would do the processing in the callback is that is not how it should be done.  Shouldn't the examples be examples of the correct way to do things?

0 Likes

Hello,

Please let me know which vendor command you are referring to in the USBBulkSrcSink Example.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes