Byte buffers do not store data as separate items. All data is stored as a sequence of bytes, and any number of bytes can be sent or retrieved each time. Use byte buffers when separate items do not need to be maintained (e.g. a byte stream).
次に Windows の PowerShell 窓を「管理者で起動」し、使いたい USB 機器を usbipdにアタッチします。
usbipd wsl list コマンドで USB 機器を表示。
4.0 系:
> usbipd list
3 系:
> usbipd wsl list
BUSID VID:PID DEVICE STATE
3-1 17ef:6047 Lenovo USB Interface Device(HID), USB 入力デバイス Not attached
3-3 0e8d:0608 RZ608 Bluetooth(R) Adapter Not attached
7-1 0499:170d AG06/AG03, Line (AG06/AG03) Not attached
9-1 10c4:ea60 CP2104 USB to UART Bridge Controller Not attached
ここでは、CP2104 USB to UART が M5Stack なので 9-1 をアタッチ。なお、初回のアタッチの操作のみ管理者権限が必要で次回からはユーザ権限でいけるようです。
❯ usbipd.exe wsl attach --busid 9-3
usbipd: error: WSL 'usbip' client not correctly installed. See https://github.com/dorssel/usbipd-win/wiki/WSL-support for the latest instructions.
$ sudo update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20
update-alternatives: 警告: /usr/lib/linux-tools/5.15.0-70-generic/usbip の alternative (リンクグループ usbip のパート) が存在しません 。alternatives のリストから削除しています
update-alternatives: 警告: /etc/alternatives/usbip is dangling; it will be updated with best choice
update-alternatives: /usr/local/bin/usbip (usbip) を提供するために自動モードで /usr/lib/linux-tools/5.15.0-71-generic/usbip を使います
ちなみにユーザ権限がついたあとは、Ubuntu 側 WSL2 窓から次のコマンドでも操作可能です。(.exe を付けて明示的に Windows 側のコマンドを呼びます)
4.0 系:
$ usbipd.exe attach --wsl --busid 9-1
3 系:
$ usbipd.exe wsl attach --busid 9-1
うまくいけば、upsipd wsl list コマンドのデバイス部分が Ubuntu になります。
4.0 系:
> usbipd list
3 系:
> usbipd wsl list
BUSID VID:PID DEVICE STATE
9-1 10c4:ea60 CP2104 USB to UART Bridge Controller Attached - Ubuntu-22.04
できたら、WSL2 Ubuntu で lsusb してみて機器(CP210)が見えればOKです。
$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> usbipd wsl list
BUSID VID:PID DEVICE STATE
3-1 17ef:6047 Lenovo USB Interface Device(HID), USB 入力デバイス Not attached
3-3 0e8d:0608 RZ608 Bluetooth(R) Adapter Not attached
7-1 0499:170d AG06/AG03, Line (AG06/AG03) Not attached
9-1 28e9:0189 Not attached
先に管理者権限 PowerShell でアタッチした後、リセットするとアタッチが切れるので、再アタッチ。 WSL2 Ubuntu 側からも Windows の usbipd.exe を呼べる動作を活用してアップロード操作前にアタッチコマンドを実行できるようにタスクを組むと便利。
$ usbipd.exe wsl attach --busid 9-1
$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 28e9:0189 GDMicroelectronics GD32 DFU Bootloader (Longan Nano)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$ which openocd
/home/hiromasa/.espressif/tools/openocd-esp32/v0.11.0-esp32-20221026/openocd-esp32/bin/openocd
$ openocd -f board/esp32c3-builtin.cfg
Open On-Chip Debugger v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Warn : Transport "jtag" was already selected
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : esp_usb_jtag: serial (34:B4:72:12:94:14)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 40000 kHz
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : datacount=2 progbufsize=16
Info : Examined RISC-V core; found 1 harts
Info : hart 0: XLEN=32, misa=0x40101104
Info : starting gdb server for esp32c3 on 3333
Info : Listening on port 3333 for gdb connections
> usbipd.exe wsl list
BUSID VID:PID DEVICE STATE
6-1 2345:7654 USB download gadget
初回の場合は PowerShell 管理者で実行。
> usbipd.exe wsl attach --busid 6-1
WSL2 側で認識確認。
$ sudo dmesg
[ 31.713030] usb 1-1: new high-speed USB device number 2 using vhci_hcd
[ 31.873057] usb 1-1: SetAddress Request (2) to port 0
[ 31.920340] usb 1-1: New USB device found, idVendor=2345, idProduct=7654, bcdDevice= 2.23
[ 31.921254] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 31.921580] usb 1-1: Product: USB download gadget
[ 31.921790] usb 1-1: Manufacturer: T-HEAD
[ 49.129386] hv_balloon: Max. dynamic memory size: 14204 MB