0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows10 からスタックチャンを書き込む(その2)

Posted at

前回の課題

Web Serial 経由で書き込むのは成功したが、スタックチャンは再起動が繰り返される

今回は

前回Webからしか書けないと思ってましたが、USB経由で書き込む方法が見つかったのでメモ
ただし、再起動ループは直ってない。

実施内容

usbipd をインストール

winget install usbipd

環境変数PATH(ユーザー)に以下を追加

C:\Program Files\usbipd-win\

WSL にアタッチする

usbipd がインストールできると、USBの一覧からM5Stackが見えるようになっているはずです。
私の場合は、BUSID 1-1 がそれでした。接続前後でリストをみると確認しやすいです。

PS C:\WINDOWS\system32> usbipd list
Connected:
BUSID  VID:PID    DEVICE                                                        STATE
1-1    303a:1001  USB シリアル デバイス (COM3), USB JTAG/serial debug unit      Not shared
1-3    045e:07e8  USB 入力デバイス                                              Not shared
1-6    1286:204b  Marvell AVASTAR Bluetooth Radio Adapter                       Not shared
1-7    045e:07be  Microsoft LifeCam Front                                       Not shared
1-8    045e:07bf  Microsoft LifeCam Rear                                        Not shared

次に、WSLにアタッチします。BUSIDを読み替えて実行してください。
usbipd bindusbipd attach を実行します。この時USBデバイスがWindowsから外れ、WSLにアタッチされます。(音が鳴るはず)

> usbipd bind --busid 1-1
> usbipd attach --wsl --busid 1-1
usbipd: info: Using WSL distribution 'Ubuntu' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Detected networking mode 'nat'.
usbipd: info: Using IP address 172.31.112.1 to reach the host.

WSLから確認

WSLのコンソールから lsusb コマンドを実行してください。なければ sudo apt install -y usbutils でインストールしてください。

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 303a:1001 Espressif USB JTAG/serial debug unit
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

ぱっとみ Bus 001 の Device 002 っぽいですね。

デバイスへのアクセス権限を確認すると root とそのグループしかアクセスできないせっていになっています。このままではアクセスできないのでアクセス権を変更します。
そのまえに、/dev/tty?? とどこに接続されたかを確認します。

$ dmesg | grep -i usb | grep tty
[55269.811298] cdc_acm 1-1:1.0: ttyACM0: USB ACM device

ここでは ttyACM0 のようです。
アクセス権限を見てみましょう

$ ls -la /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 May 11 00:26 /dev/ttyACM0

これでは npm からのデプロイでデバイスを見つけられません。

権限を変更します。

USBデバイスの権限変更

/etc/udev/rules.d/ にファイルを置くことで権限変更ができます。

配置するファイルの書き方は以下のような感じです

SUBSYSTEM=="tty", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0043", MODE="0666"

idVendorと idProduct を見つける必要があります。
以下の lsusb の結果を使います。実はID 303a:1001が上記の情報にあたります。

Bus 001 Device 002: ID 303a:1001 Espressif USB JTAG/serial debug unit

ファイルはこんな感じになります。ファイル名は99-esp32.rules にしてみました。

$ cat /etc/udev/rules.d/99-esp32.rules 
SUBSYSTEM=="tty", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="1001", MODE="0666"

変更を適用します。

sudo udevadm control --reload-rules
sudo udevadm trigger

これで権限が変更されているはずです。

$ ls -l /dev/ttyACM0
crw-rw-rw- 1 root dialout 166, 0 May 11 00:42 /dev/ttyACM0

書き込み

さっそく書き込みをします。WSL上での環境の整え方は省略しててすみませんが、公式のドキュメントを見てください。npm で単純に構築できるようになってます。(いくつか環境変数の前提があった気がしますが。。)

$ npm run deploy --target=esp32/m5stack_cores3

> stack-chan@0.2.1 deploy
> cross-env npm_config_target?=esp32/m5stack cross-env-shell mcconfig -d -m -p \$npm_config_target -t deploy ./stackchan/manifest_local.json

# warning: Using AudioIn simulator!
# warning: no modules match: /home/hiroyuki/workspace/stack-chan/firmware/typings/btutils!
# warning: no modules match: /home/hiroyuki/.local/share/moddable/typings/embedded_network/*!

...


Writing at 0x0023b63e... (76 %)
Writing at 0x00240af2... (77 %)
Writing at 0x00245d8b... (78 %)
Writing at 0x0024b2a5... (79 %)
Writing at 0x0025098d... (80 %)
Writing at 0x0025609c... (81 %)
Writing at 0x0025af5d... (82 %)
Writing at 0x0025fe9e... (83 %)
Writing at 0x00265252... (84 %)
Writing at 0x0026a6d5... (85 %)
Writing at 0x0026f82c... (86 %)
Writing at 0x002749b4... (87 %)
Writing at 0x0027a661... (88 %)
Writing at 0x0027fa90... (89 %)
Writing at 0x00284aa0... (90 %)
Writing at 0x00289c85... (91 %)
Writing at 0x0028f3b1... (92 %)
Writing at 0x00295994... (93 %)
Writing at 0x0029c336... (94 %)
Writing at 0x002a6561... (95 %)
Writing at 0x002ac7ec... (96 %)
Writing at 0x002b2014... (97 %)
Writing at 0x002b7b68... (98 %)
Writing at 0x002bdf1c... (99 %)
Writing at 0x002c399f... (100 %)
Wrote 2846608 bytes (1697000 compressed) at 0x00010000 in 24.5 seconds (effective 928.0 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 120...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (120 compressed) at 0x00008000 in 0.0 seconds (effective 513.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Done

書き込み完了のようです。

まとめ

Windows10 でも npm をつかって書き込みができるようなりました。
よかったよかった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?