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?

Raspberrt Pi Pico + vscode + Raspberry Pi Pico Visual Studio Code extensionで WSL2に環境つくってサンプルをビルドして実行する

Last updated at Posted at 2025-10-27

はじめに

WSLに接続したvscodeでPicoSDKのサンプルプロジェクトをビルド&実行してもエラーが発生して実行できない
これはWSLからUSB接続されたRaspberry Pi Picoが認識できないからである
この文章ではWSLからRaspberry Pi Picoにアクセスする手順を記述する

作業環境

  • Windows 11 Pro 25H2
  • WSL バージョン: 2.6.1.0
  • Visual Studio Code バージョン: 1.105.1
  • usbipd バージョン54+Branch.master.Sha.aa3db8b82c4cb5071fd31bc54211606c70886912.aa3db8b82c4cb5071fd31bc54211606c70886912

用意するもの

  • Raspberry Pi Pico
  • Raspberry Pi PicoとPCを接続する A - Micro B のUSBケーブル

準備

WSLアップデート

いろいろする前にWSLをアップデートしておく。

wsl --update
wsl --shutdown

vscodeのインストール

詳細は割愛

Raspberry Pi Pico Visual Studio Code extension

  • vscodeを開いてwslに接続する。
  • 左のアイコンから下記調機能(Ctrl+Shift+X)をクリック
  • テキストボックスに「raspberry pi pico」をタイプ
  • 検索結果にある「Raspberry Pi Pico」をクリック
  • インストールクリック

usbipd-winのインストール

Windowsに接続されているUSBデバイスをほかのPCや仮想環境からアクセスさせるためのものらしい

winget install usbipd

ローカルPCに接続されたPicoをWSLからアクセスできるようにする

以下の手順でPCに接続されたPicoがWSLからアクセスできるようになる

  • Rapberry Pi PicoをBOOTDSELで接続する
    エクスプローラーにPicoのドライブがあるなら「取り出し」しておく

  • 管理者権限でPowerShellを開いて次を実行

    > usbipd list
    

    WindowsがRaspberry Pi Picoを認識していれば以下のような出力がある
    BUSID 4-1がRaspberry Pi Pico

    Connected:
    BUSID  VID:PID    DEVICE                                                        STATE
    2-2    0b05:19af  AURA LED Controller, USB 入力デバイス                         Not shared
    2-25   0499:172f  Steinberg UR22C, DAW (4- Steinberg UR22C), Music (4- Stei...  Not shared
    4-1    2e8a:0003  USB 大容量記憶装置, RP2 Boot                                  Not shared
    5-2    117f:4004  USB 入力デバイス                                              Not shared
    5-3    046d:c52b  Logitech USB Input Device, USB 入力デバイス                   Not shared
    
    Persisted:
    GUID                                  DEVICE
    
  • ひきつづきPowerShellで以下を実行

    > usbipd bind --busid 4-1
    

    成功すると usbpid listのSTATEがSharedになる

    4-1    2e8a:0003  USB 大容量記憶装置, RP2 Boot                                  Shared  
    
  • WLSとRaspberry Pi Picoを接続する

    • この手順は管理者権限でなくてもよい
    • 別のターミナルでwslを実行しておくこと
    > usbipd.exe attach --wsl --busid 4-1
    usbipd: info: Using WSL distribution 'Ubuntu' to attach; the device will be  available in all WSL 2 distributions.
    usbipd: info: Detected networking mode 'mirrored'.
    usbipd: info: Using IP address 127.0.0.1 to reach the host.
    
    
  • UDEVルールファイルの作成

    WSLから管理者権限なしでRaspberry Piにアクセスできるようにする

    • /etc/udev/rule.d/99-pico.rules

      SUBSYSTEM=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE="0666"
      
      $ sudo udevadm control --reload-rules && sudo udevadm trigger
      

以上でWSLからPicoにアクセスできるようになった
lsusbコマンドでubuntuからPicoが見えるのが確認できる

satoshi@PC1:/mnt/c/Users/tatam$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 2e8a:0003 Raspberry Pi RP2 Boot
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

ビルド&実行

vscodeはwslに接続され、サンプルプロジェクトを開いているとする

  • Run Project(USB)をクリックするとビルド&実行する
    image.png

    image.png

おわり

以上でビルド&実行ができるようになった

IMG_2025-10-27-22-55-34-707 - コピー.jpg

トラブル

  • vscodeで実行時にエラーが発生する
P2040 device at bus 1, address 3 appears to be in BOOTSEL mode, but picotool was unable to connect. Maybe try 'sudo' or check your permissions.

ユーザー権限でPicoにアクセスしようとしてエラーが発生している
UDEVルールファイルを作成してユーザー権限でアクセスできるようにする

  • usbipd attachでエラーが発生する
usbipd.exe attach --wsl --busid 4-1

usbipd: error: There is no WSL 2 distribution running; keep a command prompt to a WSL 2 distribution open to leave it running.

別のターミナルでwlsを実行しておく

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?