ESP32调试工具与调试环境搭建 -- 单核芯片

在ESP32官网上有使用JTAG进行调试的详细介绍:ESP32 JTAG 调试。其中使用的例子是 ESP-WROVER-KIT 开发板,板载的是双核ESP32芯片。对于 ESP32-DevKitM-1开发板,板载的是单核芯片,调试时OpenOCD的配置需要做一些相应的改动。

先看看ESP-WROVER-KIT 开发板的配置、调试过程。

JTAG与目标板连接需要5根线,其中4个是JTAG信号线、1个是GND:


图一

参考链接:https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-guides/jtag-debugging/configure-ft2232h-jtag.html


图二

JTAG连接完毕后,先运行OpenOCD、相当于启动了一个代理目标板的GDB-SERVER:

    openocd -f board/esp32-wrover-kit-3.3v.cfg

OpenOCD运行时需要2个必须的参数:JTAG的interface配置文件和目标芯片的target配置文件。上面的 esp32-wrover-kit-3.3v.cfg 文件实际上是interface和target的集合,其内容如下:

# Source the JTAG interface configuration file

source [find interface/ftdi/esp32_devkitj_v1.cfg]

set ESP32_FLASH_VOLTAGE 3.3

# Source the ESP32 configuration file

source [find target/esp32.cfg]

它调用了ftdi子目录下的 esp32_devkitj_v1.cfg(乐鑫的JTAG配置文件)和 esp32.cfg(ESP32双核芯片通用配置文件),所以OpenOCD形式上调用了一个cfg配置,实际上还是调用了2个cfg配置文件。

对于单核的 ESP32-DevKitM-1开发板,如果仍使用:

    openocd -f board/esp32-wrover-kit-3.3v.cfg

来调试,得到出错信息:

Open On-Chip Debugger v0.10.0-esp32-20200709 (2020-07-09-08:54)

Licensed under GNU GPL v2

For bug reports, read

        http://openocd.org/doc/doxygen/bugs.html

Info : Configured 2 cores

Info : Listening on port 6666 for tcl connections

Info : Listening on port 4444 for telnet connections

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: 0xffffffff (mfg: 0x7ff (), part: 0xffff, ver: 0xf)

Warn : JTAG tap: esp32.cpu1      UNEXPECTED: 0xffffffff (mfg: 0x7ff (), part: 0xffff, ver: 0xf)

Error: JTAG tap: esp32.cpu1  expected 1 of 1: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)

Error: Trying to use configured scan chain anyway...

Error: esp32.cpu1: IR capture error; saw 0x1f not 0x01

Warn : Bypassing JTAG setup events due to errors

Info : Listening on port 3333 for gdb connections

提示 cpu1有关信息错误!实际上单核ESP32芯片上没有cpu1、出错是必然的。说明cfg配置文件出错了,需要修改 esp32-wrover-kit-3.3v.cfg,把target中的双核改为单核(JTAG的interface不用修改)。查看 esp32.cfg 所在目录:

a-user@ubuntu:~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20200709/openocd-esp32/share/openocd/scripts/target$ ls esp*.cfg -l

-rw-r--r-- 1 patrick patrick 1881 Jul  9  2020 esp32.cfg

-rw-r--r-- 1 patrick patrick  967 Jul  9  2020 esp32s2.cfg

-rw-r--r-- 1 patrick patrick  185 Jul  9  2020 esp32-solo-1.cfg

-rw-r--r-- 1 patrick patrick 3409 Jul  9  2020 esp_common.cfg

其中的 esp32-solo-1.cfg 就是针对单核芯片的cfg配置文件,乐鑫已经为我们准备好了,我们直接使用就行。仿照 esp32-wrover-kit-3.3v.cfg,在board目录下编写一个针对 ESP32-DevKitM-1开发板的配置文件:

a-user@ubuntu:~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20200709/openocd-esp32/share/openocd/scripts/board$ more esp32-DevKitM-1.cfg

# Source the JTAG interface configuration file

source [find interface/ftdi/esp32_devkitj_v1.cfg]

set ESP32_FLASH_VOLTAGE 3.3

# Source the ESP32 configuration file

source [find target/esp32-solo-1.cfg]

用 target/esp32-solo-1.cfg 替换 target/esp32.cfg。再次启动OpenOCD:

    openocd -f board/esp32-DevKitM-1.cfg

显示:

Licensed under GNU GPL v2

For bug reports, read

        http://openocd.org/doc/doxygen/bugs.html

Info : Configured 1 cores

Info : Listening on port 6666 for tcl connections

Info : Listening on port 4444 for telnet connections

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 : Listening on port 3333 for gdb connections

不再出现错误,GDB-CLIENT可以连接OpenOCD并进行断点调试了(略)。


【海东青电子原创文章,转载请注明出处:https://www.jianshu.com/p/34843c3c3930】

你可能感兴趣的:(ESP32调试工具与调试环境搭建 -- 单核芯片)