LoginSignup
0
0

More than 1 year has passed since last update.

Raspberry Pi 3B+ と Olimex ARM-USB-OCD-H の接続

Last updated at Posted at 2022-03-26

目的

Raspberry Pi 3B+ と Olimex ARM-USB-OCD-H を接続してデバッグできるようにする

設定するもの

  • ホストPC(Ubuntu 20.04.4 LTS)
  • ターゲット(Raspberry Pi 3B+)
  • デバッガ(ARM-USB-OCD-H)

Olimex ARM-USB-OCD-Hとは

2V未満の用途にも使いたいのでこれを選びました。価格は、税込み7700円。

ホストPC

OpenOCDのインストール

パッケージは0.10系なので、0.11系のソースコードをダウンロードしてインストールしました。

$ git clone https://git.code.sf.net/p/openocd/code openocd-code

ビルドに必要なライブラリをインストールします。

$ sudo apt-get install libusb-1.0.0-dev libftdi-dev

ビルドします。configureのオプションはちゃんと調べず適当です。

$ cd openocd-code
$ ./bootstrap
$ ./configure --prefix=/opt/openocd --enable-ftdi --enable-armjtagew --enable-bcm2835gpio
$ make -j8
$ sudo make install

/opt/openocd/binPATH に追加しておきます。

udevの設定

一般ユーザでデバイスにアクセスできるように以下の設定をします。

$ sudo vi /etc/udev/rules.d/99-openocd.rules

中身は以下

SUBSYSTEM=="usb", ATTR{idVendor}=="15ba", ATTR{idProduct}="002b", MODE="0666"

ターゲットの設定

あらかじめSDカードにRaspbianをインストールしています。

/boot/config.txtに以下の設定を追加します。ホストPCでSDカードをマウントして編集でもよいし、RaspberryPiを起動して編集でも良いです。私はJTAGとは別にUARTもつないでいるので以下の設定になっています。

[all]
enable_uart=1
uart_2ndstage=1
enable_jtag_gpio=1

ターゲットとデバッガの接続(私のハマりポイント)

下図は、デバッガ本体のピン配置です。今回私はリボンケーブルとターゲットを接続したので、左右を入れ替える必要がありました(ここでハマった)。

image.png

ターゲット本体のピン配置は以下を参照しました。

Host Target (コネクタを右側にしたときの場所)
1 VREF GPIO-17(上から9番目左)
3 TRST GPIO-22(上から8番目左)
5 TDI GPIO-26(下から2番目左)
7 TMS GPIO-27(上から7番目左)
9 TCK GPIO-25(上から11番目右)
11 RTCK GPIO-23(上から8番目右)
13 TDO GPIO-24(上から9番目右)
18 GND Ground(下から1番目左など)

結果こんな感じです。

image.png

別角度から。

image.png

起動

ターゲットに電源を投入後、デバッガをホストにUSB接続します。

ホストで以下のコマンドを実行します。

$ openocd -f /opt/openocd/share/openocd/scripts/interface/ftdi/olimex-arm-usb-ocd-h.cfg -f /opt/openocd/share/openocd/scripts/target/bcm2837.cfg 
Open On-Chip Debugger 0.11.0+dev-00626-g92c4e634d (2022-03-25-00:39)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 4000 kHz
Info : JTAG tap: bcm2837.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x4)
Info : bcm2837.cpu0: hardware has 6 breakpoints, 4 watchpoints
Info : bcm2837.cpu1: hardware has 6 breakpoints, 4 watchpoints
Info : bcm2837.cpu2: hardware has 6 breakpoints, 4 watchpoints
Info : bcm2837.cpu3: hardware has 6 breakpoints, 4 watchpoints
Info : gdb port disabled
Info : starting gdb server for bcm2837.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
Info : starting gdb server for bcm2837.cpu1 on 3334
Info : Listening on port 3334 for gdb connections
Info : starting gdb server for bcm2837.cpu2 on 3335
Info : Listening on port 3335 for gdb connections
Info : starting gdb server for bcm2837.cpu3 on 3336
Info : Listening on port 3336 for gdb connections

新たにターミナルを立ち上げ、openocdにtelnetで接続します。

$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reg
===== Aarch64 registers
(0) x0 (/64)
(1) x1 (/64)
(2) x2 (/64)
(3) x3 (/64)
(4) x4 (/64)
(5) x5 (/64)
(6) x6 (/64)
(7) x7 (/64)
(8) x8 (/64)
~省略~

以上です。

おまけ

OpenOCD 0.10

パッケージでインストールした OpenOCD 0.10 では以下のエラーが出て解消できませんでした。(設定やJTAGの結線が悪かった可能性もある)

Warn : Haven't made progress in mpsse_flush() for 2126ms.
Warn : Haven't made progress in mpsse_flush() for 4166ms.
Warn : Haven't made progress in mpsse_flush() for 8247ms.
Warn : Haven't made progress in mpsse_flush() for 16152ms.
Warn : Haven't made progress in mpsse_flush() for 32217ms.

JTAGの結線

JTAGの結線でハマりました。接続を間違えていると以下のようなエラーが出ます。

Open On-Chip Debugger 0.11.0+dev-00626-g92c4e634d (2022-03-25-00:39)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 4000 kHz
Error: JTAG scan chain interrogation failed: all zeroes
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway...
Error: bcm2837.cpu: IR capture error; saw 0x00 not 0x01
Warn : Bypassing JTAG setup events due to errors
Error: Invalid ACK (0) in DAP response

参考URL

https://metebalci.com/blog/bare-metal-raspberry-pi-3b-jtag/
https://qiita.com/toshinaga/items/146bcb00db235258162f
https://logmi.jp/tech/articles/326201
https://datasheets.raspberrypi.com/rpi3/raspberry-pi-3-b-plus-reduced-schematics.pdf
https://www.raspberrypi.com/documentation/computers/processors.html#bcm2837b0
https://tnishinaga.hatenablog.com/entry/2015/04/04/033445
https://chakoku.hatenablog.com/entry/2020/08/27/192925
https://hikalium.hatenablog.jp/entry/2021/07/18/214013#openocd%E3%81%AE%E8%A8%AD%E5%AE%9A
https://qiita.com/toshinaga/items/146bcb00db235258162f

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