USB

Q1: usb host和device如何切换?

USB 2.0 Host配置选项

-> Device Drivers

    ->[*] USB support --->

选择上述红框中选项,然后编译出USB 2.0 Host driver:usb-common.ko usbcore.ko ehci-hcd.ko

USB 2.0 Device配置选项:

-> Device Drivers

    ->[*] USB support --->

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

            -> USB Peripheral Controller --->

选择上述红框中选项,然后编译出USB 2.0 Device driver:usb-common.ko usbcore.ko udc-core.ko udc-msb250x.ko

生成的ko可以添加到project\kbuild\customize\4.9.84\p3\dispcam\kernel_mod_list_late中开机自动insmod

注意: ehci-hcd.ko为host驱动,udc-msb250x.ko为device驱动,在没有otg功能的情况下,两者无法共存。 同时只能存在一种配置,后面安装的驱动会覆盖前面的驱动

打开uvc配置如下:

添加配置:make menuconfig

a. media 框架配置

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

输出模块: media.ko videodev.ko v4l2-common.ko

b. usb Gadget 框架配置

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

输出模块:usb-common.ko udc-core.ko

c. udc 驱动配置:该模块为硬件ip相关模块,视具体情况进行配置

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

输出模块: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

输出模块:libcomposite.ko videobuf2-core.ko videobuf2-v4l2.ko videobuf2-memops.ko videobuf2-vmalloc.ko usb_f_uvc.ko g_webcam.ko

注意:

  1. 当配置选项为 y (可在kernel目录查看.config)时,代表该模块编译为builtin模式,默认编译进kernel内核, 此时需将该Image替换烧录,通常生成为uImage.xz(目录arch/arm/boot/)文件。

  2. 当配置选项为 m 时,代表该模块编译为 module模式,在kernel/modules目录会生成相应 xxx.ko,此时需要 将相应的文件在linux启动之后进行加载: insmod xxx.ko。

  3. 模块之前具有相应依赖关系,配置与加载都需要有先后顺序。

加载的先后顺序如下:

加载顺序推荐(builtin忽略):

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: USB Gadget配置为Keyboard?

Kernel配置如下(注意不要insmod /config/modules/4.9.84/ehci-hcd.ko

配置keypad设备示例:

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