UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor vvilly
Visitor
542 Views
Registered: ‎03-26-2019

ZynqMP USB Bare-Metal Driver: Sharing a solution to the problem that XUsbPsu_EpXferComplete() does not return the correct actual number of bytes transferred.

 

Hello,

I'm trying to test a usb vendor-defined device with 2 bulk endpoints on zcu106 evaluation board.

Then I noticed that XUsbPsu_EpXferComplete() does not return the correct actual number of bytes transferred.

 

Simply debugging XUsbPsu_EpXferComplete() function which is endpoint handler in xusbpsu_endpoint.c as shown below.

source_1.PNG

fail_2.PNG

You can see that TrbPtr->Size=1024 and Ept->BytesTxed=0.

Ept->BytesTxed indicates actual number of bytes transferred.

And TrbPtr->Size indicates the number of bytes to be transferred and decreases by the number of bytes actually sent/received.

However, TrbPtr->Size was never decreased.

 

I got a hint by looking at the following sentence in the link below.

https://forums.xilinx.com/t5/Embedded-Processor-System-Design/Zynq-UltraScale-USB-Bare-Metal-Driver-XUsbPsu-EpXferComplete-not/m-p/775508#M20065

"XUsbPsu struct being placed in an incorrect memory location with respect to its 256 byte alignment request. I've fixed that"

 

The TrbPtr->Size is a member of the XUsbPsu_Trb struct, and the address of instance of the XUsbPsu_Trb struct is written in DEPCMDPAR1 register.

The DEPCMDPAR1 register seems to require a 64bytes size aligned address by several tests.

 

Likewise, simply debugging, 

fail_mem_1.PNG

 

fail_mem_2.PNG

 

fail_mem_3.PNG

You can see that the address of XUsbPsu->eps[]->EpTrb[0] is 0x113140 that is aligned 64 bytes in size, but EpTrb[1] and EpTrb[2] are not 64 bytes size aligned address.

 

The source is trying to align the EpTrb array using ALIGNMENT_CACHELINE as below.

However, the elements of EpTrb array were not aligned to a size of 64 bytes as you can see above.

ep_struct.PNG

 

 

Since the elements of the EpTrb array only need to be aligned to 64 bytes, I simply added the padding bytes as shown below to make the XUsbPsu_Trb structure 64 bytes in size.

trb_struct.PNG

When debugging again, you can see the addresses of the elements of EpTrb array are aligned 64 bytes in size as shown below .

ok_mem_1.PNG

 

ok_mem_2.PNG

 

ok_mem_3.PNG

&EpTrb[0] ==> 0x113280,  &EpTrb[1] ==> 0x1132c0,  &EpTrb[2] ==> 0x113300

All three are addresses aligned 64 byte in size.

ok_2.PNG

You can also see that TrbPtr->size is decreased well and Ept->BytesTxed is printed well.

==> It shows that prepared 1024 bytes for transfer and 836 bytes were left, so 188 bytes were received.

 

Thanks for reading.

 

5 Replies
Xilinx Employee
Xilinx Employee
515 Views
Registered: ‎06-21-2018

Re: ZynqMP USB Bare-Metal Driver: Sharing a solution to the problem that XUsbPsu_EpXferComplete() does not return the correct actual number of bytes transferred.

Thanks for sharing that vvilly! Point to the post and Mark it as Accepted Solution, to benefit other users.

Regards,
Andres

0 Kudos
410 Views
Registered: ‎05-23-2018

Re: ZynqMP USB Bare-Metal Driver: Sharing a solution to the problem that XUsbPsu_EpXferComplete() does not return the correct actual number of bytes transferred.

Hi,

I had the exact same problem and your solution fixed all my experienced issues. Thank you for the solution, hopefully Xilinx will fix this in their official bare-metal drivers.

Sincerely,
Erasmus Cedernaes

Visitor chinton
Visitor
374 Views
Registered: ‎05-21-2018

Re: ZynqMP USB Bare-Metal Driver: Sharing a solution to the problem that XUsbPsu_EpXferComplete() does not return the correct actual number of bytes transferred.

This was a great post! I was experiencing this same problem and this solution fixed it for me. I also hope Xilinx updates this in their bare-metal driver soon. Thanks for sharing!

Caleb
Xilinx Employee
Xilinx Employee
203 Views
Registered: ‎06-21-2018

Re: ZynqMP USB Bare-Metal Driver: Sharing a solution to the problem that XUsbPsu_EpXferComplete() does not return the correct actual number of bytes transferred.

Hi all,

A Change Request (CR-1046617) was submitted to reflect your input.

Thanks,
Andres

 

0 Kudos
Visitor broermank
Visitor
138 Views
Registered: ‎08-28-2018

Re: ZynqMP USB Bare-Metal Driver: Sharing a solution to the problem that XUsbPsu_EpXferComplete() does not return the correct actual number of bytes transferred.

vvilly,

Thanks for sharing!  This resolved my Tx and Rx DMA issues with the USB v1.5 BareMetal driver!   Not sure why DMA for the baremetal USB mass storage example seems to work... (?)

Thanks,

Keith