About ROCK3A's usb otg

rock3a can support a usb3.0 otg or usb 2.0 otg, but when i use usb otg to simulate a hid, it sames doesn’t work, however when i run my otg hid shell on another board (cpu is rk3566), use the same kernel image as rock3a, and use the same usb config for dtc code. it works well on rk3566. Why is it? is there some hardware err on rock3a ?

kernel driver need:

modprobe configfs
modprobe libcomposite
modprobe usb_f_hid

create usb otg hid shell is:

create_usbhid.zip (983 Bytes)

#!/bin/sh

new_directory="/sys/kernel/config/usb_gadget/otg"

if [ $# -ne 1 ]
then
echo “usage: $0 <start|stop>” >&2
exit 0
fi

action=$1

if [ $action = “start” ];then

original_directory="$(pwd)"
mkdir “${new_directory}”
cd “${new_directory}”

echo 0x0100 > bcdDevice
echo 0x0200 > bcdUSB
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x1d6b > idVendor # Linux Foundation

mkdir strings/0x409

echo “hid” > strings/0x409/manufacturer
echo “virtual_input” > strings/0x409/product
echo “OTG0001” > strings/0x409/serialnumber

mkdir functions/hid.0

echo 1 > functions/hid.0/protocol # 1: keyboard
echo 8 > functions/hid.0/report_length
echo 1 > functions/hid.0/subclass

echo -ne ‘\x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x75\x01\x95\x08\x81\x02\x95\x01\x75\x08\x81\x03\x95\x05\x75\x01\x05\x08\x19\x01\x29\x05\x91\x02\x95\x01\x75\x03\x91\x03\x95\x06\x75\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0’ > functions/hid.0/report_desc

mkdir functions/hid.1

echo 0 > functions/hid.1/protocol # 2: mouse
echo 6 > functions/hid.1/report_length
echo 1 > functions/hid.1/subclass

echo -ne ‘\x05\x01\x09\x02\xa1\x01\x09\x01\xa1\x00\x05\x09\x19\x01\x29\x03\x15\x00\x25\x01\x95\x05\x75\x01\x81\x02\x95\x01\x75\x03\x81\x01\x05\x01\x09\x30\x09\x31\x15\x00\x26\xff\x7f\x75\x10\x95\x02\x81\x02\x09\x38\x15\x81\x25\x7f\x75\x08\x95\x01\x81\x06\xc0\xc0’ > functions/hid.1/report_desc

mkdir configs/c.1
mkdir configs/c.1/strings/0x409

echo 0x80 > configs/c.1/bmAttributes
echo 300 > configs/c.1/MaxPower
echo “” > configs/c.1/strings/0x409/configuration

ln -s functions/hid.0 configs/c.1
ln -s functions/hid.1 configs/c.1

echo “fcc00000.dwc3” > UDC
cd “${original_directory}”
elif [ $action = “stop” ];then
original_directory="$(pwd)"
cd $new_directory
rm configs/c.1/hid.0
rm configs/c.1/hid.1
rmdir functions/hid.0
rmdir functions/hid.1
rmdir configs/c.1/strings/0x409
rmdir configs/c.1
rmdir strings/0x409
cd “${original_directory}”
rmdir $new_directory
else
echo “invalid action $action” >&2
exit 1
fi

exit 0

use “create_usbhid.sh start” to create a mouse and keyboard, and use “create_usbhid.sh stop” to remove mouse and keyboard, i’m sure my shell script is correct, but i still not konw where is wrong with rock3a.

If you success creat a mouse and keyboard, you will see like this:

and rock3a is like this:

What’s the kernel dmeg output? How about the cable? Usually the USB A to A cable is not so good quality. Also, make sure your OTG switch is set to the HOST.

kernel dmesg does’t show any useful info.

[ 6.644544] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 7.295068] ttyFIQ ttyFIQ0: tty_port_close_start: tty->count = 1 port count = 2
[ 7.311181] fbcon: Taking over console
[ 7.550379] rk-pcie 3c0000000.pcie: PCIe Linking… LTSSM is 0x0
[ 7.576971] rk-pcie 3c0800000.pcie: PCIe Linking… LTSSM is 0x0
[ 8.563543] rk-pcie 3c0000000.pcie: PCIe Linking… LTSSM is 0x1
[ 8.590306] rk-pcie 3c0800000.pcie: PCIe Linking… LTSSM is 0x1
[ 9.576871] rk-pcie 3c0000000.pcie: PCIe Linking… LTSSM is 0x0
[ 9.603604] rk-pcie 3c0800000.pcie: PCIe Linking… LTSSM is 0x0
[ 10.590164] rk-pcie 3c0000000.pcie: PCIe Linking… LTSSM is 0x0
[ 10.616904] rk-pcie 3c0800000.pcie: PCIe Linking… LTSSM is 0x0
[ 11.603457] rk-pcie 3c0000000.pcie: PCIe Link Fail
[ 11.603566] rk-pcie 3c0000000.pcie: failed to initialize host
[ 11.630083] rk-pcie 3c0800000.pcie: PCIe Link Fail
[ 11.630137] rk-pcie 3c0800000.pcie: failed to initialize host
[ 32.056195] pcie30_3v3: disabling
[ 69.082472] dwc3 fcc00000.dwc3: device reset
[ 69.145341] android_work: sent uevent USB_STATE=CONNECTED
[ 69.156800] configfs-gadget gadget: high-speed config #1: c
[ 69.157000] android_work: sent uevent USB_STATE=CONFIGURED

root@rock3a:mnt$ lsmod
Module Size Used by
usb_f_hid 20480 0
libcomposite 57344 1 usb_f_hid
8021q 24576 0
sch_fq_codel 20480 2
ip_tables 28672 0
x_tables 28672 1 ip_tables
ipv6 397312 32
dwc3 131072 0
udc_core 36864 3 usb_f_hid,libcomposite,dwc3
dwc3_of_simple 16384 0

I use a usb A to A cable, and tested usb 2.0 cable and usb 3.0 cable both, but it still not work well.
I’m sure my OTG switch is set to the Device, becuase i can use maskrom to download bootload.

OK, I have solved the problem. becuse the rock3a’s ubuntu rootfs use /bin/sh link to dash, but i need sh link to bash