This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM5726: USB video stream fails with 3KB packet size

Part Number: AM5726

Tool/software: Linux

Hi ,

We are using the AM572x board.

Linux Kernel version - 4.4.41

And we are not able stream video if usb packet size set to 3k but it is working for 1K.

Please let me know any Idea.

Reagrds

Mahesh Kalmeshwar 

  • The software team have been notified. They will respond here.
  • Mahesh,

    I need more information to understand your use case.
    AM57x USB in host mode or device mode?
    How do you specify the 3k packet size? Please describe the exact steps/commands for how you tested it.
  • Hi Bin,
    it is in device mode .
    while loading driver webcam passing parameter as steaming_maxpacket=3062.
  • Mahesh,

    This feature is not implemented until TI v4.9 kernel, so please use the latest Processor Linux SDK v4.0 to have this feature.

  • Hi Bin,

    Is this usb device mode works as usb.30 ?

    if yes how do I configure driver to use usb3.0 interface.

  • mahesh kalmeshwar said:
    Is this usb device mode works as usb.30 ?

    Yes.

    mahesh kalmeshwar said:
    if yes how do I configure driver to use usb3.0 interface.

    The g_webcam gadget driver supports usb3.0 super-speed, you don't need any software configuration change, it should work as long as you bring out usb3.0 data signal pins to the receptacle.

  • We are using EVM board(AM572x),Is this board default works as USB3.0(Gadget) ?
  • No, the AM572x EVM uses USB2.0 micro-B receptacle, so this board doesn't support super-speed device mode.
  • Hi Bin,

    AM572x EVM without any change in hardware, host USB3.0 can be configured as device mode?
    if ans yes, please let me know what are the configuration changes required to stream video.
  • Unfortunately no, one of the reasons is that there is a usb hub on the evm and the usb controller is connected to the hub upstream port.
  • Hi Bin,

    Thank you for info.
    Please let me know ,Is any TI EVM board which can support USB3.0 (gadget).
  • Currently AM57x doesn't have any TI EVM which supports super-speed gadget mode. But please check

    www.ti.com/.../j6evm5777

    the link above shows a J6 EVM which supports USB super-speed gadget mode. The EVM uses DRA74x device, which has the same USB controller as that on AM57x.

    Please note that the J6 EVM and DRA74x devices belong to TI Automotive business. Those are not supported on this Sitara forum.
  • Hi Bin,
    Thank you for information.
  • Hi Bin,
    "bring out usb3.0 data signal pins to the receptacle."
    Please let me know in details how to do this.
  • Hi,
    Let me know which document need to refer for to make changes " bring out usb3.0 data signal pins to the receptacle"
  • mahesh kalmeshwar said:
    "bring out usb3.0 data signal pins to the receptacle."
    Please let me know in details how to do this.

    I meant to use super-speed micro-B or micro-AB receptacle on your design, then connect the super-speed USB rx/tx pins from AM5726 to the receptacle, so that you can use super-speed.

  • Hi,

    Plz let me know where I will get board schematic.

  • Bin,

    please see my offline mail regarding this post.

    Regards, Bernd

  • mahesh kalmeshwar said:
    Plz let me know where I will get board schematic.

    We don't have any AM57x board which has USB super-speed port, so there is no board schematics we can share.

    The USB is a point-to-point connection, you will have to bring up all the USB related pins from AM57x to the super-speed receptacle, you can follow our USB design checklist, AM57x TRM, and the USB3.0 Specs.

  • AM57xx Schematic Checklist is placed on Wiki here: http://processors.wiki.ti.com/index.php?title=AM57xx_Schematic_Checklist

    Regards, Bernd

  • Hi Bin,

    This is regarding some inconsistencies with the TI USB gadget controller (DWC3) especially in 3K mode.
    We are using a custom gadget driver but similar scenario is easily reproducible with the below steps on the default USB gadget driver on TI platform.

    Hardware: TI AM572X EVM
    SDK: software-dl.ti.com/.../ti-processor-sdk-linux-am57xx-evm-04.00.00.04-Linux-x86-Install.bin

    Steps to reproduce the issue
    1.Download TI linux kernel source 4.9.28 (above SDK link)

    2.Apply Patch for gadget driver - webcam.c (support NV12 format)
    2.1 Apply patch 0001_Ti_gadget_driver_NV12_support.patch
    $ patch -p0 < 0001_Ti_gadget_driver_NV12_support.patch
    path for webcam.c = ti-processor-sdk-linux-am57xx-evm-04.00.00.04/board-support/linux-4.9.28+gitAUTOINC+eed43d1050-geed43d1050/drivers/usb/gadget/legacy

    3.Compilation of gadget driver - webcam.c (precompiled binary attached - g_webcam.ko)
    $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- SUBDIRS=drivers/usb/gadget/legacy/

    4. Compile Application (precompiled binary attached - uvcgadget)
    4.1 Attached is modified application source code - uvc-gadget.c (attached)
    4.2 Use the attached MAKEFILE to build application (Update KERNEL_DIR, CROSS_COMPILE, ARCH)
    4.3 Update path of uvc.h in uvc-gadget.c
    4.3 Cross-Compile UVC gadget application for TI platform
    $ make

    5. Copy binaries to SD card
    5.1 Copy 'g_webcam.ko' to /media/user/rootfs/lib/modules/4.9.28/kernel/drivers/usb/gadget/legacy/
    5.2. Copy 'uvcgadget' executable /media/user/rootfs/home/root/
    5.3. Copy sample NV12 image to /media/user/rootfs/home/root/

    6. Insert SD card and power ON the TI platform AM572X

    7. Execution (working scenario 1k mode)
    $ modprobe libcomposite
    $ modprobe g_webcam
    $ ./uvcgadget -d /dev/videoX -i <NV12-image-file-name>
    eg: $./uvcgadget -d /dev/video1 -i 1280x720.yuv
    $./uvcgadget -d /dev/video1 -i 640x360.yuv
    Run VLC(2.1.2) on the streaming linux PC and start the stream with the corresponding YUV resolution 1280x720 (or) 640x360
    Result: Image streams

    8. Execution (non working scenario 3k mode)
    $ modprobe libcomposite
    $ modprobe g_webcam
    $ modprobe g_webcam streaming_maxpacket=3062
    $ ./uvcgadget -d /dev/videoX -i <NV12-image-file-name>
    eg: $./uvcgadget -d /dev/video1 -i 1280x720.yuv
    $./uvcgadget -d /dev/video1 -i 640x360.yuv
    Run VLC(2.1.2) on the streaming linux PC and start the stream with the corresponding YUV resolution 1280x720 (or) 640x360.
    Result: Image does not streams

    Issues:
    1. Data transfer happens without loss but host reports error (-EPROTO returned by host controller) for every last packet of a frame.
    Note:
    This is observed for only 3k mode.
    The issue is not seen when the same app and driver code is used on other arm platform (Non TI) for 3K mode.

    2. Warning at gadget TI platform while streaming image for 3062 bytes as streaming_maxpacket (Attached kernel log - warn.txt).

    3. Need to be able to run the driver in streaming_maxpacket=3072 as the camera supports full hd with 3072 packet size to achieve max throughput.

    Queries:
    1. What are the limitations for maxpacket while loading the driver with the parameter streaming_maxpacket.
    The custom driver we use can stream 720P when driver is loaded with maxpacket 2688 or less than 1K (eg: 944) but fails when set to 3062.
    Most resolutions fail when maxpacket is 3062 but work fine when set default 1024 or less.

    NV12_Support.tar

  • Mahesh,
    our experts will look at this.

    Regards, Bernd
  • Mahesh,

    mahesh kalmeshwar said:
    This is observed for only 3k mode.
    The issue is not seen when the same app and driver code is used on other arm platform (Non TI) for 3K mode.

    Do you know what is the USB IP on the other arm platform? Is it also dwc3?

    What is the Linux kernel version in this test?

    Does the test pass on other arm platform with maxpacket=3072 too?

    I'd like to understand the difference between the TI AM57x and the other arm platform to narrow down the issue.

    mahesh kalmeshwar said:
    1. What are the limitations for maxpacket while loading the driver with the parameter streaming_maxpacket.

    This needs to be understood more. The last time I looked at the USB bus packets but didn't observe anything obviously wrong.

  • Hi Bin,
    Platform used : IMX6qp.
    USB IP : ChipIdea.
    Linux Kernel: 4.1.xx.
    In this platform 3k(3072) packet size is working.
  • Mahesh,

    It appears the 3072 maxpacket size issue is already solved in the mainline dwc3 driver since kernel v4.13. I am trying to find out which patches are related to the issue and back port them to TI v4.9.28 kernel. It seems there are more than one patch. I will keep you posted.
  • Mahesh,

    Please apply the patch attached below to TI v4.9 kernel which solves the streaming_maxpacket=3072 issue. It is a manual backport from the mainline kernel.

    From 15b9e8642a3ce2d4e1ef083f219ac78e2294b97d Mon Sep 17 00:00:00 2001
    From: Manu Gautam <mgautam@codeaurora.org>
    Date: Wed, 19 Jul 2017 17:07:10 +0530
    Subject: [PATCH] usb: dwc3: gadget: Correct ISOC DATA PIDs for short packets
    
    commit 40d829fb2ec636b6b4b0cc95e2546ab9aca04cc9 upstream.
    
    The PIDs for Isochronous data transfers are incorrect
    for high bandwidth IN endpoints when the request length
    is less than EP wMaxPacketSize.
    
    As per spec correct PIDs for ISOC data transfers are:
    
    1) For request length <= maxpacket
    	- DATA0,
    
    2) For maxpacket < length <= (2 * maxpacket)
    	- DATA1, DATA0
    
    3) For (2 * maxpacket) <  length <= (3 * maxpacket)
    	- DATA2, DATA1, DATA0.
    
    But driver always sets PCM fields based on wMaxPacketSize
    due to which DATA2 happens even for small requests.
    
    Fix this by setting the PCM field of trb->size depending
    on request length rather than fixing it to the value
    depending on wMaxPacketSize.
    
    Ideally it shouldn't give any issues as dwc3 will send
    0-length packet for next IN token if host sends (even
    after receiving a short packet). Windows seems to ignore
    this but with MacOS frame loss observed when using f_uvc.
    
    Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
    Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
    Cc: stable@vger.kernel.org # v4.9 only
    [b-liu@ti.com added following change for v4.9.]
    
    -	unsigned int maxp = usb_endpoint_maxp(ep->desc);
    +	unsigned int maxp;
    +	maxp = usb_endpoint_maxp(ep->desc) & 0x07ff;
    
    Signed-off-by: Bin Liu <b-liu@ti.com>
    ---
     drivers/usb/dwc3/gadget.c | 35 ++++++++++++++++++++++++++++++++++-
     1 file changed, 34 insertions(+), 1 deletion(-)
    
    diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
    index 0546fb60d095..b1dbf2d65553 100644
    --- a/drivers/usb/dwc3/gadget.c
    +++ b/drivers/usb/dwc3/gadget.c
    @@ -817,9 +817,42 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
     		if (!node) {
     			trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS_FIRST;
     
    +			/*
    +			 * USB Specification 2.0 Section 5.9.2 states that: "If
    +			 * there is only a single transaction in the microframe,
    +			 * only a DATA0 data packet PID is used.  If there are
    +			 * two transactions per microframe, DATA1 is used for
    +			 * the first transaction data packet and DATA0 is used
    +			 * for the second transaction data packet.  If there are
    +			 * three transactions per microframe, DATA2 is used for
    +			 * the first transaction data packet, DATA1 is used for
    +			 * the second, and DATA0 is used for the third."
    +			 *
    +			 * IOW, we should satisfy the following cases:
    +			 *
    +			 * 1) length <= maxpacket
    +			 *	- DATA0
    +			 *
    +			 * 2) maxpacket < length <= (2 * maxpacket)
    +			 *	- DATA1, DATA0
    +			 *
    +			 * 3) (2 * maxpacket) < length <= (3 * maxpacket)
    +			 *	- DATA2, DATA1, DATA0
    +			 */
     			if (speed == USB_SPEED_HIGH) {
     				struct usb_ep *ep = &dep->endpoint;
    -				trb->size |= DWC3_TRB_SIZE_PCM1(ep->mult - 1);
    +				unsigned int mult = ep->mult - 1;
    +				unsigned int maxp;
    +
    +				maxp = usb_endpoint_maxp(ep->desc) & 0x07ff;
    +
    +				if (length <= (2 * maxp))
    +					mult--;
    +
    +				if (length <= maxp)
    +					mult--;
    +
    +				trb->size |= DWC3_TRB_SIZE_PCM1(mult);
     			}
     		} else {
     			trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS;
    -- 
    1.9.1
    
    

  • Hi Bin,

    Will update soon.

    where shall I get 4.13.xx kernel version for AM572x,

    http://www.ti.com/tool/processor-sdk-am57x 

  • The latest TI kernel is on v4.9.
    I got v4.13 kernel from kernel.org.
  • Thank you bin.

    the new patch is working now. 

    New query:

    1. Audio and video is separately working.

    2.Integrated Audio and video is not working(simultaneously).

  • Mahesh,

    Glad this issue is solved. Thanks for the update.

    Can you please create a post about this audio/video integration issue? What is the testcase and how it fails?
  • Thanks Mahesh, let's close this thread and move the conversation to the new thread.