豚吐露@wiki

WSLからUSB_Serialを利用する

最終更新:

ohden

- view
管理者のみ編集可

WSLからUSB Serialを利用する


Windows11 22H2(22621.1992)
wsl 1.2.5.0
usbipd 3.0.0+361.Branch.master.Sha.89d4b327c99a4eecc9b583e1843a428aae3c9270

Ubuntu 20.04.6 LTS on WSL2
usbip (usbip-utils 2.0)

SPRESENSE CXD5602PWBMAIN1

usbipd/usbip

基本、usbipを利用する方法が提案されてるので、それを利用する。
usbipd/usbipは、USB機器をネットワーク経由で共有して接続するための仕組み。

cf.)

【Win】usbipdのinstall

PowerShellを起動し、以下のcommandを実行。

> winget install --interactive --exact dorssel.usbipd-win
確認が出るので"y"で続行。
しばらく待ってるとinstallが完了する。
その後、一度PowerShellを終了し、もう一度PowerShellを起動し直さないと、installしたcommandが有効にならない。
再起動したPowerShellで以下のcommandを実行。

> usbipd wsl list
BUSID VID:PID DEVICE STATE
1-3 06cb:00e7 Synaptics UWP WBDI Not attached
2-1 8087:0029 インテル(R) ワイヤレス Bluetooth(R) Not attached
2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Not attached

usbipd: warning: Unknown USB filter 'edevmon' may be incompatible with this software; 'bind --force' may be required.

認識されてるUSB機器が一覧で表示される。
今回はSPRESENSEを用いて実施。"Silicon Labs CP210x USB to UART Bridge"ってヤツがSPRESENSE。

【Linux】usbipのinstall

WSL側にもusbipをinstall。
$ sudo apt update
$ sudo apt install linux-tools-generic hwdata
$ sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/*-generic/usbip 20
msの手順に上記のように書いてあるが、update-alternativesが失敗する場合は、"*"の指すpathが複数存在してる場合。
その時は、
$ sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/5.4.0-153-generic/usbip 20
のように、wildcardを使わないpathを書いてみると良い。

【Win】USB Serialの接続

まずは、接続されてるUSB機器一覧の表示。
> usbipd wsl list
BUSID VID:PID DEVICE STATE
1-3 06cb:00e7 Synaptics UWP WBDI Not attached
2-1 8087:0029 インテル(R) ワイヤレス Bluetooth(R) Not attached
2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Not attached

usbipd: warning: Unknown USB filter 'edevmon' may be incompatible with this software; 'bind --force' may be required.

今回は"2-2"で認識されてる"Silicon Labs CP210x USB to UART Bridge"を接続する。
色々接続方法はあるが、今回はBUSID"2-2"を指定して接続する。
> usbipd wsl attach -b 2-2
usbipd: warning: Unknown USB filter 'edevmon' may be incompatible with this software; 'bind --force' may be required.

接続成功すると、listのSTATEが'Attached'に変わる。
> usbipd wsl list
BUSID VID:PID DEVICE STATE
1-3 06cb:00e7 Synaptics UWP WBDI Not attached
2-1 8087:0029 インテル(R) ワイヤレス Bluetooth(R) Not attached
2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Attached - Ubuntu

【Win】tcp connect errorが起きてつながらない
接続時、以下のようなerrorが出て繋がらないことがある。
> usbipd wsl attach -b 2-2
usbipd: warning: Unknown USB filter 'edevmon' may be incompatible with this software; 'bind --force' may be required.
usbipd: warning: A third-party firewall may be blocking the connection; ensure TCP port 3240 is allowed.
usbip: error: tcp connect
usbipd: error: Failed to attach device with busid '2-2'.

この原因はfirewall。portが開いとらんので接続error起きてた。
冒頭にもサラッと書いとるが、usbipd/usbipはUSB機器をネットワーク経由で共有して接続する仕組み。
なので、firewallで接続が遮断されとると、接続errorが発生する。

Windows Firewallなら接続要求が発生したときに"usbipdがTCP 3240で通信したがってるよ"ってdialogが出て分かるハズ。
わしはESET使ってたんでdialogが出んくてトラブった。

以下はesetの設定例。
"ローカル"タブにアプリケーション単位で許可してあげればえぇみたい。

【Linux】usb機器の接続確認

lsusbで認識しとるUSB機器を確認。"Silicon Labs CP210x"が含まれていればok。
WSL2にUSB機器が接続されている状態になってる。
lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


更新日: 2023年08月11日 (金) 08時12分46秒

名前:
コメント:

すべてのコメントを見る
記事メニュー
目安箱バナー