percu Posted June 22, 2020 Posted June 22, 2020 Hello! I try to turn on usb gadget mode on my OPi. For example g_ethernet, or g_midi. Read many posts, but still don't understand what I should do. Is it possible to turn on gadget mode without compiling my own armbian? Also, I had found on this forum info that legacy roms already have OTG support from the box. Is it true? May be somebody knows tutorials of how to turn on usb gadget mode?
usual user Posted June 23, 2020 Posted June 23, 2020 On 6/22/2020 at 7:11 PM, percu said: example g_ethernet, or g_midi Expand g_ethernet or g_midi is legacy USB gadget. You should use the USB gadget framework, it is much more flexible. It can run multiple functions simultaneously and be reconfigured at run time. On 6/22/2020 at 7:11 PM, percu said: Is it possible to turn on gadget mode without compiling my own armbian? Expand To use the USB gadget framework it is usually not necessary to recreate the entire distribution. The only precondition is that the kernel build has created the required components. If your kernel provides /usr/lib/modules/*/kernel/drivers/usb/gadget/libcomposite.ko and /usr/lib/modules/*/kernel/drivers/usb/gadget/functions/*, you are ready to go. The only missing part is proper configuration. First you need a proper devicetree setup for the hardware support. (your prefered editor and DTC to compile the DTB). Second the USB gadget framework configuration (your prefered editor and your usual file system tools). On 6/22/2020 at 7:11 PM, percu said: have OTG support from the box Expand I doubt that this will be the case, gadget features are much too different and there are probably no generic ones that suit someone's needs. At least vendor and device IDs have to be chosen properly.
percu Posted June 23, 2020 Author Posted June 23, 2020 Thank you for replying! In the armbian-config -> hardware I turned on usbhost0. After rebooting, and command "modprobe g_ether", now I can see my OPi as usb COM device in windows. But when I try: sudo modprobe g_midi I get error: modprobe: FATAL: Module g_midi not found in directory /lib/modules/4.19.57-sunxi Where I can get this module? Here I had read, that I need to reconfigure kernel. Think that I need to use make menuconfig command in the kernel build directory. Right? But I don't have source code in /usr/src. May be it is in the other dir? On 6/23/2020 at 8:48 AM, usual user said: First you need a proper devicetree setup Expand I can't find any info about midi device tree configurations. May be devicetree setup have some rules to configure it? On 6/23/2020 at 8:48 AM, usual user said: Second the USB gadget framework configuration (your prefered editor and your usual file system tools). Expand Does USB gadget framework included in the Armbian? Or where I can find it? Sorry for my questions, I'm really stupid in linux.
Igor Posted June 23, 2020 Posted June 23, 2020 On 6/23/2020 at 1:51 PM, percu said: Think that I need to use make menuconfig command in the kernel build directory. Right? But I don't have source code in /usr/src. May be it is in the other dir? Expand In embedded world we compile on the desktop even its also possible native. Recommended way:https://docs.armbian.com/Developer-Guide_Build-Preparation/ Do what you have to do, copy resulting kernel to the board (image and dtb), install (dpkg -i *.deb) and reboot. Remember to push changes to Armbian, so that the next upgrade will contain your work otherwise you will need to repeat this over and over again on each regular kernel upgrade ...
usual user Posted June 23, 2020 Posted June 23, 2020 On 6/23/2020 at 1:51 PM, percu said: command "modprobe g_ether", now I can see my OPi as usb COM device Expand I doubt it. To expose a serial port, you probably used g_serial. On 6/23/2020 at 1:51 PM, percu said: I can't find any info about midi device tree configurations. May be devicetree setup have some rules to configure it? Expand No, devicetree configures only the USB OTG IP for device mode. As your serial port setup is working, your devicetree is already properly set up. On 6/23/2020 at 1:51 PM, percu said: Does USB gadget framework included in the Armbian? Expand Since it's been years since I was tinkering with the USB gadget framework, I looked at the kernel of balbes150's "Single Armbian image for RK + AML + AW" (the only one I had easily available). I learned that the legacy drivers are gone for good nowadays. There are only wraper modules to expose the legacy gadget configuration interfaces that use the gadget framework as backend. Unfortunately he is only building the wraper modules and left out the configfs components to configure the gadget framework via userspace. I don't know how your kernel is configured, so it may be different for you. As the same configuration parameters have to be determined for legacy and configfs configuration I prefer to use configfs. E.g. this shell script sets up a gadget with a printer interface, an ethernet interface and a storage device simultaneously: Reveal hidden contents #!/bin/bash CONFIGFS=/sys/kernel/config/ G1=${CONFIGFS}usb_gadget/acme #--------------------------------------------------------------------------------------------------- mkdir ${G1} printf "0xEF" > ${G1}/bDeviceClass printf "0x01" > ${G1}/bDeviceProtocol printf "0x02" > ${G1}/bDeviceSubClass printf "0x0100" > ${G1}/bcdDevice printf "0x0200" > ${G1}/bcdUSB printf "0x0001" > ${G1}/idProduct printf "0x0555" > ${G1}/idVendor mkdir ${G1}/strings/0x409 printf "ACME AG" > ${G1}/strings/0x409/manufacturer printf "ACME-BOX" > ${G1}/strings/0x409/product printf "02010001" > ${G1}/strings/0x409/serialnumber #--------------------------------------------------------------------------------------------------- mkdir ${G1}/configs/acme-box.1 mkdir ${G1}/configs/acme-box.1/strings/0x409 printf "ACME-BOX Interfaces" > ${G1}/configs/acme-box.1/strings/0x409/configuration #--------------------------------------------------------------------------------------------------- FN=rndis mkdir ${G1}/functions/${FN}.usb0 printf "00:2d:55:FF:0F:FD" > ${G1}/functions/${FN}.usb0/dev_addr printf "00:2d:55:FF:0F:FE" > ${G1}/functions/${FN}.usb0/host_addr ln -s ${G1}/functions/${FN}.usb0 ${G1}/configs/acme-box.1 #--------------------------------------------------------------------------------------------------- FN=mass_storage mkdir ${G1}/functions/${FN}.usb0 # printf "1" > ${G1}/functions/${FN}.usb0/lun.0/cdrom # printf "1" > ${G1}/functions/${FN}.usb0/lun.0/nofua printf "1" > ${G1}/functions/${FN}.usb0/lun.0/removable printf "1" > ${G1}/functions/${FN}.usb0/lun.0/ro printf "ACME-BOX" > ${G1}/functions/${FN}.usb0/lun.0/inquiry_string printf "/run/acme/mass_storage.img" > ${G1}/functions/${FN}.usb0/lun.0/file ln -s ${G1}/functions/${FN}.usb0 ${G1}/configs/acme-box.1 #--------------------------------------------------------------------------------------------------- FN=printer mkdir ${G1}/functions/${FN}.usb0 printf "MFG:Acme;MDL:ACME-BOX;CLS:PRINTER;CMD:PDF,PCL;" > ${G1}/functions/${FN}.usb0/pnp_string ln -s ${G1}/functions/${FN}.usb0 ${G1}/configs/acme-box.1 #--------------------------------------------------------------------------------------------------- printf "ci_hdrc.0" > ${G1}/UDC ifconfig usb0 10.0.0.1 netmask 255.255.255.0 This can't be done with legacy, there you have only one function at a time and the configuration is applied at module load.
percu Posted June 30, 2020 Author Posted June 30, 2020 Sooo, it works now! Big thanks to Igor and usual user! What I do: 1) Reconfigure kernel, turn on midi gadget support(https://linux-sunxi.org/USB_Gadget/MIDI) and compile it. (https://docs.armbian.com/Developer-Guide_Build-Preparation/) 2) Turn on usbhost0 in System -> Hardware section using armbian-config. 3) Install new kernel on my Pi ( sudo dpkg -i linux-image-current-sunxi_20.08.0-trunk_armhf.deb) 4) sudo modeprobe g_midi Profit! Now I can see my midi device in device manager in Win10. It appears with name "MIDI function". So one more question: how I can change this name? Or do I need to do somthing before compiling kernel?
usual user Posted June 30, 2020 Posted June 30, 2020 On 6/30/2020 at 12:02 PM, percu said: So one more question: how I can change this name? Expand As you have chosen the legacy g_midi configuration interface, you have to do configuration while module-load. "modinfo g_midi" will tell all available configurable parameters.
Recommended Posts