AN87216 buffer mechanism

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

cross mob
WGT_4383351
Level 5
Level 5
First like received

In AN87216:

The expected behavior when PC only send data to master FX3 but doesn't read data from slave FX3 is : When data is send from PC to master FX3, it get transfered to slave FX3 through GPIFII and get saved in a slave DMA buffer. When more data are send to master FX3, more slave DMA buffer are filled with the received data. Finally all allocated slave DMA buffer is filled, then the slave FX3 will signal the master FX3 all buffer are full and can't receive more data. At this time, data send from PC to master FX3 get saved in master FX3's DMA buffer - waiting to get transfered to slave FX3. Finally all master DMA buffer is full too and now the any more XferData() should fail since master FX3 can't receive any more data from PC. More data can only be sent from PC to master FX3 when some data get read away from slave FX3 by PC.

But the real behavior is: Even the PC doesn't read from slave FX3, PC can continue to send data to the master FX3 without failure/timeout, why?  This unexpected behavior means some data get discarded when buffer is full, but where is it get discarded?

0 Likes
1 Solution

Hello,

The result which you saw in your response 2 is expected.

- When you hit Transfer IN in control center for Slave Device and no data is transferred from Master device, you will not get any data transferred to host.

- When you hit Transfer OUT twice in control center for Master Device, data transfer from Host to Master device takes place. This is sent to the slave device through GPIF block. Note that you need to hit it twice when you send 1024 bytes to fill the DMA buffer so that it is committed to the GPIF II block of master device.

- Now, when you hit transfer DATA IN from slave device, it can be seen in the Control Center.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

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

Hello,

Please let me know how you are transferring data to the Master FX3 from the Host. Is it using Control center Application?

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
WGT_4383351
Level 5
Level 5
First like received

Now I have tested with Control center too, same result.

Test method:

(1) Load master and slave firmware to board

(2) Open two control center

(3) Click transfer data in button for slave in one control center to receive 1KB data, it will be blocked since there is no data and will time out soon

(4) Quickly (before slave time out) get to another control center and press transfer data out button for master twice to send 2*1KB data to master.

(5)Switch back to the first control center and wait for the time out(unexpected as described). Then press data in button for slave twice, both 1KB will be received succesfully.

0 Likes

Hello,

The result which you saw in your response 2 is expected.

- When you hit Transfer IN in control center for Slave Device and no data is transferred from Master device, you will not get any data transferred to host.

- When you hit Transfer OUT twice in control center for Master Device, data transfer from Host to Master device takes place. This is sent to the slave device through GPIF block. Note that you need to hit it twice when you send 1024 bytes to fill the DMA buffer so that it is committed to the GPIF II block of master device.

- Now, when you hit transfer DATA IN from slave device, it can be seen in the Control Center.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
WGT_4383351
Level 5
Level 5
First like received

The above response is for this question XferData() doesn't return when data arrives during wait

0 Likes
WGT_4383351
Level 5
Level 5
First like received

Now this question is done. The reason is that FX3 has large RAM so you have to send a lot of data before the full.

0 Likes
WGT_4383351
Level 5
Level 5
First like received
0 Likes
WGT_4383351
Level 5
Level 5
First like received

Need to send 2*1KB is explained above, but what about the time out? Please check that question XferData() doesn't return when data arrives during wait . The expected behavior is, if data arrive during wait before timetout, the read from slave should return OK immediately when data is ready. But the obvserved behavior is it will continue to wait until timeout and return FAIL. The data can only be read on the next time.

0 Likes

Hello,

This is because when you press on DATA In button in control center for an endpoint, the timeout will be 2 seconds. So it will wait for 2 seconds to see whether the endpoint buffer has some data to be transferred to the host. But the data that is to be transferred to the host comes from the Master FX3. It should be transferred from host to OUT endpoint of master FX3 and then to the GPIF II block of master FX3. Then the data should be transferred to the GPIF II block of slave FX3 and fill the DMA buffers allocated with the channel from P port to U Port. Once the buffers are full, then only it will be sent out to the U port. By this time, the timeout would have been exhausted as the GPIF II block is very slow compared to the USB port for data transfers (max clock for GPIF II block is 100 MHz). Due to this, you may not be able to receive the data in the same button press.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
WGT_4383351
Level 5
Level 5
First like received

Please note that I'v send enough data to master FX3 before the timeout.

For example set time out to 10sec or even 100sec and begin receive from slave FX3 and get blocked, then send enough data to master FX3 through another control center since the first control center get blocked, then you have to wait 10 sec or 100sec and fail on the slave FX3, no data is received. You will receive that data on the next read from the slave FX3.

0 Likes

Hello,

Please let me know where did you change the timeout? Did you modify the source of control center?

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
WGT_4383351
Level 5
Level 5
First like received

The speed of GPIF doesn't matter since it is 400MB/s, the data used is only 2KB there won't be any buffer full/speed bottle neck during this process.

0 Likes
WGT_4383351
Level 5
Level 5
First like received

With two control center and fast enough operation, you can observe the above behavior even with 2 second timeout. I press receive and instantly Alt+Tab to another control center and press send for 2 times then switch back.

0 Likes

Hello,

Sorry for making a mistake. The timeout which you mentioned before is the timeout for the data transfer between Host application and endpoint Buffer. It assumes that the endpoint buffer is having some data when you press on DATA IN button. From that point it will wait and check if the data is transferred to host or not. So, if the data is not available in the endpoint buffer when you hit DATA IN, it will result in failure. This is expected behaviour.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
WGT_4383351
Level 5
Level 5
First like received

In fact this behavior can be observed indirectly with Steamer + USBBulkSourceSinkLED firmware.

Set packets per xfer set to 32 and xfers to queue to 16.

First test write, you can get 400MB/s

Then test read with the default 1500ms timtout, the speed is only 10-150MB/s and is jumping high and low, and often stuck for 0.x seconds.

Then set the timeout to 5ms and test read, then you get 350MB/s

The common behavior of an IORX with timeout is, if enough data arrive before timtout, then it success with the data and return immediately. The the expected behavior of the 1500ms should be the same with 5ms since the data are almost always available

0 Likes
WGT_4383351
Level 5
Level 5
First like received

"The timeout which you mentioned before is the timeout for the data transfer between Host application and endpoint Buffer" If this is true, then custom host applicated is need to be discussed. I found this unexpected behavior in a custom C# program using XferData() with 10seconds timeout, same unexpected behavior.

0 Likes
WGT_4383351
Level 5
Level 5
First like received

"The timeout which you mentioned before is the timeout for the data transfer between Host application and endpoint Buffer" How do you know this? This seems to be wrong, checked the source code of control center, there is

curEndpt.TimeOut = 2000;

in the code. So the timeout is exactly the timeout mentioned above.

0 Likes

Hello,

Please let me know whether you developed your own custom host application from scratch for generating the 10s timeout or did you edit the source code of control center for this?

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
WGT_4383351
Level 5
Level 5
First like received

Custom.

0 Likes

Hello,

Can you please change the DMA channel type from AUTO to MANUAL for Auto slave project with callback notification being CY_U3P_DMA_CB_CONS_EVENT. So whenever the data is read from the consumer socket, DMA callback function will be called with the callback type as CY_U3P_DMA_CB_CONS_EVENT. Inside the callback function you can set a variable and print the same in the infinite for loop. This can be used to identify if the CY_U3P_DMA_CB_CONS_EVENT was set or not that is whether the read from the consumer socket was successful or not. You can refer to the FX3 SDK example project USBBulkSrcSink to understand how to change the channel from AUTO to MANUAL and set the callback notification and callback functions. This project can be found in the following location:

C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\basic_examples\cyfxbulksrcsink

Note: This path depends on the installation directory of FX3 SDK.

Once you change the firmware for slave FX3 with the recommendations mentioned above, you can load the modified image into the slave FX3. Now try the test that you performed before that is, hit Transfer DATA IN for slave FX3 and then hit on transfer DATA OUT for master FX3. Now check if you are getting the cons event in the debug logs. If you are getting it, then the data has been successfully read out from the USB socket. Otherwise, the data is not read out from the USB socket.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
WGT_4383351
Level 5
Level 5
First like received

AUTOSIG should be used for this purpose right? Or you have to manually switch buffers.

0 Likes
WGT_4383351
Level 5
Level 5
First like received

A former post said this behavior is not observed using two control centers and stacked boards, the reason may be you did't drain the IN buffer before the test.

0 Likes
WGT_4383351
Level 5
Level 5
First like received

Now I've used AUTOSIG(not MANUAL) and print debug information in the callback. The callback is like:

void

CyFxBulkLpDmaCallback (

        CyU3PDmaChannel   *chHandle, /* Handle to the DMA channel. */

        CyU3PDmaCbType_t  type,      /* Callback type.             */

        CyU3PDmaCBInput_t *input)    /* Callback status.           */

{

    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 DMA transfer will not wait

         * for the commit from CPU. Increment the counter. */

    glDMAP2UProductCount++;

    CyU3PDebugPrint(4,"PROD_EVENT\n");

    }

    if (type == CY_U3P_DMA_CB_CONS_EVENT)

    {

    glDMAP2UConsumeCount++;

    CyU3PDebugPrint(4,"CONS_EVENT\n");

    }

}

Then the result is, there is PROD_EVENT when send 2*1KB to master, but no CONS_EVENT at all. Of course if you receive data after the timeout/fail there will be CONS_EVENT to read the 2KB data successfully.

BTW the uart have some strange characters:

1.jpg

Why?

0 Likes
WGT_4383351
Level 5
Level 5
First like received

Now what is needed is you try the experiment and verify the behavior. Drain the IN endpoint before the experiment

0 Likes
WGT_4383351
Level 5
Level 5
First like received

Test method:

(1) Load master and slave firmware to board

(2) Open two control center

(3) Click transfer data in button for slave in one control center to receive 1KB data, it will be blocked since there is no data and will time out soon

(4) Quickly (before slave time out) get to another control center and press transfer data out button for master twice to send 2*1KB data to master. (Why twice - this is another problem, if you only send 1*1KB, the slave will always timeout. But this have nothing to do with this question, just send 2*1KB - or 1*2KB)

-------PROD_EVENT printed now

(5)Switch back to the first control center and wait for the time out(unexpected as described).

-------no CONS_EVENT printed now

(6)Then press data in button for slave twice, both 1KB will be received succesfully.

-------CONS_EVENT printed now.(on the second press of the button)

You can edit the Control center source code to change the time out from 2sec to longer value too.

0 Likes
WGT_4383351
Level 5
Level 5
First like received

Then the data is successfully put into the slave buffer during wait, you can even send more data during the process, all will print PROD_EVENT, but there are no CONS_EVENT. Then how can there are data in slave buffer but there is no read from the buffer by the USB IN endpoint?

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

Hello,

Please use the following firmware and let me know if you find the same behaviour. I tested this on my end and found that the control center for the slave device could read data when the Transfer IN button was pressed before transfer OUT in the control center for master device.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna
0 Likes
WGT_4383351
Level 5
Level 5
First like received

Still can't see any atachment, but the answer is here: XferData() doesn't return when data arrives during wait

0 Likes