How to use the OTG port in device mode

Hi,

I’ve been struggling a bit with this, and couldn’t find any guide/reference except this post, which was left unanswered: How to get USB OTG port to work in Device mode?

the USB-C port is advertised as supporting OTG device mode, but I can’t seem to make it work.

did anyone ever achieve that on the kvim2 ?

thanks,

Ok, let me refine my question: I’ve managed to see it work on vim2 with the latest Nougat firmware (kernel 3.14), but has anyone made it work with a 4.9 kernel ?

cheers,

1 Like

Would imagine you need to build your own kernel using the fenix scripts?

I guess the USB flash method to load an image shows it can work at a very low level, but have no idea what is needed in a 4.9 kernel to prop things up. I am running balbes150 Armbian 4.9.40 and am happy to try test except am still powered via the USB-C.

[Presume you have sorted power via VIN - has always been 1 of my aims but have yet to take the leap to pay RS Components for qty 10 - any tips?]

I’m using 150balbes 4.9-khadas branch, but I can’t quite figure out the stuff to be done with configfs, since it looks a bit different between 3.14 and 4.9, so I can’t just use the same procedure as the 3.14 nougat ROM… (btw, I’m powering the board through USB-C too)

here’s my current script, but nothing happens on the host when I write the UDC part to enable device mode:

#!/bin/sh

mount -t configfs none /config
mkdir /config/usb_gadget/g1
echo 0x18d1 > /config/usb_gadget/g1/idVendor
echo 0x4ee1 > /config/usb_gadget/g1/idProduct

mkdir /config/usb_gadget/g1/strings/0x409
echo 12345678 > /config/usb_gadget/g1/strings/0x409/serialnumber
echo Dummy > /config/usb_gadget/g1/strings/0x409/manufacturer
echo Demo > /config/usb_gadget/g1/strings/0x409/product

mkdir /config/usb_gadget/g1/configs/c.1
mkdir /config/usb_gadget/g1/configs/c.1/strings/0x409
echo "Conf 1" > /config/usb_gadget/g1/configs/c.1/strings/0x409/configuration
echo 120 > /config/usb_gadget/g1/configs/c.1/MaxPower

mkdir /config/usb_gadget/g1/functions/eem.f0
ln -s /config/usb_gadget/g1/functions/eem.f0 /config/usb_gadget/g1/configs/c.1/eem.f0

echo c9100000.dwc2_a > /config/usb_gadget/g1/UDC

and I have this in kernel config:

CONFIG_USB_CONFIGFS=y
CONFIG_USB_CONFIGFS_RNDIS=y
CONFIG_USB_CONFIGFS_EEM=y
CONFIG_USB_CONFIGFS_F_FS=y
CONFIG_USB_CONFIGFS_F_MTP=y
CONFIG_USB_CONFIGFS_F_PTP=y
CONFIG_USB_CONFIGFS_UEVENT=y
CONFIG_CONFIGFS_FS=y

CONFIG_AMLOGIC_USB_DWC_OTG_HCD=y
CONFIG_USB_DWC3=y
CONFIG_USB_DWC3_DUAL_ROLE=y
CONFIG_USB_DWC3_OF_SIMPLE=y

and notably, 3.14 has properties in /sys/class/android_usb/android0 (like enable), that don’t exist in 4.9, and I don’t know what to replace them with…

4.9 is also missing /sys/class/dual_role/

ok, so it’s working in 3.14 because of /sys/class/android_usb/android0/enable

need to figure out how it’s replaced in 4.9

alright, got it working at last.

for reference, the issue was that my dtb had ‘controller-type = <3>’ in dwc2_a section, while it should be <2>, 3 meaning ‘otg’ and 2 meaning ‘device’.

2 Likes

Nice one.
(Your skills are orders of magnitude beyond mine!)