usb hub区分端口_树莓派上 USB 子系统拓扑浅析
【注釋】以下實驗基于 RaspberryPi 3B。
參考 “樹莓派官網(wǎng)”對 USB 子系統(tǒng)的描述如下:
The number and type of USB ports on Raspberry Pi depends on the model. The Raspberry Pi Model B is equipped with two USB 2.0 ports; the B+, 2B, 3B and 3B+ have four USB 2.0 ports. The Pi 4 has two USB 2.0 ports and two USB 3.0 ports. In all models prior to the Pi 4, the USB ports connect to a combo hub/Ethernet chip, which is itself a USB device connected to the single upstream USB port on BCM2835. On the Pi 4, the USB hub chip is connected to the SoC using a PCIe bus.怎么理解這段話呢,我們可以首先查看 Raspbian(Linux)的設(shè)備模型 。執(zhí)行如下命令:
ls /sys/bus/usb/devices或者
ls /sys/devices可以看到以下設(shè)備:
/sys/devices/platform/soc/3f980000.usb/usb1/1-0:1.0 /sys/devices/platform/soc/3f980000.usb/usb1/1-1 /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1 /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1:1.0 /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1/1-1.1:1.0結(jié)合 Raspbian 啟動的日志流程,我們一起來看一下 USB 的設(shè)備模型的拓?fù)浣Y(jié)構(gòu)究竟是怎么一回事以及系統(tǒng)是如何構(gòu)造出這些文件的。
整體的 log 我們就不貼了,我只摘取了和 USB 相關(guān)的條目,參考時間戳由上至下排列,并在相應(yīng)日志下補(bǔ)上對應(yīng)的注釋。
[ 0.785594] dwc_otg 3f980000.usb: DWC OTG Controller【注釋】這里系統(tǒng)提示找到了一個 host controller,“3f980000.usb” 是 soc 上的 USB host controller。
啟動繼續(xù):
[ 0.797191] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 4.19 [ 0.801703] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 0.804114] usb usb1: Product: DWC OTG Controller [ 0.806480] usb usb1: Manufacturer: Linux 4.19.97-v7+ dwc_otg_hcd [ 0.808929] usb usb1: SerialNumber: 3f980000.usb【注釋】usb1 是 USB host controller 直接控制的 roothub, roothub 是 1 起序的,所以這是第一個 hub。
啟動繼續(xù):
[ 0.811882] hub 1-0:1.0: USB hub found [ 0.814160] hub 1-0:1.0: 1 port detected【注釋】這個usb1 是一個 roothub,而且這個 roothub 只有一個 port,設(shè)備模型中 “/sys/devices/platform/soc/3f980000.usb/usb1/1-0:1.0”就是對應(yīng)的這個 roothub,其中 “1-0:1.0”中的 “1-0”表示的是第 1 個 hub(即usb1)的第 0 號端口,但實際上 hub 的 port 編號是從 1 開始, 0 號 port 就是指 hub 自身。而 ":" 后面的 "1.0" 對應(yīng)的語法格式是 "configID:interfaceID"。
啟動繼續(xù):
[ 2.786999] usb 1-1: new high-speed USB device number 2 using dwc_otg [ 2.795901] Indeed it is in host mode hprt0 = 00001101 [ 3.037235] usb 1-1: New USB device found, idVendor=0424, idProduct=9514, bcdDevice= 2.00 [ 3.053286] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [ 3.064064] hub 1-1:1.0: USB hub found [ 3.070789] hub 1-1:1.0: 5 ports detected [ 3.396998] usb 1-1.1: new high-speed USB device number 3 using dwc_otg [ 3.537280] usb 1-1.1: New USB device found, idVendor=0424, idProduct=ec00, bcdDevice= 2.00 [ 3.551275] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=01.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:91:bc:d3【注釋】檢測到連在 roothub(usb1) 上的另一個新設(shè)備 "1-1"。 它連在 roothub 的第 2 個 port 上,編號從 1 開始。 設(shè)備模型 sysfs 中的下面兩個設(shè)備都是在描述它,從上面的描述可以看出來這第二個設(shè)備也是一個 hub,而且它有 5 個 port。
/sys/devices/platform/soc/3f980000.usb/usb1/1-1 /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1:1.0同時在這個 hub 上的第一個口連了一個usb以太網(wǎng)卡,設(shè)備名 “1-1.1”
也就是對應(yīng)設(shè)備模型中的以下兩個文件:
/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1 /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1/1-1.1:1.0我在 3B 的第一個 USB exteral port (四個中左上方的那個)接入一個鼠標(biāo),系統(tǒng)產(chǎn)生 log 如下:
[ 1045.256993] usb 1-1.2: new low-speed USB device number 4 using dwc_otg [ 1045.392240] usb 1-1.2: New USB device found, idVendor=413c, idProduct=301a, bcdDevice= 1.00 [ 1045.392257] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 1045.392267] usb 1-1.2: Product: Dell MS116 USB Optical Mouse [ 1045.392276] usb 1-1.2: Manufacturer: PixArt [ 1045.401341] input: PixArt Dell MS116 USB Optical Mouse as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:413C:301A.0001/input/input0 [ 1045.402934] hid-generic 0003:413C:301A.0001: input,hidraw0: USB HID v1.11 Mouse [PixArt Dell MS116 USB Optical Mouse] on usb-3f980000.usb-1.2/input0查看 sysfs 多了以下內(nèi)容
/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0說明我們在 hub (“/sys/devices/platform/soc/3f980000.usb/usb1/1-1”)上的 2 號 port 上接了一個鼠標(biāo)設(shè)備,這個設(shè)備的名字叫 “1-1.2”,全路徑是 “/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2”,而“/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0”就是該鼠標(biāo)設(shè)備的接口的全路徑名稱。
綜上所示(在插入鼠標(biāo)的情況下),整個樹莓派設(shè)備的 USB 系統(tǒng)拓?fù)溥壿嬋缦聢D所示:
--------------+------------- platform bus(/sys/devices/platform/soc/3f980000.usb)|/-----------------| Host Controller | (usb1), which contains a roothub (1-0)-----------------/ the roothub has only one downstream port| --------------+--------------- usb bus (level 1)| /----------| 1-1 | hub (1-1), has 5 ports----------/| --------+--------------+------ usb bus (level 2)| || |eth (1-1.1) mouse (1-1.2)總結(jié)
以上是生活随笔為你收集整理的usb hub区分端口_树莓派上 USB 子系统拓扑浅析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于window.location可以获
- 下一篇: Git错误non-fast-forwar