FinishDataXfer returns false

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

cross mob
lock attach
Attachments are accessible only for community members.
mary
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

In the bulkloop source code,  in function public unsafe void TransfersThread(), I just change to send out 1024 bytes per time, then inEndpoint.FinishDataXfer will return false, and failed receive the data. the change is as following, there will no problem if set xferLen to 1023 or 1025. I have attached the source code

xferLen = lenOut;

//calls the XferData function for bulk transfer(OUT/IN) in the cyusb.dll
bResult = outEndpoint.XferData(ref outBuffer, ref xferLen);

change to

xferLen = 1024; // has problem

//calls the XferData function for bulk transfer(OUT/IN) in the cyusb.dll
bResult = outEndpoint.XferData(ref outBuffer, ref xferLen);

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

Hi Mary,

Yes. If the data received is not 256KB (in your case) and if it is multiple of 1KB, then the transfer fails.

To summarize again:

In your case, the IN transfer succeeds in below conditions

a. Entire 256KB is sent by device.

b. less than 256KB is sent, but the last packet is a short packet (size less than 1024 bytes).

c. less than 256KB is sent, but the last packet is a zero length packet.

Regards,

Hemanth

View solution in original post

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

Hi,

Which firmware are you using on the device? What device controller are you using?

Regards,

Hemanth
0 Likes
mary
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

Hi Hemanth,

The firmware I use is USBBulkLoopAuto, device controller is bulkloop.

mary_0-1628069262086.png

And I found the XferData function also has same problem, I test with  USB Control Center

1. send out 1024 byte

mary_1-1628069523220.png

2. read 1025 bytes, XferData will return false

mary_2-1628069590026.png

3. but if I send out 1023 bytes, then read 1025 bytes, XferData will return true

Since in my project, the data length sending out by firmware is not fixed, so the parameters len of function  XferData(ref byte[] buf, ref int len) or BeginDataXfer(ref byte[] singleXfer, ref byte[] buffer, ref int len, ref byte[] ov) is large than the data sending out by firmware, it can be received successfully if firmware sends out 1023 or 1025 bytes, but if firmware sends out 1024 byte, the reception will fail

Looking forward to your reply, thank you!

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

Hi,

Please see the thread https://community.cypress.com/t5/USB-Superspeed-Peripherals/XferData-may-return-FALSE-in-short-packe...

You can see the condition for which a transfer(made by the host) ends.

Regards, 

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

Adding to my last post:
The IN transfer initiated from the host ends under following conditions

a. All the requested data is sent by the device OR
b. less than requested data is sent by device BUT the last sent packet from the device is a short packet (not maxpacket size)
c. less than requested data is sent by the device BUT last sent packet from the device is Zero length packet (ZLP)

Regards,

Hemanth
0 Likes
mary
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

Hi Hemanth,

Thanks for your reply.

Do you mean the problem will be resolved by sending a ZLP after sending the 1024 bytes data? I will try this solution with our FPGA engineers.

Thanks,

Mary

 

 

0 Likes
mary
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

Hi Hemanth,

How to send a ZLP, and how does the PC confirm that the firmware has sent a ZLP?

0 Likes
mary
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

Hi Hemanth,

My inEndpoint.MaxPktSize is 16384, in buffer size is 16384 * 256, our FPGA change to send a ZLP if the sending data length is multiples of 16384, then the question that receive data failed if the data length is  multiples of 16384 has been solved , but if the sending length is multiples of 1024 but not multiples of 16384, reception still fails, should the PGA change to send a ZLP if the sending data length is multiples of 1024?

Thanks,

Mary

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

Hi Mary,

Do you mean buffer size on your host application is 256*16KB?

Regards,

Hemanth
0 Likes
mary
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

Hi Hemanth,

Yes, the buffer size on host application is 256*16KB, inEndpoint.MaxPktSize is 16KB

Thanks,

Mary

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

Hi Mary,

Yes. If the data received is not 256KB (in your case) and if it is multiple of 1KB, then the transfer fails.

To summarize again:

In your case, the IN transfer succeeds in below conditions

a. Entire 256KB is sent by device.

b. less than 256KB is sent, but the last packet is a short packet (size less than 1024 bytes).

c. less than 256KB is sent, but the last packet is a zero length packet.

Regards,

Hemanth
0 Likes