USB Q&A

Q1: How to switch between usb host and device?

USB 2.0 Host config options:

-> Device Drivers

    ->[*] USB support --->

Select the options in the red box above, and then compile USB 2.0 Host driver: usb-common.ko usbcore.ko ehci-hcd.ko

USB 2.0 Device config options:

-> Device Drivers

    ->[*] USB support --->

        -><*> USB Gadget Support --->

            -> USB Peripheral Controller --->

Select the options in the red box above, and then compile USB 2.0 Device driver:usb-common.ko usbcore.ko udc-core.ko udc-msb250x.ko

Add the generated ko to project\kbuild\customize\4.9.84\p3\dispcam\kernel_mod_list_late, automatically insmod at boot.

Note: ehci-hcd.ko is the host driver, and udc-msb250x.ko is the device driver. If there is no otg function, only one of them can exist. The driver installed later will overwrite the previous one.

Open the uvc config:

Add config: make menuconfig

a. media frame config

-> Device Drivers 
-> Multimedia support
-> Device Drivers 
-> Multimedia support 
-> Cameras/video grabbers support 
-> Device Drivers
-> Multimedia support
-> Media Controller API

Output module: media.ko videodev.ko v4l2-common.ko

b. usb Gadget frame config

-> Device Drivers 
-> USB support 
-> Device Drivers
-> USB support 
-> USB Gadget Support

Output module: usb-common.ko udc-core.ko

c. udc drive config: This is a hardware ip related module, which can be configured according to the specific situation.

-> Device Drivers 
-> USB support 
-> USB Gadget Support 
-> USB Peripheral Controller 
-> Sstar USB 2.0 Device Controller

Output module: udc-msb250x.ko

d. gadget webcam

-> Device Drivers 
-> USB support 
-> USB Gadget Support 
-> USB Gadget Drivers 
-> Device Drivers 
-> USB support 
-> USB Gadget Support 
-> USB Gadget Drivers 
-> USB Webcam Gadget

Output module: libcomposite.ko videobuf2-core.ko videobuf2-v4l2.ko videobuf2-memops.ko videobuf2-vmalloc.ko usb_f_uvc.ko g_webcam.ko

Note:

  1. When the configuration option is y (check .config in the kernel directory), the module is compiled to builtin mode and compiled in kernel by default. At this time, the Image needs to be replaced and burned to generate uImage.xz (arch/arm/boot/ ).

  2. When the configuration option is m, the module is compiled to module mode, and xxx.ko will be generated in kernel/modules. Load the corresponding file after linux starts: insmod xxx.ko.

  3. There are dependencies between modules, configuration and loading need to be in order.

The order of loading is as follows(recommended/If it is builtin please ignore):

1. media.ko 
2. videodev.ko 
3. v4l2-common.ko 
4. usb-common.ko 
5. videobuf2-core.ko 
6. videobuf2-v4l2.ko 
7. videobuf2-memops.ko 
8. videobuf2-vmalloc.ko 
9. udc-core.ko 
10. libcomposite.ko 
11. usb_f_uvc.ko 
12. udc-msb250x.ko 
13. g_webcam.ko

Q2: Is the USB Gadget configured as a Keyboard?

Kernel configuration is as follows (be careful not to insmod /config/modules/4.9.84/ehci-hcd.ko)

Example of configuring the keypad device:

mount -t configfs none /sys/kernel/config/
cd sys/kernel/config/usb_gadget
mkdir keyboard
cd keyboard
mkdir configs/c.1
mkdir functions/hid.usb0
echo 1 > functions/hid.usb0/protocol 
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
cat /customer/kybd-descriptor.bin > functions/hid.usb0/report_desc
mkdir strings/0x409                           
mkdir configs/c.1/strings/0x409
echo 0xXXXX > idVendor
echo 0xXXXX > idProduct
echo "1234567890" > strings/0x409/serialnumber
echo "XXXXXX." > strings/0x409/manufacturer
echo "XXXXXX" > strings/0x409/product
echo "hid_conf" > configs/c.1/strings/0x409/configuration
ln -s functions/hid.usb0 configs/c.1
echo "soc:Mstar-udc" > UDC

...