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.

USB3.0 device (gadget) mode support on linux SDK

Other Parts Discussed in Thread: TWL6040

USB3.0 host mode is supported by the "GLSDK 6.03.00.01", it has been mostly work in our environment.
However, Device mode seem to not work with the default configuration. (I can not insmod the gadget driver)

Is there a method of operating a device mode?

  • Hello 39vc,

    To configure the USB driver features trough menuconfig:

    make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig

     Device Drivers --->
     ....
     [ ] HID Devices  --->  
     [*] USB support  --->  

    Configuration

    1. Select USB Gadget support

      Device Drivers --->
      USB support --->
      < >   Support for Host-side USB 
        *** Enable Host or Gadget support to see Inventra options ***
        *** NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may ***
      <*>   USB Gadget Support  ---> 
       *** OTG and related infrastructure ***
        
    

    2. Select device/gadget controller support

    < >   Support for Host-side USB
       <*>   Inventra Highspeed Dual Role Controller (TI, ADI, ...)
            *** Platform Glue Layer ***  
       
     
           Driver Mode (USB Peripheral (gadget stack))  ---> 
      [ ]   Disable DMA (always use PIO)  
      [*]   Enable debugging messages  
       *** NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may *** 
      <*>   USB Gadget Support  --->   
           *** OTG and related infrastructure ***   
    

    3. Select gadget driver, also select USB Peripheral controller

      Device Drivers --->
      USB support --->
      USB Gadget Support --->
      [ ]   Debugging messages (DEVELOPMENT) 
      [ ]   Debugging information files (DEVELOPMENT)
      [ ]   Debugging information files in debugfs (DEVELOPMENT)
          (2)   Maximum VBUS Power usage (2-500 mA
      USB Peripheral Controller (Inventra HDRC USB Peripheral (TI, ADI, ...))  --->
      < >   GPIO based peripheral-only VBUS sensing 'transceiver'
      [ ]   Generic ULPI Transceiver Driver  
         -*-   NOP USB Transceiver Driver
      <M>   USB Gadget Drivers       
      < > Gadget Zero (DEVELOPMENT)  
      < >     Audio Gadget (EXPERIMENTAL)
      < >     Ethernet Gadget (with CDC Ethernet support)
      < >     Gadget Filesystem (EXPERIMENTAL)       
      < >     Function Filesystem (EXPERIMENTAL) 
      <M>     File-backed Storage Gadget    
      [*]       File-backed Storage Gadget testing version
      <M>     Mass Storage Gadget
    
    Installation of File Storage Gadget Driver

    Let us assume that we are interested in exposing /dev/mmcblk0 block device to the file storage gadget device to host (windows/linux). To that effect we need to issue the following command to load the file storage gadget driver. The module parameter buflen can be used set buffersize of the gadget driver for better performance, please refer to /driver/usb/gadget/file_storage.c for more information on module parameters.

     example
     #insmod <g_file_storage.ko> file=/dev/sda1 buflen=65536 stall=0 removable=1
     #insmod <g_file_storage.ko> file=/dev/mmcblk0 stall=0 removable=1
    
    For more information see the link - http://processors.wiki.ti.com/index.php/Usbgeneralpage
    This link describe USB driver configuration for OMAP compatible devices.

    Best regards,
    Yanko
  • Hello, Yanko

    Thank you for quick and detailed answers.
    However, this seems like a method for non OMAP5. Because OMAP5's USB3.0 controller is dwc3.
    Is that correct?

    Best regards,

  • Hi 39vc,

    Yes, USB3 controller in OMAP5 supports dwc3.

    If you want to use USB gadget options, you must  use the menuconfig. Use the following:

    /ti-glsdk_omap5-uevm_6_03_00_01/board-support/linux$ sudo make menuconfig

    Select USB driver and then USB support and will see the picture:

    Select DWC3 mode selection:

    Then select gadget only mode:

    You can see and manage USB gadget options:

    I suggest trying this settings.

    Then use the command insmod <module>.ko

    Best regards,
    Yanko
  • Hello, Yanko

    I've tried to that already. However, after "make" command, ". config" file is overwritten, so it can't be built to a "gadget only mode".
     
    ".config" file after "make menuconfig" command
    ----------------
    CONFIG_USB_DWC3 = m
    # CONFIG_USB_DWC3_HOST is not set
    CONFIG_USB_DWC3_GADGET = y
    # CONFIG_USB_DWC3_DUAL_ROLE is not set
    ----------------

    ".config" file after "make linux" command
    ----------------
    CONFIG_USB_DWC3 = m
    # CONFIG_USB_DWC3_HOST is not set
    # CONFIG_USB_DWC3_GADGET is not set
    CONFIG_USB_DWC3_DUAL_ROLE = y
    ----------------

    My operations are below.

    ----------------
    # export GLSDK = "$ {HOME} / ti-glsdk_omap5-uevm_6_03_00_01"
    # cd $ {GLSDK}
    # make linux_clean # Just in case
    # cd $ {GLSDK} / board-support/linux
    # make menuconfig

    modify to set gadget only mode


    # sudo make linux_install

    ----------------

    Is there my misunderstanding?

    Best regards,

  • Hi 39vc,

    I think that you must not use "make linux" commands. Because this command overrides the changes from menuconfig. 

    When you run "make linux" - this command use $(MAKE) -C $(LINUXKERNEL_INSTALL_DIR) $(LINUXKERNEL_BUILD_VARS) $(DEFAULT_LINUXKERNEL_CONFIG)

    When you made the changes in menuconfig you must only run make the kernel. You need only the new uimage.

    Use the following steps:


    host# cd board-support
    host# cd linux
    host# //edit the defconfig to meet your needs.
    host# //set up your environment
    host# export ARCH=arm
    host# export PATH=<path to GCC>/bin:$PATH
    host# export CROSS_COMPILE=<path to GCC>/bin/arm-linux-gnueabihf-     //check the arm-linux-gnueabihf- part
    host# make omap2plus_defconfig

    host# make menuconfig   - Set the USB gadget support
    host# make uImage
    host# //following is to your wish
    host# make modules
    host# make omap5-dts //see dts file name from original makefile!

    Best regards,

    Yanko

  • Hi, Yanko

    Thanks to your support, I was able to "insmod" the gadget driver.
    But, unfortunately, when that connect to a Host (USB3.0 PC), an error occurs.

    ----------------

    omap5-evm login: root

    root@omap5-evm:~# df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/root             29647940    532080  27603156   2% /
    devtmpfs                924904         4    924900   0% /dev
    tmpfs                    16384       280     16104   2% /var/volatile
    tmpfs                  1023396         0   1023396   0% /dev/shm
    tmpfs                    16384         0     16384   0% /media/ram
    /dev/mmcblk0p1           62495      5090     57406   8% /media/mmcblk0p1
    /dev/sda1             15418304   4194312  11223992  27% /media/sda1  <- USB2.0 Storage Device
    root@omap5-evm:~# cd /lib/modules/3.8.13-00044-g10b8b99-dirty/kernel/drivers/usb/gadget/
    root@omap5-evm:/lib/modules/3.8.13-00044-g10b8b99-dirty/kernel/drivers/usb/gadget# insmod libcomposite.ko
    root@omap5-evm:/lib/modules/3.8.13-00044-g10b8b99-dirty/kernel/drivers/usb/gadget# insmod g_mass_storage.ko file=/dev/sda1 stall=0
    [  127.187164]  gadget: Mass Storage Function, version: 2009/09/11
    [  127.195068]  gadget: Number of LUNs=1
    [  127.199127]  lun0: LUN: file: /dev/sda1
    [  127.203552]  gadget: Mass Storage Gadget, version: 2009/09/11
    [  127.209960]  gadget: userspace failed to provide iSerialNumber
    [  127.216094]  gadget: g_mass_storage ready // Successful insert driver!

    Connect to USB3.0 Host here then error occured.

    ----------------
    root@omap5-evm:/lib/modules/3.8.13-00044-g10b8b99-dirty/kernel/drivers/usb/gadget# [  157.796874] Unable to handle kernel NULL pointer dereference at virtual address 00000020
    [  157.805450] pgd = c0004000
    [  157.808319] [00000020] *pgd=00000000
    [  157.812133] Internal error: Oops: 17 [#1] PREEMPT SMP ARM
    [  157.817810] Modules linked in: g_mass_storage libcomposite snd_soc_spdif_tx dwc3 omapdrm_pvr(O) ehci_omap snd_soc_omap_abe_twl6040 snd_soc_twl6040 ehci_hcd omap_usb3 ahci_platform libahci palmas_usb omap_usb2 dwc3_omap snd_soc_omap_mcpdm snd_soc_omap_abe snd_soc_abe_hal snd_soc_omap_mcasp snd_soc_omap_dmic snd_soc_omap_mcbsp
    [  157.848266] CPU: 0    Tainted: G           O  (3.8.13-00044-g10b8b99-dirty #5)
    .....
    [  158.701995] Fixing recursive fault but reboot is needed!
    ----------------


    Please refer to the attached log for more information.

    Does it work in TI side ?

    Best regards,

    omap5_gadget_driver_log.zip
  • Hello 39vc,


    My suggestion is to try plug other USB3 device.
    Try to enable - xHCI HCD (USB 3.0) support  in menuconfig.

    I assume that it is possible the full USB3.0 functionality not be enabled.

    What is the device, which you plug in USB3 port?

    Although your issue, I want to notice, the known issue for GLSDK - OMAPS00305047: OMAP5: USB: DWC3: usb device plugin on cold start does not get detected and gets detected & workafter unplug/plug of device

    Best regards,

    Yanko

  • Hi, yanko

    > My suggestion is to try plug other USB3 device.
    > Try to enable - xHCI HCD (USB 3.0) support  in menuconfig.
    > I assume that it is possible the full USB3.0 functionality not be enabled.
    > What is the device, which you plug in USB3 port?

    - xHCI HCD (USB 3.0) support  was enabled.
       (reference: attached .config file on previous post)
    - Connected Device: PC (USB3.0 host port, OS: Windows, Linux)
    - Connected Port: OMAP5 USB3.0 OTG port

    > Although your issue, I want to notice, the known issue for GLSDK -
    > OMAPS00305047: OMAP5: USB: DWC3: usb device plugin on cold
    > start does not get detected and gets detected & workafter unplug/plug of
    > device

    My understanding, this issue is function of USB3.0 host mode. When hot start by reset button, no problem in our side.

    I'd like to confirm that OMAP5432 EVM and GLSDK6_03_00_01 supports function of USB3.0 device (gadget) mode (not host mode).

    Best regards,

  • Hello 39vc,

    The USB3.0 module in OMAP5 supports host mode.

    See section - 23.11.4.4.1 xHCI USB Host Software API in OMAP5 TRM. Then check the registers settings in the file - drivers/usb/dwc3/dwc3-omap.c. If it is needed for your USB3.0 use case.

    See the section 23.11.4.14.2 xHCI Host Mapping

    The core host block is subdivided based on the eXtensible Host Controller Interface for USB (xHCI)
    specification, with subblocks mapped at specified offsets of the core host base.
    The constant offset primitives are:
    • Host offset = 0x1 0000
    • CAPLENGTH = 0x20 (readable from hardwired USBOTGSS_CAPLENGTH[7:0] CAPLENGTH register
    bitfield)
    • RTSOFF = 0x440 (readable from hardwired USBOTGSS_RTSOFF[31:0] register)
    • DBOFF = 0x480 (readable from hardwired USBOTGSS_DBOFF[31:0] register)
    • xECP × 4 = 0x220 × 4 (readable from the hardwired USBOTGSS_HCCPARAMS[31:16] XECP register
    bitfield)

    Best regards,

    Yanko

  • Hello, Yanko

    I succeed to use the g_mass_storage gadget driver !!

    Cause of the failure last time, seems to be enabled debug messages.

    Thank you for your great support !!

     ---------------------------

    omap5-evm login: root
    root@omap5-evm:~# mke2fs /dev/ram0  // configured 512MBx1 RAM disk by "make menuconfig"
    root@omap5-evm:~# mkdir -p /mnt/ramdisk
    root@omap5-evm:~# mount /dev/ram0 /mnt/ramdisk
    root@omap5-evm:~# cd /lib/modules/3.8.13-00044-g10b8b99-dirty/kernel/drivers/usb/gadget/
    root@omap5-evm:/lib/modules/3.8.13-00044-g10b8b99-dirty/kernel/drivers/usb/gadget# insmod libcomposite.ko
    root@omap5-evm:/lib/modules/3.8.13-00044-g10b8b99-dirty/kernel/drivers/usb/gadget# insmod g_mass_storage.ko file=/dev/ram0
    [  223.907165]  gadget: Mass Storage Function, version: 2009/09/11
    [  223.916503]  gadget: Number of LUNs=1
    [  223.920593]  lun0: LUN: file: /dev/ram0
    [  223.925537]  gadget: Mass Storage Gadget, version: 2009/09/11
    [  223.931884]  gadget: userspace failed to provide iSerialNumber
    [  223.938323]  gadget: g_mass_storage ready
    root@omap5-evm:/lib/modules/3.8.13-00044-g10b8b99-dirty/kernel/drivers/usb/gadget#

    [  224.157073] g_mass_storage gadget: super-speed config #1: Linux File-Backed Storage
    [  224.273406] g_mass_storage gadget: super-speed config #1: Linux File-Backed Storage
    ....

    USB protocol analyzer's view on write data (PC:HDD -> OMAP5:RAM disk)

    Reference: .config file, log file, build operation
     
     
    However, Current SDK seems to be little unstable. There was a pause in the file copy.
     
    > The USB3.0 module in OMAP5 supports host mode.This means followings ?
     
    - OMAP543x silicon supports the USB 3.0 peripheral (device / gadget) mode but, current SDK software does not support it yet.
     
    Best regards,