WSL2 内ではホストの USB デバイスを使うことができないという大きな欠点がある。WSL2 のベースとなる Hyper-V 基盤は USB の仮想化というのがないので、すぐにサポートされることはないだろうという見込み。
そこで USB IP という USB プロトコルを IP に乗せネットワーク経由にする技術がある。usbipd-win はこの USB IP のホストを Windows 上で実現するソフトウェアの1つでOSS。MS の公式 YouTube で紹介されていて知った。
USB IP 系のあれこれはドライバの関係で secure boot と相性がわるかったりするが…… これはどうだろう。現状よくわかってない (Secure Boot していないので)
インストール
winget install --exact dorssel.usbipd-win
この状態で Administrator 権限の PowerShell をひらき、usbipd.exe list が実行できることを確認する
$ sudo /usr/lib/linux-tools/5.4.0-77-generic/usbip list --remote=172.18.48.1
Exportable USB devices
======================
- 172.18.48.1
4-3: STMicroelectronics : ST-LINK/V2 (0483:3748)
: USB\VID_0483&PID_3748\6&19CA3885&0&3
: (Defined at Interface level) (00/00/00)
: 0 - Vendor Specific Class / Vendor Specific Subclass / Vendor Specific Protocol (ff/ff/ff)
lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 0483:3748 STMicroelectronics ST-LINK/V2
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
一応 認識して使えてはいるっぽい。
sudo openocd -f interface/stlink-v2.cfg -f target/stm32f0x.cfg
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v34 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.262724
Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x0bb11477
in procedure 'init'
in procedure 'ocd_bouncer'
PS C:\Users\test> usbipd list
Unhandled exception. System.AggregateException: One or more errors occurred. (An item with the same key has already been added. Key: [1, UsbIpServer.UsbConfigurationDescriptors+UsbConfiguration])
---> System.ArgumentException: An item with the same key has already been added. Key: [1, UsbIpServer.UsbConfigurationDescriptors+UsbConfiguration]
at System.Collections.Generic.TreeSet`1.AddIfNotPresent(T item)
at System.Collections.Generic.SortedSet`1.Add(T item)
at System.Collections.Generic.SortedDictionary`2.Add(TKey key, TValue value)
at UsbIpServer.UsbConfigurationDescriptors.AddDescriptor(ReadOnlySpan`1 descriptor) in D:\a\usbipd-win\usbipd-win\UsbIpServer\UsbConfigurationDescriptors.cs:line 96
at UsbIpServer.ExportedDevice.GetConfigurationDescriptor(DeviceFile hub, UInt16 connectionIndex, Byte numConfigurations)
at UsbIpServer.ExportedDevice.GetDevice(SafeDeviceInfoSetHandle deviceInfoSet, SP_DEVINFO_DATA devInfoData, CancellationToken cancellationToken) in D:\a\usbipd-win\usbipd-win\UsbIpServer\ExportedDevice.cs:line 202
at UsbIpServer.ExportedDevice.GetAll(CancellationToken cancellationToken) in D:\a\usbipd-win\usbipd-win\UsbIpServer\ExportedDevice.cs:line 239
at UsbIpServer.Program.<>c.<<Main>b__19_9>d.MoveNext() in D:\a\usbipd-win\usbipd-win\UsbIpServer\Program.cs:line 234
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass79_0.<OnExecute>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at UsbIpServer.Program.Main(String[] args) in D:\a\usbipd-win\usbipd-win\UsbIpServer\Program.cs:line 555
usbview.exe による
---===>Device Information<===---
English product name: "xCORE USB Audio 2.0"
ConnectionStatus:
Current Config Value: 0x01 -> Device Bus Speed: High (is not SuperSpeed or higher capable)
Device Address: 0x0A
Open Pipes: 2
===>Device Descriptor<===
bLength: 0x12
bDescriptorType: 0x01
bcdUSB: 0x0200
bDeviceClass: 0xEF -> This is a Multi-interface Function Code Device
bDeviceSubClass: 0x02 -> This is the Common Class Sub Class
bDeviceProtocol: 0x01 -> This is the Interface Association Descriptor protocol
bMaxPacketSize0: 0x40 = (64) Bytes
idVendor: 0x20B1 = XMOS Ltd.
idProduct: 0x000A
bcdDevice: 0x06C5
iManufacturer: 0x01
English (United States) "XMOS"
iProduct: 0x03
English (United States) "xCORE USB Audio 2.0"
iSerialNumber: 0x00
bNumConfigurations: 0x02
*!*CAUTION: Most host controllers will only work with one configuration per speed
バッテリーは 2020mAh のリチウムポリマー。入ってた箱に「Due to the trial version of the machine, the battery may be overused. Please pay attention to the charging of the battery, or choose to use the registered version」と書いあって不穏。