Any synchronize mechanism between FX3 Firmware and host application?

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

cross mob
Wellington
Level 4
Level 4
100 sign-ins 50 sign-ins 25 replies posted

Hi,

My application are video streaming, where we will send frame request from Host application -> Firmware -> FPGA.

FPGA will then start trigger Frame Valid and line valid back to Firmware. Firmware then passback the data to host application.

The application are running fine but we still observe out of 1000 frame there would be around 10 fail frame at random interval. Our requirement are not allowed any fail frame.

I found the problem where when host application call xferdata(), it return true. But the rlen value only grab partial data.

I have checked my FPGA using the oscilloscope and it did send out a full frame data during the failed case. It seems like somewhere in Firmware was failed to received/send the data.

1.) Do you have any suggestion on this?

2.) Can we implement any synchronize mechanisim for this problem? (such as keep checking the current dma status busy/no busy and continuous report back the status to host)

3.) I have tried to implement CY_U3P_DMA_TYPE_MANUAL_MANY_TO_ONE but no luck get it working.

 

The size of my data transfer are 8,454,144 bytes and i am using cyusb3_win10_x64_1.2.3.25 Driver provided by cypress.

My DMA configuration as below(using CY_U3P_SUPER_SPEED/Bulk in transfer):

CyU3PMemSet((uint8_t *)&dmaCfg, 0, sizeof(dmaCfg));

dmaCfg.size = 16*1024;
dmaCfg.count = 6;
dmaCfg.validSckCount = 2;
dmaCfg.prodSckId[0] = (CyU3PDmaSocketId_t)CY_U3P_PIB_SOCKET_0;
dmaCfg.prodSckId[1] = (CyU3PDmaSocketId_t)CY_U3P_PIB_SOCKET_1;
dmaCfg.consSckId[0] = (CY_U3P_UIB_SOCKET_CONS_3);
dmaCfg.prodAvailCount = 0;
dmaCfg.prodHeader = 0;
dmaCfg.prodFooter = 0;
dmaCfg.consHeader = 0;
dmaCfg.dmaMode = CY_U3P_DMA_MODE_BUFFER;
dmaCfg.notification = CY_U3P_DMA_CB_PROD_EVENT| CY_U3P_DMA_CB_CONS_EVENT;
dmaCfg.cb = CyFxApplnDmaCallback;
apiRetStatus = CyU3PDmaMultiChannelCreate(&glChHandleMultiCh,
CY_U3P_DMA_TYPE_AUTO_MANY_TO_ONE, &dmaCfg);

0 Likes
1 Solution

Hello,

From the traces (AUTO_MANY_TO_ONE) I found that the USB transfers did not fail ( but short packets are committed to USB.

auto_frame_SP.PNG

The reason can be the changed that are done to the GPIF state machine. I had checked  the GPIF state machine and found some issues. I will help you with the changes in the GPIF state machine as per your requirement.

Regards,
Rashi

View solution in original post

0 Likes
5 Replies
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

To understand the reason of the failure please share the wireshark traces (.pcap).

Please let me know the reason of using dmaCfg.dmaMode = CY_U3P_DMA_MODE_BUFFER; 

Also let me know if UART prints can be captured.

If yes, please try switching to CY_U3P_DMA_TYPE_MANUAL_MANY_TO_ONE and dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE  and track the  CY_U3P_DMA_CB_PROD_EVENT and  CY_U3P_DMA_CB_CONS_EVENT events using global variables in the DMA callback. Also try to check if for any DMA buffer (i.e. when producer event is seen) the DMA buffer is partially filled. It can be checked as follows:

if(dmaBuffer.count < CX3_UVC_DATA_BUF_SIZE)
{

partial_buffer++

}

This will help us to check how many DMA buffers are consumed. 

As it is not recommended to use the CyU3PDebugPrint in the DMA callback, please print the variables value in the thread entry function (i.e. inside for loop for(;;)).

 

Please confirm AN75779 firmware is used as the base of your application and if the GPIF state machine with AN75779 is being used.

Regards,
Rashi
0 Likes

HI Rashi,

Thanks for your suggestion. I have manage to code manual mode using AN75779 example.

1.) What is the size of CX3_UVC_DATA_BUF_SIZE you mention above?

 

2.) Below are my configuration and CB():

CyU3PMemSet((uint8_t *)&dmaCfg, 0, sizeof(dmaCfg));
#ifdef DEBUG_PRINT
CyU3PDebugPrint (4, " sizeof (dmaCfg) = %d\r\n", sizeof (dmaCfg));
#endif

dmaCfg.size = 16*1024;//burstLength*size;//16* size; //16*1024
dmaCfg.count = 4;
dmaCfg.validSckCount = 2;
dmaCfg.prodSckId[0] = (CyU3PDmaSocketId_t)CY_U3P_PIB_SOCKET_0;
dmaCfg.prodSckId[1] = (CyU3PDmaSocketId_t)CY_U3P_PIB_SOCKET_1;
dmaCfg.consSckId[0] = (CY_U3P_UIB_SOCKET_CONS_3);
dmaCfg.prodAvailCount = 0;
dmaCfg.prodHeader = 0;
dmaCfg.prodFooter = 0;
dmaCfg.consHeader = 0;
dmaCfg.dmaMode = CY_U3P_DMA_MODE_BUFFER; //Tried CY_U3P_DMA_MODE_BYTE makes no different.
dmaCfg.notification = CY_U3P_DMA_CB_PROD_EVENT| CY_U3P_DMA_CB_CONS_EVENT;
dmaCfg.cb = CyFxApplnDmaCallback;
apiRetStatus = CyU3PDmaMultiChannelCreate(&glChHandleMultiCh,
CY_U3P_DMA_TYPE_MANUAL_MANY_TO_ONE, &dmaCfg);

void CyFxApplnDmaCallback(CyU3PDmaMultiChannel *multiChHandle, CyU3PDmaCbType_t type, CyU3PDmaCBInput_t *input)
{
//CyU3PDmaBuffer_t dmaBuffer = &(input->buffer_p);
CyU3PDmaBuffer_t * produced_buffer = &(input->buffer_p);
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
//rename dmaBuffer into produced_buffer
if (type == CY_U3P_DMA_CB_PROD_EVENT)
{
/* This is a produce event notification to the CPU. This notification is received upon reception of
* every buffer. The buffer will not be sent out unless it is explicitly committed. The call shall fail
* if there is a bus reset / usb disconnect or if there is any application error.
*/

#ifdef FRAME_TIMER_ENABLE
/* Received data from the sensor so stop the frame timer */
CyU3PTimerStop(&UvcTimer);

/* Restart the frame timer so that we receive the next buffer before timer overflows */
CyU3PTimerModify(&UvcTimer, glFrameTimerPeriod, 0);
CyU3PTimerStart(&UvcTimer);
#endif

/* There is a possibility that CyU3PDmaMultiChannelGetBuffer will return CY_U3P_ERROR_INVALID_SEQUENCE here.
* In such a case, do nothing. We make up for this missed produce event by making repeated commit actions
* in subsequent produce event callbacks.
*/

status = CyU3PDmaMultiChannelGetBuffer (&glChHandleMultiCh, produced_buffer, CYU3P_NO_WAIT);

while (status == CY_U3P_SUCCESS)
{
if (produced_buffer->count == 16384) //Full buffer
{
#ifdef DEBUG_PRINT_FRAME_COUNT
glFrameCount++;
glDmaDone = 0;
#endif

/* Commit Buffer to USB*/
status = CyU3PDmaMultiChannelCommitBuffer(&glChHandleMultiCh, produced_buffer->count, 0);
if (status == CY_U3P_SUCCESS)
{
#ifdef DEBUG_PRINT_FRAME_COUNT
glDmaDone++;
#endif
}
else
{
//Variable to track whether the reason for DMA Reset is Frame Timer overflow or Commit Buffer Failure
//if(glDmaResetFlag == CY_FX_UVC_DMA_RESET_EVENT_NOT_ACTIVE)
//{
// glDmaResetFlag = CY_FX_UVC_DMA_RESET_COMMIT_BUFFER_FAILURE;
// CyU3PEventSet(&glFxUVCEvent, CY_FX_UVC_DMA_RESET_EVENT, CYU3P_EVENT_OR);
//}
//break;
}
}
else //not full buffer
{
#ifdef DEBUG_PRINT_FRAME_COUNT
glFrameHalfCount++;
glDmaHalfDone = 0;
#endif
status = CyU3PDmaMultiChannelCommitBuffer(&glChHandleMultiCh, produced_buffer->count, 0);
if (status == CY_U3P_SUCCESS)
{
#ifdef DEBUG_PRINT_FRAME_COUNT
glDmaHalfDone++;
#endif
}
//status = CyU3PDmaMultiChannelGetBuffer (&glChHandleMultiCh, produced_buffer, CYU3P_NO_WAIT);
}
/* Check if any more buffers are ready to go, and commit them here. */
status = CyU3PDmaMultiChannelGetBuffer (&glChHandleMultiCh, produced_buffer, CYU3P_NO_WAIT);
}


}
else if (type == CY_U3P_DMA_CB_CONS_EVENT)
{
//streamingStarted = CyTrue;// toggle of video stream has started in host end.
//glCommitBufferFailureCount = 0; /* Reset the counter after data is consumed by USB */
}
}

Attached Wireshark log on manual mode pcture(Sorry, this forum seems like updated not able to upload .pcapng file type)

Wellington_0-1612751770383.png

My full size data are 8454144 bytes. My video able to display but is extremely slow(around 15 second one frame) and the UART print log not able to print anything when doing live due to this slowness. Do you have any idea on this?

Note: *On Manual mode, i am able to display normal speed when input small size 18432 bytes and UART Print is able to capture debug message log.

* On Auto Mode, i am able to display normal speed when input Full size 8454144 bytes.

* I have tried using CY_U3P_DMA_MODE_BYTE, i dont think it makes any different in terms of frame rate

 

Sorry, i not able to answer you why we use CY_U3P_DMA_MODE_BUFFER instead of BYTE, the code is kind of work pass from previous developer. I have tried both BUFFER and BYTE mode it seems like makes no different.

My State machine are similar to SVC application but there are extra two state added. Could you leave your email here so i can send you the state machine configuration for more understanding?

 

Thanks

ZY

 

 

 

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

1.) What is the size of CX3_UVC_DATA_BUF_SIZE you mention above?

>> It is same as the DMA buffer size in your case 16384

Please uncomment the following code

else
{
//Variable to track whether the reason for DMA Reset is Frame Timer overflow //or Commit Buffer Failure
if(glDmaResetFlag == CY_FX_UVC_DMA_RESET_EVENT_NOT_ACTIVE)
{
 glDmaResetFlag = CY_FX_UVC_DMA_RESET_COMMIT_BUFFER_FAILURE;
 CyU3PEventSet(&glFxUVCEvent, CY_FX_UVC_DMA_RESET_EVENT, CYU3P_EVENT_OR);
}
break;

Also, add this code to the else condition of partial buffer condition.

Attached Wireshark log on manual mode pcture(Sorry, this forum seems like updated not able to upload .pcapng file type)

>> Could please zip the .pcap files and then attach it to the post.

 

My full size data are 8454144 bytes. My video able to display but is extremely slow(around 15 second one frame) and the UART print log not able to print anything when doing live due to this slowness. Do you have any idea on this?

>> As in the main thread description, you mentioned that some video data is lost/ frame fail. Is that problem still happening or is it only the low FPS problem? Are they two different problems seen 1) data loss (frame fail) 2) low fps/ streaming or are both the problems same?

Please let me know the video resolution, bits/pixel and fps that you are trying to stream

* On Auto Mode, i am able to display normal speed when input Full size 8454144 bytes.

>> Does this mean when in AUTO mode there are no issues seen and the video streaming is as expected

 I have tried using CY_U3P_DMA_MODE_BYTE, i dont think it makes any different in terms of frame rate

>> Can you please change to CY_U3P_DMA_MODE_BYTE for the tests as it is the default mode

Regards,
Rashi
0 Likes
lock attach
Attachments are accessible only for community members.

As in the main thread description, you mentioned that some video data is lost/ frame fail. Is that problem still happening or is it only the low FPS problem?

-> Yes, it is still happening on AUTO mode. Attached AUTO MANYTOONE wireshark log. As we tried 300++ continous frame, we observed 6 failed. Once again we have probed The FPGA during fail frame, it is sending out correct full data. On the wireshark side it is reported the data not able to grabbed full. We have no idea whats wrong on the FX3 side.

 Are they two different problems seen 1) data loss (frame fail) 2) low fps/ streaming or are both the problems same?

AUTO mode only have Data loss problem

Manual mode have low fps problem. (Yet to find Data loss at this moment as the fps is very low to find out)

 

Please let me know the video resolution, bits/pixel and fps that you are trying to stream

>> Video resolution: Width x Height x 2 : 2064 x 2048 x 2.  One pixel is 16bits

Does this mean when in AUTO mode there are no issues seen and the video streaming is as expected

>>This means AUTO mode has only issue above which have random fail frame. The frame rate and display are smooth.

 

>> Can you please change to CY_U3P_DMA_MODE_BYTE for the tests as it is the default mode

Sure, attached wireshark log are captured using CY_U3P_DMA_MODE_BYTE

0 Likes

Hello,

From the traces (AUTO_MANY_TO_ONE) I found that the USB transfers did not fail ( but short packets are committed to USB.

auto_frame_SP.PNG

The reason can be the changed that are done to the GPIF state machine. I had checked  the GPIF state machine and found some issues. I will help you with the changes in the GPIF state machine as per your requirement.

Regards,
Rashi
0 Likes