1. 體驗
1.1 使用
所有命令都是在開發板上執行。
掛載 configfs 文件系統
# modprobe libcomposite # mount -t configfs none /sys/kernel/config # ls /sys/kernel/config/ usb_gadget #ls /sys/kernel/config/usb_gadget // 一開始它是空目錄創建目錄
# cd /sys/kernel/config/usb_gadget # mkdir test_serial # ls test_serial/ -l total 0 -rw-r--r-- 1 root root 4096 Jan 1 03:20 UDC -rw-r--r-- 1 root root 4096 Jan 1 03:20 bDeviceClass -rw-r--r-- 1 root root 4096 Jan 1 03:20 bDeviceProtocol -rw-r--r-- 1 root root 4096 Jan 1 03:20 bDeviceSubClass -rw-r--r-- 1 root root 4096 Jan 1 03:20 bMaxPacketSize0 -rw-r--r-- 1 root root 4096 Jan 1 03:20 bcdDevice -rw-r--r-- 1 root root 4096 Jan 1 03:20 bcdUSB drwxr-xr-x 2 root root 0 Jan 1 01:49 configs drwxr-xr-x 2 root root 0 Jan 1 01:49 functions -rw-r--r-- 1 root root 4096 Jan 1 03:20 idProduct -rw-r--r-- 1 root root 4096 Jan 1 03:20 idVendor drwxr-xr-x 2 root root 0 Jan 1 01:49 os_desc drwxr-xr-x 2 root root 0 Jan 1 01:49 strings創建目錄后,里面就自動生成了很多文件、目錄,比如:
- idVendor:表示廠家 ID,默認值是 0
- idProduct:表示產品 ID,默認值是 0
設置設備描述符,比如設置廠家 ID、產品 ID,這是可選的
echo "0x1234" > idVendor echo "0x5678" > idProduct創建配置:格式為"configs/.",name 可以取任意字符,number 是配置編號
mkdir configs/c.1創建功能(function、接口):格式為"functions/.",name 對應 function 的名字,比如 acm 對應 ACM 功能,對應的驅動為usb_f_acm.ko;instance name 可以取任意字符
mkdir functions/acm.test1把配置和功能聯系起來:ln -s functions/. configs/.
ln -s functions/acm.test1 configs/c.1/使能 Gadget(確定使用哪個 USB Device Controller):echo > UDC,可用的 UDC,可以在 /sys/class/udc/* 目錄下查看
echo ci_hdrc.0 > UDC
1.2 清除
- 禁止 Gadget
echo "" > UDC - 移除配置里的功能(Remove functions from configurations):命令:rm configs/./
rm configs/c.1/acm.test1 - 移除配置:rmdir configs/.
rmdir configs/c.1 - 移除功能:rmdir functions/.
rmdir functions/acm.test1 - 移除 Gadget
rmdir test_serial
1.3 STM32MP157上的實驗
因為 STM32MP157 系統里已經使用 adb 設備,要想模擬串口設備,需要先清除 adb,命令如下:
cd /sys/kernel/config/usb_gadget/g1
echo "" > UDC
rm configs/b.1/ffs.adb
rmdir configs/b.1/strings/0x409
rmdir configs/b.1
rmdir functions/ffs.adb
rm strings/0x409
cd ..
rmdir g1
清除后,就按照《1.1 使用》來操作,需要注意的是最后一步:
ls /sys/class/udc/
49000000.usb-otg
echo 49000000.usb-otg > UDC
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。
舉報投訴
-
嵌入式
+關注
關注
5198文章
20445瀏覽量
334008 -
Linux
+關注
關注
88文章
11759瀏覽量
219013
發布評論請先 登錄
相關推薦
熱點推薦
樹莓派編譯內核報錯
編譯的時候報錯CC [M]fs/btrfs/volumes.ofs/btrfs/volumes.c:28:27: fatal error: linux/raid/pq.h: No such file
發表于 09-29 09:47
Linux系統啟動卡制作及系統固化
:VMware14.1.1Kernel:Linux-4.9.65、Linux-RT-4.9.65Linux Processor SDK
發表于 09-17 16:16
怎么去解決D1s tina linux連接失敗的問題
] configfs-gadget gadget: high-speed config #1: c[13.729040] android_work: sent uevent USB_STATE=CONFIGURED
發表于 12-28 06:19
Imx6如何作為UVC wbcam相機?
。在內核日志中我看到:[ 78.763930] configfs-gadget 小工具:uvc:無法將請求排隊 (-22)。[ 79.259922] ci_hdrc ci_hdrc.0: 未頁面
發表于 04-21 07:17
Linux之chardev_buttom_linux26_str
Linux之chardev_buttom_linux26_struct教程,很好的Linux資料,快來學習吧
發表于 04-15 17:49
?15次下載
Linux之chardev_buttom_linux_struc
Linux之chardev_buttom_linux_struct_poll教程,很好的Linux資料,快來學習吧
發表于 04-15 17:49
?7次下載
Linux之chardev_buttom_linux_struc
Linux之chardev_buttom_linux_struct_timer_debounce教程,很好的Linux自學資料,快來學習吧。
發表于 04-15 17:59
?5次下載
REDIce-Linux--靈活的實時Linux內核
REDSonic, Inc. REDSonic的RedIce-Linux是一個實時Linux內核,設計來支持以任務和時間為臨界的應用,為你的系統提供質量服務。RedIce-Linux包括高精度的微秒
發表于 11-08 10:24
?12次下載
Linux教程之Linux的文件權限管理實驗
嚴格來講,Linux這個詞本身只表示Linux內核,但在實際上人們已經習慣了用Linux來形容整個基于Linux內核,并且使用GNU工程各種工具和資料庫的操作系統(也被稱為GNU/
發表于 11-20 17:08
?6次下載
如何學習Linux學習Linux的詳細步驟說明
Linux系統現在越來越滿足人們對技術的要求,因此Linux不論在市場中還是企業里都備受歡迎,所以學習Linux的人越來越多,那么Linux到底應該怎么學呢?有沒有
發表于 01-15 17:17
?63次下載
Linux有什么優勢?Linux能替代Windows 嗎?
Linux 能用嗎? Linux 有圖形界面 支持日常開發 社交溝通沒問題 Linux 能替代 Windows 嗎? Linux 下運行 Android 應用
嵌入式linux和桌面linux的區別
嵌入式linux和桌面linux的區別主要區別是:1. 硬件平臺:嵌入式Linux一般是Mips, ARM平臺, 桌面Linux一般是x86平臺。2. 根文件系統嵌入式
發表于 10-20 15:36
?4次下載
Linux configfs的內部機制介紹
2.1 configfs 和 sysfs configfs 和 sysfs 都是基于內存的虛擬文件系統,但是它們并不相同。 對于 sysfs,當內核創建某個對象時,比如注冊一個
Linux configfs的使用
評論