VIM3 USB-C port hid mouse emulation

Which Khadas SBC do you use?

VIM3

Which system do you use? Android, Ubuntu, OOWOW or others?

Ubuntu, Kernel 4.9.241

Which version of system do you use? Khadas official images, self built images, or others?

Official

Please describe your issue below:

So I want to emulate an HID-compliant mouse, but I can’t figure out how to enable gadget mode for the USB-c port. I added otg-device in the /boot/env.txt and tried to load the g_hid module (it says it isn’t found ). Tried gadgetfs too but it seems to be missing in ubuntu ( tried this: Building Gadget USB Module - Openmoko but didn’t work ). I am pretty new to this and can’t find anything helpful.

@IRules you will need to modify the device tree to enable dwc2 on the USB-C node for OTG usb mode.

Also g_hid is not enabled on the default configuration of the linux kernel for the VIM3.
You need rebuild the kernel using Fenix

you can run make kernel-debs to setup the kernel building system.

Within build/linux/arch/arm64/kvims_config, add the configuration you need

and run make kernel-debs again, within build/debs/... you can find the kernel packages to install on your vim with the added config.

Hello, after much trial and error, I am still unable to get g_hid to work ( I think ). This is everything I enabled, did I miss something?
Kvims config:
image

make kernel-config


/boot/env.txt ( did sync and reboot after changing it )
image

Yet, my /dev ( should have devices in the hidgX format ) and modprobe g_hid

Edit: here is the documentation I am following to test for USB HID gadget: Linux USB HID gadget driver — The Linux Kernel documentation

@IRules maybe you need to add other kernel configuration to make it run, probably.

please look at this to enable the otg USB config

you also need to add to arch/arm64/configs/kvims_defconfig

+ CONFIG_USB=y
+ CONFIG_USB_SUPPORT=y
+ CONFIG_USB_PHY=y

Added those, tried more stuff like making the USB slave ( gadget ) only, tried making the files manually, adding g_hid in the /etc/modules, and even following a rasp pi tutorial and adapting it. Nothing worked. I guess I have to ask now if someone who knows much more about Linux and vim3 than me can compile a kernel with g_hid, please. ( or just give me even more info about this rabbit hole )

I have solved the problems and got everything to work as it should, here is what one has to do:

  1. Clone fenix ( GitHub - khadas/fenix: One-stop script set to build Ubuntu/Debian images ) on a ubuntu machine
    ( Next in make kernel-config )
  2. Enable gadget support, the Dummy HCD driver and the HID driver
  3. Put the USB in slave only mode
    ( save with make kernel-saveconfig )
  4. Edit the kvims_config ( file is at build/linux/arch/arm64/kvims_config - path was a little different for me, but you should find it around that path )
    ( make image )
  5. Flash the image on the VIM3 ( obviously )
  6. go to /boot/env.txt ( you need sudo ) and add otg-device dwc2 to the overlays ( dwc2 argument is not documented in the file but it works )
  7. save, run sync and reboot
  8. run the tester from here: Linux USB HID gadget driver — The Linux Kernel documentation

Hope this helps anyone who is in the same situation I was.

Thank you @Electr1 for the advice, helped me a lot!

2 Likes