MacBook Air M2でPicoProbeをセットアップ
この記事でわかること
Raspberry Picoの公式ドキュメントを参考に、Bashプロンプトでアレコレ操作してコンパイル〜デバッグまでを行える環境を構築します。
ArudinoIDEやらVSCodeやらの記事は、他の方にお任せして、ここでは公式ドキュメントを参考に、コマンドラインで一通りの作業を行う方法を記事にしています。
コンパイル環境構築
事前に、コンパイル環境構築を完了させてください。
↓↓
MacBook Air M2でPi Picoのビルド環境構築
PicoProbeの作成
下記のURLのリンク【Debugging using another Raspberry Pi Pico】のDownload the UF2 fileからUF2ファイルをダウンロードします。
ファイル名:picoprobe.uf2
↓↓
Debugging using another raspberrypi pico
通常のプログラム書き込みと同様に、Pi Picoにpicoprobe.uf2を書き込みます。
↓↓
PipicoのBOOTボタン押しながら、MacbookにUSB接続。 → 外付けドライブとして「RPI-RP2」がFinderに認識される
picoprobe.uf2をRPI-RP2へコピー。
OpenOCDのビルド
必要なツールをインストール
$ brew install libtool automake libusb wget pkg-config gcc texinfo
ビルド
$ cd ~/pico $ git clone https://github.com/raspberrypi/openocd.git --branch rp2040-v0.12.0 --depth=1 $ cd openocd $ cd ./openocd $ export PATH="$(brew --prefix)/opt/texinfo/bin:$PATH" $ ./bootstrap $ ./configure --enable-picoprobe --disable-werror $ make -j4 $ sudo make install
OpenOCD実行
結果エラーになるけれど、実行できていればきにしない
$ src/openocd Open On-Chip Debugger 0.10.0+dev-gc231502-dirty (2020-10-15-07:48) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html embedded:startup.tcl:56: Error: Can't find openocd.cfg in procedure 'script' at file "embedded:startup.tcl", line 56 Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Error: Debug Adapter has to be specified, see "interface" command embedded:startup.tcl:56: Error: in procedure 'script' at file "embedded:startup.tcl", line 56
PicoProbeテスト
PicoProbeと開発ターゲット用のPiPicoを結線
Pico A GND -> Pico B GND Pico A GP2 -> Pico B SWCLK Pico A GP3 -> Pico B SWDIO Pico A GP4/UART1 TX -> Pico B GP1/UART0 RX Pico A GP5/UART1 RX -> Pico B GP0/UART0 TX Pico A VSYS -> Pico B VSYS
OpenOCD起動
$ openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg -s tcl
※~/opt/shell/openocd_pico.sh としてスクリプト化し活用しています。
Open On-Chip Debugger 0.12.0-g4d87f6d (2024-03-02-15:47) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html adapter speed: 5000 kHz Info : Hardware thread awareness created Info : Hardware thread awareness created Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E66044304317392D Info : CMSIS-DAP: SWD supported Info : CMSIS-DAP: Atomic commands supported Info : CMSIS-DAP: Test domain timer supported Info : CMSIS-DAP: FW Version = 2.0.0 Info : CMSIS-DAP: Interface Initialised (SWD) Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0 Info : CMSIS-DAP: Interface ready Info : clock speed 5000 kHz Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001 Info : SWD DPIDR 0x0bc12477, DLPIDR 0x10000001 Info : [rp2040.core0] Cortex-M0+ r0p1 processor detected Info : [rp2040.core0] target has 4 breakpoints, 2 watchpoints Info : [rp2040.core1] Cortex-M0+ r0p1 processor detected Info : [rp2040.core1] target has 4 breakpoints, 2 watchpoints Info : starting gdb server for rp2040.core0 on 3333 Info : Listening on port 3333 for gdb connections
実行ファイルの読込/実行
テストとして、サンプルのblinkを動かしてみます。
GDB起動
前項で動かしたOpenOCDのプロンプトはそのままに、新しくプロンプトを新規に開いて、以降のコマンドを実施します。
$ cd ~/pico/pico-examples/build/blink $ arm-none-eabi-gdb -q -ex "target extended-remote :3333" ./blink.elf
Reading symbols from ./blink.elf... (No debugging symbols found in ./blink.elf) Remote debugging using :3333 warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread 0x10000ce2 in sleep_until () (gdb)
プログラムのロード
(gdb) load
Loading section .boot2, size 0x100 lma 0x10000000 Loading section .text, size 0x1d88 lma 0x10000100 Loading section .rodata, size 0xf4 lma 0x10001e88 Loading section .binary_info, size 0x20 lma 0x10001f7c Loading section .data, size 0x18c lma 0x10001f9c Start address 0x100001e8, load size 8488 Transfer rate: 10 KB/sec, 1697 bytes/write.
プログラムの実行
(gdb) continue
プログラムの停止
Ctrl + c 操作で強制停止
(gdb) continue Continuing. ^C Thread 1 "rp2040.core0" received signal SIGINT, Interrupt. 0x10000ce2 in sleep_until () (gdb)
デタッチ
(gdb) detach Detaching from program: /Users/k/pico/pico-examples/build/blink/blink.elf, Remote target [Inferior 1 (Remote target) detached] (gdb)
終了
(gdb) quit