USB虚拟2路串口
通過(guò)configfs虛擬出兩路usb串口,腳本如下:
#!/bin/sh# usage # ./usb-acm.sh usb2 or ./usb-acm.sh usb3 # ./usb-acm.sh usb2 disable or ./usb-acm.sh usb3 disableusb_dev_controller=${1}_acm export CONFIGFS_HOME=/etc/configfs UDC=$CONFIGFS_HOME/usb_gadget/${usb_dev_controller}/UDC# modify following to adapt different chip USB_COUNT=2 USB1_NAME=usb2 USB2_NAME=usb3 USB1=100000.dwc3 USB2=200000.dwc3if [ $# == 0 ] || [ $# -ge 3 ]; thenecho "usage:"echo "./usb-acm.sh usb2 or ./usb-acm.sh usb3"echo "./usb-acm.sh usb2 disable or ./usb-acm.sh usb3 disable"exit 0 fiif [ ${USB_COUNT} == 1 ] && [ $1 != ${USB1_NAME} ]; thenecho "don't support: ${1}"exit 0 fiif [ ${USB_COUNT} == 2 ] && [ $1 != ${USB1_NAME} ] && [ $1 != ${USB2_NAME} ]; thenecho "don't support: ${1}"exit 0 fiif [ $# == 2 ]; thenif [ $2 == "disable" ]; thenecho > ${UDC}exit 0fiecho "error cmd: ${0} ${1} ${2}"exit 0 fiif [ -f ${UDC} ]; thenread line < ${UDC}if [ -n "${line}" ]; thenecho "usb ACM has enabled" # so we don't need to enable it againexit 0fi fiif [ -f ${UDC} ]; thenecho "enable usb ACM gadget"if [ ${1} = ${USB1_NAME} ]; thenecho ${USB1} > ${UDC}elseecho ${USB2} > ${UDC}fiexit 0 fimkdir -p $CONFIGFS_HOME if [ ! -d "${CONFIGFS_HOME}/usb_gadget/" ]; thenmount none $CONFIGFS_HOME -t configfs fimkdir -p $CONFIGFS_HOME/usb_gadget/${usb_dev_controller} cd $CONFIGFS_HOME/usb_gadget/${usb_dev_controller}echo 0x2222 > idVendor echo 0x1111 > idProductmkdir -p strings/0x409 echo 20200210 > strings/0x409/serialnumber echo "xxxxx" > strings/0x409/manufacturer echo "xxxxxx" > strings/0x409/productmkdir -p configs/c.1 mkdir -p configs/c.1/strings/0x409 echo acm > configs/c.1/strings/0x409/configuration echo 120 > configs/c.1/MaxPower# creat 2 usb-serial-device mkdir -p functions/acm.usb0 mkdir -p functions/acm.usb1ln -s functions/acm.usb0 configs/c.1/f1 ln -s functions/acm.usb1 configs/c.1/f2echo "enable usb ACM gadget" if [ ${1} = ${USB1_NAME} ]; thenecho ${USB1} > UDC elseecho ${USB2} > UDC fi 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
- 上一篇: 法国一顶尖大学禁止使用 ChatGPT,
- 下一篇: 如何使能linux vivid