1
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?

Zephyr GDB Debugging (ESPr Developer C5)

1
Posted at

概要

ESPr Developer C5における、GDBデバッグ方法の備忘録

ボード

こちらを使う
https://www.switch-science.com/products/11006?srsltid=AfmBOoq54-kr72NTj_jUejbaxnD8zaOm0SUWOTfRFQro-CQgenMAn7DU

Zephyrとしては、以下のボードとして扱う。
https://docs.zephyrproject.org/latest/boards/espressif/esp32c5_devkitc/doc/index.html

ZephyrRTOS version

-- Zephyr version: 4.4.99 (/home/tqm/zephyrproject/zephyr), build: v4.4.0-1781-g718dfc7d4445

Patch

ESPr Developer C5はZephyrがサポートするESP32-C5-DevKitC-1と互換性がある。
ただし、
ESPr Developer C5 は "USB Type-C to UART Port" を搭載しておらず、
UARTはピンアウトしているGPIOから引き出す必要があり面倒なので、USBシリアルからコンソール出力を得られるように、DTSを以下のように修正する必要があった。

diff --git a/boards/espressif/esp32c5_devkitc/esp32c5_devkitc_hpcore.dts b/boards/espressif/esp32c5_devkitc/esp32c5_devkitc_hpcore.dts
index c35774b6ea9..bc0374781ba 100644
--- a/boards/espressif/esp32c5_devkitc/esp32c5_devkitc_hpcore.dts
+++ b/boards/espressif/esp32c5_devkitc/esp32c5_devkitc_hpcore.dts
@@ -17,8 +17,8 @@
 
 	chosen {
 		zephyr,sram = &sramhp;
-		zephyr,console = &uart0;
-		zephyr,shell-uart = &uart0;
+		zephyr,console = &usb_serial;
+		zephyr,shell-uart = &usb_serial;
 		zephyr,flash = &flash0;
 		zephyr,code-partition = &slot0_partition;
 		zephyr,ieee802154 = &ieee802154;
@@ -40,6 +40,11 @@
 	};
 };
 
+&usb_serial {
+	status = "okay";
+	current-speed = <115200>;
+};
+
 &uart0 {
 	status = "okay";
 	current-speed = <115200>;

ビルド

適当なサンプルをビルドする

$ west build -b esp32c5_devkitc/esp32c5/hpcore --sysbuild samples/synchronization

Flash

https://www.switch-science.com/products/11006?srsltid=AfmBOoq54-kr72NTj_jUejbaxnD8zaOm0SUWOTfRFQro-CQgenMAn7DU
の注意書き

注意

商品出荷時、ESP32-C5-WROOM-1にソフトウェアは何も書き込まれていません。その為パソコンに接続するとリセット動作を繰り返します。初回ソフトウェア書き込み時はダウンロードモードで起動し書き込みを行ってください。

の通り、リセットを繰り返しているログが出て、west flashでも言うことを聞かなかったので、
以下のように、直接 esptoolでブートローダだけを書き込むと大人しくなった。

$ sudo esptool --chip esp32c5 --port /dev/ttyACM0 --baud 921600 --before default-reset --after hard-reset write-flash -u --flash-mode dio --flash-freq 80m --flash-size 8MB 0x2000 ~/zephyrproject/zephyr/build/mcuboot/zephyr/zephyr.bin

動作確認

普通に書き込む

$ west flash

/dev/ttyACM* に接続して起動ログを確認しておく。

*** Booting Zephyr OS build v4.4.0-1781-g718dfc7d4445 ***
thread_a: Hello World from cpu 0 on esp32c5_devkitc!
thread_b: Hello World from cpu 0 on esp32c5_devkitc!
thread_a: Hello World from cpu 0 on esp32c5_devkitc!

Debuggerの起動

Espressifが提供しているカスタム版のOpenOCD
https://github.com/espressif/openocd-esp32/releases
をダウンロードして、適当な場所に配置。

$ sudo tar xvf openocd-esp32-linux-amd64-0.12.0-esp32-20260424.tar.gz -C /opt/
$ /opt/openocd-esp32/bin/openocd --version
Open On-Chip Debugger v0.12.0-esp32-20260424 (2026-04-24-15:13)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html

OpenOCDから、このボードの設定ファイルを指定してGDBサーバを起動する。

$ /opt/openocd-esp32/bin/openocd \
  -s /opt/openocd-esp32/share/openocd/scripts \
  -s ~/zephyrproject/zephyr/boards/espressif/esp32c5_devkitc/support \
  -f ~/zephyrproject/zephyr/boards/espressif/esp32c5_devkitc/support/openocd.cfg

そして、GDBクライアントを起動

$ ~/zephyr-sdk-1.0.0/gnu/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gdb

ターゲットに接続し、elfの読み込み、リセット、実行などの操作ができることを確認する

(gdb) target remote localhost:3333
(gdb) file ~/zephyrproject/zephyr/build/synchronization/zephyr/zephyr.elf
(gdb) monitor reset halt
JTAG tap: esp32c5.tap0 tap/device found: 0x00017c25 (mfg: 0x612 (Espressif Systems), part: 0x0017, ver: 0x0)
JTAG tap: esp32c5.tap1 tap/device found: 0x00017c25 (mfg: 0x612 (Espressif Systems), part: 0x0017, ver: 0x0)
[esp32c5] Reset cause (24) - (JTAG CPU reset)
(gdb) c
Continuing.

感想

オンチップデバッガは便利

1
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
1
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?