本文基于ubuntu18.04进行操,作说明如何通过Jtag adpter oocdlink连接esp8266,并通过openocd进行调试。
简述
手上有一片oocdlink和esp-12模块,因此想通过Openocd连接esp8266进行调试,在网上查阅资料后发现可行,将过程记录。
oocdlink使用FTDI的FT2232作为住芯片,理论上来说只要openocd支援的FTDI 芯片的jtag adapter都可以使用该方法进行连接。
硬件准备
我的Jtag-adpter是很久以前的oocdlink,现在网上已经找不到原理图了,jtag口的标准的按照下面方式和esp-12模块进行连接即可
JTAG signal TMS ==> ESP8266 GPIO 14
JTAG signal TDI ==> ESP8266 GPIO 12
JTAG signal TCK ==> ESP8266 GPIO 13
JTAG signal TDO ==> ESP8266 GPIO 15
JTAG signal RST ==> ESP8266 GPIO RST
下面是esp12的原理图
Openocd for esp8266
下载openocd for esp8266代码
git clone https://github.com/sysprogs/esp8266-openocd.git ~/work/build/esp8266-openocd-master
安装依赖
1 | sudo apt-get install libtool autoconf texinfo libusb-1.* |
编译
1 | sudo ./configure --enable-ftdi --disable-werror |
使用
Interface配置
信息查看
Ubuntu自带FT2232的驱动,将JTAG Adapter oocdlink连接PC上执行下面命令1
dmesg | tail
看到下面的字样说明pc已经识别到ooclink,ttyUSB0是用于JTAG调试,ttyUSB1是USB串口1
2
3
4
5
6
7
8
9
10[ 3878.302137] usbcore: registered new interface driver usbserial_generic
[ 3878.302926] usbserial: USB Serial support registered for generic
[ 3878.312610] usbcore: registered new interface driver ftdi_sio
[ 3878.312683] usbserial: USB Serial support registered for FTDI USB Serial Device
[ 3878.312809] ftdi_sio 2-1.1:1.0: FTDI USB Serial Device converter detected
[ 3878.312901] usb 2-1.1: Detected FT2232C
[ 3878.315157] usb 2-1.1: FTDI USB Serial Device converter now attached to ttyUSB0
[ 3878.315311] ftdi_sio 2-1.1:1.1: FTDI USB Serial Device converter detected
[ 3878.315397] usb 2-1.1: Detected FT2232C
[ 3878.316238] usb 2-1.1: FTDI USB Serial Device converter now attached to ttyUSB1
执行下面命令查看VID/PID1
lsusb
会列出所有的USB信息,可以看到FT2232的VID/PID是0403:60101
2
3
4
5
6
7
8Bus 002 Device 004: ID 17ef:4811 Lenovo Integrated Webcam [R5U877]
Bus 002 Device 003: ID 0425:0001 Motorola Semiconductors HK, Ltd
Bus 002 Device 005: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
配置文件修改
以oocdlink为蓝本创建新的配置文件1
2cd ~/work/build/esp8266-openocd-master/tcl/interface/ftdi/
cp oocdlink.cfg esplink.cfg
按照前面的vendor码进行修改,修改后的esplink.cfg如下:1
2
3
4
5
6
7interface ftdi
#ftdi_device_desc "OOCDLink" -->直接使用VID和PID识别更准确,如果用desc可能会识别不到
ftdi_vid_pid 0x0403 0x6010
ftdi_layout_init 0x0508 0x0f1b
ftdi_layout_signal nTRST -data 0x0200 -noe 0x0100
ftdi_layout_signal nSRST -data 0x0800 -noe 0x0400
连接
在终端中执行1
2cd ~/work/build/esp8266-openocd-master/
sudo ./src/openocd -f ./tcl/interface/ftdi/esplink.cfg -f ./tcl/target/esp8266.cfg
看到如下说明oocdlink连接esp12成功1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18Open On-Chip Debugger 0.9.0 (2018-06-25-22:16)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
WARNING!
This file was not tested with real interface, but is assumed to work as this
interface uses the same layout as configs that were verified. Please report your
experience with this file to openocd-devel mailing list, so it could be marked
as working or fixed.
trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain connect_deassert_srst
adapter speed: 1000 kHz
stop_wdt
Info : clock speed 1000 kHz
Info : TAP esp8266.cpu does not have IDCODE
Warn : Warning: Target not halted, breakpoint/watchpoint state may be unpredictable.
target state: halted
Info : halted: PC: 0x0
Info : debug cause: 0x0
调试
openocd的调试可以用两种方式连接,连接成功后的debug方式可以参见openocd和gdb文档1
2telnet localhost 4444
gdb localhost 3333
参考
https://visualgdb.com/tutorials/esp8266/nodemcu/jtag/
https://bbs.espressif.com/viewtopic.php?t=1666