简体   繁体   English

Raspberry Pi Zero USB设备仿真

[英]Raspberry Pi Zero USB device emulation

I know that the Raspberry Pi Zero supports OTG and USB Peripheral protocols, and there's a lot of cool built in peripherals shown here: https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget?view=all#other-modules 我知道Raspberry Pi Zero支持OTG和USB外设协议,这里有很多很酷的内置外设: https//learn.adafruit.com/turning-your-raspberry-pi-zero-into-a- USB-小工具吗?视图=所有其他#模块

The problem is that I need to emulate a USB Peripheral device that does not appear on this list. 问题是我需要模拟此列表中没有出现的USB外围设备。 I have a vendor ID and product ID for the device, and I'm trying to figure out how exactly to go about doing this. 我有设备的供应商ID和产品ID,我正在试图弄清楚如何做到这一点。 Do I need to modify the OTG USB drivers in the Raspbian kernel? 我是否需要修改Raspbian内核中的OTG USB驱动程序? Do I have to completely build my own kernel? 我是否必须完全构建自己的内核? Or is there a better option I don't even realize? 还是有一个我甚至没有意识到的更好的选择?

Thanks in advance!! 提前致谢!!

Do I need to modify the OTG USB drivers in the Raspbian kernel? 我是否需要修改Raspbian内核中的OTG USB驱动程序?

The answer to your first question is "it depends", but if your device doesn't do anything too unusual this could be a No: you need not modify source code for kernel modules nor the kernel. 你的第一个问题的答案是“它取决于”,但如果你的设备没有做任何太不寻常的事情,这可能是一个否:你不需要修改内核模块和内核的源代码。

You're fortunate that Raspbian supports a modern kernel with ConfigFS support. 你很幸运Raspbian支持一个支持ConfigFS的现代内核。 Once you are set up with dtoverlay=dwc2 , you can open up a FunctionFS bulk endpoint as root like so: 使用dtoverlay=dwc2设置后,可以像root一样打开FunctionFS批量端点,如下所示:

modprobe libcomposite
modprobe usb_f_fs
cd /sys/kernel/config/usb_gadget
mkdir -p myperipheral; cd myperipheral
echo 0x1234 > idVendor  # put actual vendor ID here
echo 0xabcd > idProduct # put actual product ID here
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo "My Peripheral" > configs/c.1/strings/0x409/configuration
mkdir functions/ffs.my_func_name
ln -s functions/ffs.my_func_name configs/c.1/
mkdir -p /tmp/mount_point
mount my_func_name -t functionfs /tmp/mount_point
# compile ffs-test from source, then copy and run it from /tmp/mount_point
ls /sys/class/udc > UDC

If you need to emulate the other device more closely, it's up to you to set bcdDevice , bcdUSB , serial number, manufacturer, product string, max power, os_desc , and possibly other fields. 如果您需要更密切地模拟其他设备,则需要设置bcdDevicebcdUSB ,序列号,制造商,产品字符串,最大功率, os_desc以及可能的其他字段。

AFAIK FunctionFS does not support isochronous endpoints, interrupt transfers, nor out-of-the-ordinary control transfers. AFAIK FunctionFS不支持等时端点,中断传输,也不支持非常规控制传输。 If you require this, you may need to start looking into extending existing gadget modules, with source code here . 如果您需要这一点,你可能需要开始寻找到扩展现有的小工具模块的源代码在这里

Update: When I got home to test this, I encountered a severe caveat with Raspbian. 更新:当我回到家测试时,我遇到了一个严重的Raspbian警告。 It'll initially fail to create ffs.my_func_name because usb_f_fs is not enabled by default. 它最初将无法创建ffs.my_func_name因为默认情况下未启用usb_f_fs。 Although you need not modify any kernel modules, you must recompile with an alternate configuration. 虽然您不需要修改任何内核模块,但必须使用备用配置重新编译 make menuconfig -> Device Drivers -> USB support -> USB Gadget Support -> USB functions configurable through configfs / Function filesystem (FunctionFS) + some other modules to test. make menuconfig - >设备驱动程序 - > USB支持 - > USB小工具支持 - > USB功能可通过configfs / Function filesystem(FunctionFS)+其他一些模块进行测试。 After uploading a new kernel/modules, I tested the above script on Raspbian 8. I would also recommend setting USB Gadget Drivers / Function Filesystem to (M) in case you resort to the simpler g_ffs legacy module in lieu of ConfigFS. 上传新内核/模块后,我在Raspbian 8上测试了上面的脚本。我还建议将USB小工具驱动程序/函数文件系统设置为(M),以防您使用更简单的g_ffs遗留模块代替ConfigFS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM