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?

Raspberry Pi Pico をデバッグプローブとして使用する方法

0
Last updated at Posted at 2025-08-19

Raspberry Pi Pico をデバッグプローブとして使用する方法

目次


0. 必要なもの

  • デバッグプローブ (Raspberry Pi Pico)
  • デバッグ対象のマイコン(Raspberry Pi Pico2)
  • USBケーブル(データ通信可能なもの)
  • 接続用のジャンパーワイヤ (4本)

1. Pico SDK/Exampleのビルドと動作確認

1.1 Pico SDKに必要なパッケージのインストール

sudo apt update
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential git

1.2 Pico SDKのダウンロード

cd ~
git clone -b master https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init

1.3 Pico SDKの環境変数の設定

echo 'export PICO_SDK_PATH=~/pico-sdk' >> ~/.bashrc
source ~/.bashrc

1.4 Pico Exampleのビルド

cd ~
git clone -b master https://github.com/raspberrypi/pico-examples.git
cd pico-examples
git submodule update --init
mkdir build_pico2
cd build_pico2
cmake .. -DPICO_PLATFORM=rp2350 -DPICO_BOARD=pico2 
make -j$(nproc)

1.5 Pico Exampleの動作確認

Pico SDK を正しくインストールしたか確認するために、公式の「blink」サンプルをPico2で動作させます。

Pico2を BOOTSEL モードで接続し、ファイルをコピー:

cd blink
cp blink.uf2 /media/$USER/RP2350/

LEDが点滅すればOKです。

2. Debugprobeのインストール

2.1 Debugprobeのダウンロード

cd ~
mkdir debugprobe; cd debugprobe
wget https://github.com/raspberrypi/debugprobe/releases/download/debugprobe-v2.2.3/debugprobe_on_pico.uf2

2.2 Debugprobeのインストール

Picoを BOOTSEL モードで接続し、ファイルをコピー:

cp debugprobe_on_pico.uf2 /media/$USER/RPI-RP2/

3. ハードウェアの接続

Raspberry Pi Pico(Picoprobe)とターゲットボード(デバッグ対象)を以下のように接続します。

信号 Pico (Picoprobe) ターゲットボード
SWCLK GP2 (Pin4) DEBUG SWCLK
SWDIO GP3 (Pin5) DEBUG SWDIO
SRST GP4 (Pin6) RUN (Pin30)
GND GND (Pin3) DEBUG GND

4. OpenOCDのビルドと動作確認

4.1 OpenOCDに必要なパッケージのインストール

sudo apt install texinfo libtool libhidapi-dev libusb-1.0-0-dev libftdi1-dev pkg-config

4.2 OpenOCDのダウンロード

cd ~
git clone https://github.com/raspberrypi/openocd.git --branch picoprobe --depth=1
cd openocd

4.3 OpenOCDのビルド

./bootstrap
./configure --enable-picoprobe --enable-cmsis-dap
make -j$(nproc)
sudo make install

4.4 OpenOCDの動作確認方法

リセットに、SRSTを使う場合と、SYSRESETREQを使う場合があります。

SRST SYSRESETREQ
仕組み デバッグアダプタ(CMSIS-DAP, J-Link など)が ターゲットの nRESET ピン を物理的にアサートして、チップ全体をハードリセットします。 SWD経由でデバッグアダプタが Cortex-MのAIRCR(Application Interrupt and Control Register)にある SYSRESETREQ ビット をセットする。すると CPU が内部的にリセットをかけ、ベクタアドレスから再実行を開始する。
特徴
  • チップが 電源投入直後と同じ状態に戻る(周辺ブロック、I/O、クロックなどもすべて初期化)。
  • デバッグロジック(SWD/JTAG の DAP 部分)も一瞬リセットされる場合がある。そのため、OpenOCD は「リセット中もSWD接続を維持できるか?」を srst_nogate などで調整する必要がある。
  • ROM の最初に戻るが、ベクタキャッチが効かない場合がある(デバッガがリセット後に再接続するタイミング次第)。
  • SWD/JTAGインターフェース自体はリセットされない → デバッグ接続が維持される。
  • リセットベクタ(ROM内の初期コード)に必ずジャンプするため、cortex_m vector_catch reset が有効に働きやすい。
  • 一部の外部回路(GPIO状態や外部デバイス)はリセットされないことがある。
メリット
  • 完全にクリーンな状態からデバッグ開始できる。
  • 電源オン直後と同じ条件を再現しやすい。
  • デバッグ接続が安定して維持できる。デバッグ中に「ROMの最初から実行し直したい」「リセットベクタで確実に止めたい」場合。デバッグ接続が安定するので日常的なデバッグはこちらが便利。
  • ROMの先頭やReset_Handlerに確実に止めやすい。
デメリット
  • デバッガとの接続が不安定になる場合がある。
  • 一部の環境ではリセット後に「つかみ損なう」ことがある(ROMの頭で止められない)。
  • 外部ハード(I/Oピンや周辺)が完全には初期化されないため、実際の電源投入直後とは微妙に条件が異なることがある。
  • 例えば、電源投入時のブートROMがピンのストラップや外部状態を読む処理が、SYSRESETREQでは再現されない場合がある。

4.4.1 リセットに、SRSTを使う場合

cd /usr/share/openocd/scripts

sudo openocd \
    -f interface/cmsis-dap.cfg \
    -f target/rp2350.cfg \
    -c "adapter speed 1000; \
        adapter srst pulse_width 400; \
        adapter srst delay 600; \
        reset_config \
            srst_only \
            srst_open_drain \
            connect_assert_srst \
            srst_nogate; \
        init; \
        targets rp2350.dap.core0; \
        cortex_m vector_catch all; \
        reset halt"

  1. -f interface/cmsis-dap.cfg
    CMSIS-DAP インターフェース用の設定ファイルを読み込む
  2. target/rp2350.cfg
    RP2350(Raspberry Pi Pico 2)のターゲット設定ファイルを読み込む
  3. adapter speed 1000
    SWDクロック速度を1000kHz に設定
  4. adapter srst pulse_width 400
    SRST信号を400ms間アサート(長めのリセットパルス)
  5. adapter srst delay 600
    SRST解除後に600ms待ってから通信開始(起動安定化)
  6. reset_config
    リセット関連の設定を指定する
  7. srst_only
    OpenOCD に「TRST(JTAGリセット)は使わない、SRST(システムリセット)のみ使う」と伝えます。つまり システムリセットピン(nRESET)だけでリセットを制御する設定です。ARM Cortex-M 系(RP2350 もそう)では TRST が無いので通常この指定になります。
  8. srst_open_drain
    SRST 信号を オープンドレイン出力として駆動します。nRESET ラインは多くのデバイスでオープンドレイン構成になっているため、安全のためこの設定を使うことがあります。実際には デバッガ側がリセット線を強くドライブせず、GND に落とすか Hi-Z にする方式です。
  9. connect_assert_srst
    「ターゲットに接続するときに、常にリセットを押し下げた状態で接続する」という意味です。これにより、ターゲットが暴走中でも確実に SWD/JTAG 接続を確立できます。特に RP2350 のように、ROM ブートコードがすぐ動き始めるデバイスでは有効。
  10. srst_nogate
    「SRST とデバッグポートのリセット(TRST)を連動させない」という指定です。一部のデバッガは「SRST を押すと内部的に TRST も一緒に制御」することがありますが、それを禁止する設定。Cortex-M では TRST が存在しないため、srst_nogate を指定しないと警告が出ることが多いです。
  11. init
    OpenOCDの初期化を実行し、ターゲットに接続
  12. targets rp2350.dap.core0
    デバッグ対象をRP2350のCore0に指定
  13. cortex_m vector_catch all
    すべての例外・リセットイベントで自動停止(HardFault等も含む)
  14. reset halt
    ターゲットをリセット後、直ちに停止状態で制御を保持。

4.4.2 リセットに、SYSRESETREQを使う場合

sudo openocd \
    -f interface/cmsis-dap.cfg \
    -f target/rp2350.cfg \
    -c "adapter speed 1000; \
    cortex_m reset_config sysresetreq; \
    init; \
    targets rp2350.dap.core0; \
    cortex_m vector_catch all; \
    reset halt"

「4.4.1のリセットに、SRSTを使う場合」との差分だけ説明します。

  1. cortex_m reset_config sysresetreq
    SWD経由でデバッグアダプタが Cortex-MのAIRCR(Application Interrupt and Control Register)にある SYSRESETREQ ビット をセットする。

5. GDB起動

5.1 GDBのダウンロード

sudo apt install gdb-multiarch

5.2 GDB起動

Pico2にblinkをロードして、デバッグする例です。「4.4.2 リセットに、SYSRESETREQを使う場合」で、事前にOpenOCDサーバーを起動しています。

$ cd ~/pico-examples/build_pico2/blink

$ gdb-multiarch blink.elf

(gdb) target extended-remote :3333     # OpenOCDのGDBサーバ(port 3333)に接続
Remote debugging using :3333
warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread
0x00000088 in ?? ()

(gdb) load                             # ELFファイルをターゲットのFlashへ書き込み
Loading section .rodata, size 0x124 lma 0x1000156c
Loading section .binary_info, size 0x20 lma 0x10001690
Loading section .data, size 0x144 lma 0x100016b0
Loading section .flash_end, size 0x14 lma 0x100017f4
Start address 0x1000014c, load size 6152
Transfer rate: 2 KB/sec, 1230 bytes/write.

(gdb) thbreak main                     # main() 関数に一時的なブレークポイントを設定
Hardware assisted breakpoint 1 at 0x10000274: file /home/$USER/pico-examples/blink/blink.c, line 24.

(gdb) continue                         # 実行再開(mainや任意ブレークまで進む)
Continuing.

Thread 1 "rp2350.dap.core0" hit Temporary breakpoint 1, main () at /home/kusano/pico-examples/blink/blink.c:24
24	    gpio_init(PICO_DEFAULT_LED_PIN);

(gdb) 

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?