树莓派 Zero USB 设备仿真

4
我知道树莓派Zero支持OTG和USB外设协议,并且有很多酷炫的内置外设,如:https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget?view=all#other-modules
问题是我需要模拟一个不在此列表中的USB外设。我有设备的供应商ID和产品ID,我正在尝试找出如何做到这一点。我需要修改Raspbian内核中的OTG USB驱动程序吗?我必须完全构建自己的内核吗?或者还有更好的选择我没有意识到的吗?
提前致谢!
1个回答

4
我需要翻译的内容如下:

我是否需要修改Raspbian内核中的OTG USB驱动程序?

对于你的第一个问题,答案是“这取决于情况”,但如果你的设备没有做任何太过奇怪的事情,那么就不需要修改内核模块或内核源代码。

你很幸运,因为Raspbian支持具有ConfigFS支持的现代内核。一旦你使用 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

如果您需要更准确地模拟其他设备,您需要设置bcdDevicebcdUSB、序列号、制造商、产品字符串、最大功率、os_desc以及可能的其他字段。
据我所知,FunctionFS不支持等时端点、中断传输或超出常规控制传输。如果您需要这些功能,您可能需要开始寻找扩展现有设备模块的方法,源代码在此处
更新:当我回家测试时,我遇到了一个严重的警告问题。Raspbian会因为默认情况下未启用usb_f_fs而无法创建ffs.my_func_name。虽然您不需要修改任何内核模块,但必须使用备用配置重新编译。make menuconfig -> Device Drivers -> USB support -> USB Gadget Support -> USB functions configurable through configfs / Function filesystem (FunctionFS) + some other modules to test。上传新的内核/模块后,我在Raspbian 8上测试了上述脚本。我还建议将USB Gadget Drivers / Function Filesystem设置为(M),以防您使用ConfigFS之外的简单g_ffs遗留模块。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接