Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

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.

J6EVM5777: Adding USB Gadget on J6 (Android OS) with NCM support

Part Number: J6EVM5777

On the J6, I'm trying to do a USB role switch (host -> device) from the USB 2.0 port and create a USB Gadget with multiple interfaces but running into a few problems.

When I plug a iPhone using the USB 2.0 port using the Male Mini-B to Female Standard A USB Adapter, The J6 acts as a host and correctly detects the smartphone and shows a relevant popup to choose how to connect to the phone. So the "host" part works fine.

I am tring to do a role switch so the J6 is not a "device" and would like to create a gadget (or a slave) that has a configuration with following interfaces.
- Custom Bulk IN/OUT
- USB NCM control interface
- USB NCM data interface

Now the OS seems to be configured to use 'configfs' but I cannot 'mkdir' under '/config/usb_gadget' as it results in the following error.
> kobject_add_internal failed for android0 with -EEXIST, don't try to register things with the same name in the same directory.

Also there is a '/config/usb_gadget/g1' already which is for the USB 3.0 port.

So there are multiple issues involved getting this to work so here are my questions:

Q1) Can role switch be done programmatically, aside from using the shell to write to the 'mode' file?

Q2) How can I add an additional gadget (for the USB 2.0 port) using 'configfs' (mkdir fails currently)?

Q2) How do I add support for NCM so that can be used in the new USB gadget that will be created.


Thanks,
Alan

  • Hi, Alan,

    Your query has been forwarded to experts. They will comment directly here.

    Regards,
    Mariya
  • Alan

    What is the Processor SDK Linux release version you are using ?

    Are you trying on the TI-EVM board or custom board ?

    Regards

    Ravi

  • Alan

    Which port you are using ? what is the dr_mode is set ?
    The dr_mode should be set to "otg".

    Regards
    Ravi
  • Hi Ravi,

    As I've specified in the title, I'm using the Android OS and the build is 6AM.1.3.

    The board I am using is the Jacinto 6EVM with the JAMR3 daughter card.

    Thanks,

    Alan

  • As specified in the original question, I am using port labeled USB2 which is a USB 2.0 port that has a miniB port. I am using a Female A to Male mini B adapter plugged into the port. I believe 'dr_mode' is set to 'otg'. I can change the role (at least value in the mode file changes) from "host" <-> "device" with using 'echo' command on the shell. So regarding Q1, I guess I can just try to open the file and write to it.

    Q2 and Q3 are more important questions.

    -Alan

  • One note on failure to create USB Gadget.
    It seems in the 'android_device_create()' function in 'kernel/android-4.4/drivers/usb/gadget/configfs.c', device_create() is always called with the device name "android0".
    As there is a gadget already created by default, trying to add additional gadget seems to fail as it is trying to create device named "android0" which already exists. How should this be fixed?

    static int android_device_create(struct gadget_info *gi)
    {
    //......
    android_device = device_create(android_class, NULL,
    MKDEV(0, 0), NULL, "android0");
    //......
    }
  • Hi ,

    Any updates on this issue?

    Thanks,

    Alan

  • Alan

    I am not sure about "android specific changes"  drivers/usb/gadget/configfs.c file. Whether ADB is enabled on port0 or USB0 superspeed port ?

    I have verified on standalone linux kernel with DRD role switch between host and device using configfs.

    Can you try kernel only without android specific changes.

    Make sure dr_mode = "otg" for USB2 port. 

    mount -t configfs none /sys/kernel/config

    cd /sys/kernel/config/
    cd usb_gadget/
    mkdir j6g
    cd j6g
    echo "0xA55A" > idVendor
    cat idVendor
    echo "0x0111" > idProduct
    mkdir strings/0x409
    cd strings/
    cd 0x409/
    echo "0123456789" > serialnumber
    echo "Xyz Inc." > manufacturer
    echo "NCM+ACM gadget" > product
    cd ..
    cd ..
    cd functions/
    mkdir acm.gs0
    mkdir ncm.usb0
    cd ..
    cd configs/
    mkdir c.1
    cd c.1
    mkdir strings/0x409
    cd strings/0x409/
    echo "ACM+NCM" > configuration
    cd ..
    cd ..
    cd ..
    cd ..
    ln -s functions/acm.gs0 configs/c.1
    ln -s functions/ncm.usb0 configs/c.1
    echo "48890000.usb" > UDC                     //for USB0

    echo "488d0000.usb" > UDC                     //for USB1

    Regards

    Ravi

  • Hi ,

    Thanks for the verification.

    > Can you try kernel only without android specific changes.

    I can try this but eventually I'll need this to work on Android with the exsiting configuration.
    It would be appreciated if an Android expert looked at this and provide suggestions.
    The problem as I see it is not being able to create a 2nd USB gadget using configFS as it always calls `device_create()` with "android0".
    (Should I create a new thread for this?)

    Thanks,
    Alan
  • Alan

    I have forwarded the thread to android expert.

    Regards
    Ravi
  • Hi ,

    Could you illustrate the steps for enabling USB NCM Function?

    It seems like the Android build has it disabled.

    I know TI uses 'ti_config_fragment' to build configuration for the kernel build.

    I was trying to modify the generated file at `arch/arm/configs/ti_sdk_dra7x_android_debug_defconfig' after running 'defconfig_builder.sh' before building the kernel but it did not seem to work.

    Perhaps I am missing a step.

    Thanks,

    Alan

  • Hi Ravi B,

    I figured out how to configure things properly using 'ti_config_fragments'.

    I was trying to manually edit the defconfig file but may have been missing some of the flags.

    It seems .config is created as part of the build step and all I need to do is do 'make menuconfig' with the final .config file to add in the proper features.

    So you can ignore my last question regarding the USB NCM function build for now.

    I still do need support on getting additional USB gadgets to work properly on Android OS.

    Thanks,

    Alan

  • Alan

    Maker sure g_ncm module is built and dr_mode is set to "otg" in DTB file.

    CONFIG_USB_NET_CDC_NCM=m
    CONFIG_USB_F_NCM=m
    CONFIG_USB_G_NCM=m

    Once kernel is up,

    # mount -t debugfs debugfs /mnt

    # echo "device" > /mnt/488<9 or d>0000/usb/mode (for usb0 or usb1 respectively)

    # modprobe g_ncm

    You must see usb0 interface should have created (ifconfig -a).

    Refer to PSDKLA Users Guide for more info.

    Regards

    Ravi

  • Hi Alan,

    Could you confirm that USB_CONFIGFS_NCM is enabled in your final .config?

    Regards,
    Vishal
  • Yes I have USB_CONFIGFS_NCM enabled.
    Although I haven't tested the actual communication,
    I was able to create a directory under functions with the default gadget for testing but also can see usb0 in ifconfig now.
  • Yes I have USB_CONFIGFS_NCM enabled.
    Although I haven't tested the actual communication,
    I was able to create a directory under functions with the default gadget for testing but also can see usb0 in ifconfig now.

    I did the test with the default gadget that is created at bootup and not with the additional gadget that I want to create.

  • Hi Alan,

    Could you try below steps? To check if you can use the USB2.0 port as device.
    With this I was able to test NCM with USB2.0 port. For time being I had to disable adb for this (by doing the setprop command below)

    setprop sys.usb.config none
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    mkdir /config/usb_gadget/g1/functions/ncm.gs2
    ln -s /config/usb_gadget/g1/functions/ncm.gs2 /config/usb_gadget/g1/configs/b.1/f3
    echo "488d0000.usb" > /config/usb_gadget/g1/UDC


    The above steps are on top of having right Kernel configuration and dts changes.


    By default there are steps in init.usb.configfs.rc and init.jacinto6evm.usb.rc files for configuring the USB3.0 port for ADB using configFS. These might come in the way of other gadget port.
  • Also note that, after doing above commands you can do role switch on USB2.0 port by executing below commands.

    echo 'host' > /d/488d0000.usb/mode
    echo 'device' > /d/488d0000.usb/mode
  • Thank you, Vishal.

    With your commands, I was able to enable the USB 2.0 port as a USB device with NCM by reconfiguring the 'g1' gadget.

    Doing IP configuration and a simple ping test, it seems to work.

    Now adding an additional gadget is still a problem

    but I'll first tryout testing adding additional interfaces to the gadget with your workaround.

    We may need to revisit the adding the additional gadget part.

    Regards,

    Alan

  • This limitation is coming via changes done to configFS by Android Kernel. That debug will take time as we are trying to find out how to appraoch the problem.

    There is another workaround available with which you can have multiple gadgets without having to disable ADB. But, with this workaround you won't see the Android UI notification of ADB being connected.

    Make the below changes in kernel and rebuild your config and zImage for changes to reflect. Note that you have to also disable CONFIG_USB_CONFIGFS_F_AUDIO_SRC from Kernel for avoiding compilation issue

    index 5cf6802,5cf6802..fc208aa
    --- a/drivers/usb/gadget/Kconfig
    +++ b/drivers/usb/gadget/Kconfig
    @@@ -413,14 -413,14 +413,6 @@@ config USB_CONFIGFS_F_AUDIO_SR
    help
    USB gadget Audio Source support

    --config USB_CONFIGFS_UEVENT
    -- boolean "Uevent notification of Gadget state"
    -- depends on USB_CONFIGFS
    -- help
    -- Enable uevent notifications to userspace when the gadget
    -- state changes. The gadget can be in any of the following
    -- three states: "CONNECTED/DISCONNECTED/CONFIGURED"
    --
    config USB_CONFIGFS_F_UAC1
    bool "Audio Class 1.0"
    depends on USB_CONFIGFS
  • Hi Vishal,
    Thanks for the tips on the additional workaround.
    I'll consider the multiple gadget issue closed for now and start a new thread if we need to revisit this or come up with a better solution.

    I am currently trying to add a custom BULK IN/OUT interface to the gadget.
    I think this requires adding ACM.
    Any tips on this?

    Best regards,
    Alan
  • Actually, I am using Generic USB Bulk IN/OUT which seems to be more suitable.
    >> mkdir /config/usb_gadget/g1/functions/gser.gs0
    I was able to verify simple communcations between the host and the device using /dev/ttyXXXX
  • Hi ,

    I do see one issue that is related to the USB role switch.

    We need to supply power to the VBUS even after TI J6 port has changed to 'device'.

    How do we go about doing this?

    Thanks,

    Alan

  • Hi ,

    I found what seems like a releated patch in the following page:
    processors.wiki.ti.com/.../Template:GLSDK_USB_DRD

    > Driving VBUS using GPIO
    > In order to drive the drvvbus to be "always on" in between role switch between "host" mode or "device" mode. Please refer to reference patch > implementation from link.
    >
    > This patch is based on 3.14 kernel and u-boot-2014.07.
    > u-boot-2014.07-drd-patches.tar - Includes u-boot changes which configure pinmux for drive vbus using gpio.

    Could this be applied to Android build 6AM.1.3? (omapedia.org/.../6AM.1.3_Release_Notes)

    Also would still need bit more details on how to apply and use it properly.

    Thanks,
    Alan
  • Hi Alan,

    the original issue in the thread seems to be resolved.
    Can you create a separate thread with the new issue?

    Thanks,
    Yordan