yk-hiro’s handicrafts / ひろ’s ジャンク箱

電子回路やマイコンプログラムについて チラシの裏に書いていく感じのブログ

ラズパイPico の picotool を使う

こんばんは!!

熱帯夜ですね

それでは本題です

今回の目的

プログラムのデバックを準備していたら debugprobe_on_pico.uf2 を書き込んだはずの Pico 1 が OpenOCD に反応していないようだったので picotool 2で Pico の中身を確認する

picotoolを使う準備

picotool は コマンドプロンプトDOS窓)で使うので cmd.exe を起動する

  1. タスクバーの検索アイコンで cmd と打って コマンドプロンプトを起動する
  2. picotoolのあるディレクトリに Path を通しておきたいので コマンドラインPATH=%PATH%;C:\<SDKのインストールディレクトリ>\picotool;と打って Pathに追加する 3.4
    <SDKのインストールディレクトリ>の部分は各々に合わせて修正する
  3. コマンドラインpicotool と打ってみる

     PICOTOOL:
         Tool for interacting with a RP2040 device in BOOTSEL mode, or with a RP2040 binary
    
     SYNOPSIS:
         picotool info [-b] [-p] [-d] [-l] [-a] [--bus <bus>] [--address <addr>]
            :(中略)
     COMMANDS:
         info      Display information from the target device(s) or file.
            :(中略)
     Use "picotool help <cmd>" for more info
    

    上記のように使い方が表示されれば準備完了

Picoの準備

PicoはBOOTSELモードにして使う

  1. Picoを BOOTSELモードにする 5
  2. エクスプローラーに PicoのUSBドライブ(RPI-RP2)が現れたか確認

picotoolを使う

  1. コマンドプロンプトpicotool info -a 6と打ってみる

     Program Information
      name:          debugprobe
      features:      PROBE UART INTERFACE uart1
                     PROBE UART BAUDRATE 115200
                     UART stdin / stdout
      binary start:  0x10000000
      binary end:    0x1000a2e0
    
     Fixed Pin Information
      0:   UART0 TX, UART0 TX
      1:   UART0 RX
      2:   PROBE SWCLK
      3:   PROBE SWDIO
      4:   PROBE UART TX
      5:   PROBE UART RX
      25:  LED
    
     Build Information
      sdk version:       1.5.1
      pico_board:        pico
      boot2_name:        boot2_w25q080
      build date:        Apr 16 2024
      build attributes:  Release
    
     Device Information
      flash size:   4096K
      ROM version:  3
    
  2. Picoボードの情報が表示された
    プログラムはdebugprobeが書き込まれているようだ

その他の使い方

Picoプログラムのファイルへの読み書きをする
コマンドプロンプトで 作業フォルダへ移動しておく

cd <作業フォルダのパス>

今回の作業フォルダは仮で C:\PICO\flash_image をつくった
書き込みの実験用に blink.uf2 をここにコピーしておく

  1. picotoolのSAVEコマンド
    picotool save -p <filename> -t uf2
    プログラムの読み出しとファイルへの保存

      C:\PICO\flash_image>picotool info
      Program Information
       name:      debugprobe
       features:  PROBE UART INTERFACE uart1
                  PROBE UART BAUDRATE 115200
                  UART stdin / stdout
    
      C:\PICO\flash_image>picotool save -p onboard_fw.uf2 -t uf2
      Saving file: [==============================]  100%
      Wrote 83456 bytes to onboard_fw.uf2
    
      C:\PICO\flash_image>dir
          :(中略)
      2024/07/04  23:33            83,456 onboard_fw.uf2
          :
    

    ファイル onboard_fw.uf2 にプログラムがSAVEされた

  2. picotoolのLOADコマンド
    picotool load <filename>
    ファイルを読み込んでPicoへプログラムを書き込み

      C:\PICO\flash_image>dir
         :(中略)
      2024/06/23  21:23            43,520 blink.uf2
      2024/07/04  23:33            83,456 onboard_fw.uf2
         :
    
      C:\PICO\flash_image>picotool load blink.uf2
      Loading into Flash: [==============================]  100%
    
      C:\PICO\flash_image>picotool reboot
      The device was rebooted into application mode.
    

    PicoをRebootすると blinkプログラムが走る
    再度 BOOTSELモードにして

      C:\PICO\flash_image>picotool info
      Program Information
       name:      blink
       web site:  https://github.com/raspberrypi/pico-examples/tree/HEAD/blink
    

    blinkプログラムが書き込まれているのがわかる
    1でSAVEした onboard_fw.uf2 を書き戻してみる

      C:\PICO\flash_image>picotool load onboard_fw.uf2
      Loading into Flash: [==============================]  100%
    
      C:\PICO\flash_image>picotool info
      Program Information
       name:      debugprobe
       features:  PROBE UART INTERFACE uart1
                  PROBE UART BAUDRATE 115200
                  UART stdin / stdout
    

    ファイルにSAVEしておいたプログラムに書き戻されているようである

次回は「picotool のPathを設定するBATファイル」です


  1. 正確には Pico 互換機の YD-RP2040
  2. picotoolのインストール先は C:\<SDKのインストールディレクトリ>\picotool の下にある
  3. システムのプロパティ-詳細設定タブ から 環境変数の設定でPathを追加してもよいが 間違えるとWindowsがいろいろと動かなくなるので要注意
  4. BATファイルを作ってその中で PATH を設定してもよい
  5. BOOTSELボタンを押しながらUSB接続 又はBOOTSELボタンを押しながらPicoをリセット
  6. infoコマンド:Picoボードの情報を読み出し、-aオプション:すべての情報を表示