ESP-WROOM-32をARM-USB-TINYでGDBデバッグする †ESP-WROOM-32 で hello,world サンプルプログラムが動いたので,「次はデバッガだよね」ということで GDB でデバッグできるようにしてみました. 環境 †
構成 †OpenOCD で JTAG プロトコル ←→ GDB プロトコルの変換をさせるという,組み込みではよくある構成です. 図にするとこんな感じかな. +--------------- Linux PC ------------+ | | ESP-WROOM-32 <--(JTAG)--> ARM-USB-TINY <--(USB)-|-> OpenOCD <--(TCP loopback)--> GDB | | | +-------------------------------------+ OpenOCD のインストール †ここの説明に従って,コンパイル済みの tarball をダウンロードし,~/esp で展開します. デバッグされるプログラムの用意 †デバッグ対象となるプログラムを用意します. 今回は ESP32 のサンプルプログラムの「hello,world 」を少しいじりました. main/hello_world_main.c ファイルの app_main() 中で
ようにしました. デバッガに接続したままリセットがかかると,デバッガとの同期が外れてうまく動きません. このプログラムをターゲットボードに書き込みます. ESP-WROOM-32 と ARM-JTAG-TINY の接続 †ESP-WROOM-32 と ARM-JTAG-TINY を以下の表に従って接続します.
ARM-USB-TINY のピン番号はここの図を参考にしましょう. 今回はブレッドボードワイヤで接続しました. 一時的なものでなく使いつづけるのならば,きちんとしたものを工作したほうが良いかと思います. OpenOCD の起動 †JTAG アダプタを接続し,OpenOCD を起動します. $ cd ~/esp/openocd-esp32 $ bin/openocd -s share/openocd/scripts -f interface/ftdi/olimex-jtag-tiny.cfg -f \ board/esp-wroom-32.cfg Open On-Chip Debugger 0.10.0-dev-ga859564 (2017-07-24-16:16) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html adapter speed: 20000 kHz force hard breakpoints Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling" Info : clock speed 20000 kHz Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1) Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1) Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F). Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F). GDB の起動 †OpenOCD を動かしているものとは別にターミナルを開いて GDB を起動します. $ cd ~/esp/hello_world/ $ xtensa-esp32-elf-gdb build/hello-world.elf GNU gdb (crosstool-NG crosstool-ng-1.22.0-73-ge28a011) 7.10 Copyright (C) 2015 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=x86_64-build_pc-linux-gnu --target=xtensa-esp32-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from build/hello-world.elf...done. (gdb) target remote localhost:3333 Remote debugging using localhost:3333 0x00000001 in ?? () (gdb) c あとは,普通に GDB デバッグするだけです. 注意としては,プログラムのコードは ROM 上にあるので,通常のブレークポイントは使えません. 代わりにハードウェアブレークポイントを使います. 例えば (gdb) b 37 などでブレークポイントを設定していたところを (gdb) hb 37 とするだけです. |