OpenOcd in OSX

rsimpsonbusa
Posts: 131
Joined: Tue May 17, 2016 8:12 pm

OpenOcd in OSX

Postby rsimpsonbusa » Fri Apr 21, 2017 3:56 pm

Wanted to share with you the setup, step by step, for a Mac with a Flyswatter2 JTAG debugger. Apparently it can be any JTAG debugger as long as the voltage is viable.

Anyway, the environment:
OSX 10.11.6
USB 2.0 or 3.0, both work
Flyswatter2 JTAG debugger http://www.tincantools.com/JTAG/Flyswatter2.html
DevKitC .

Cable connections.

The cable connections are very important and got it from https://gojimmypi.blogspot.com/2017/03/ ... esp32.html
They are EXACTLY as he sets them up, but to make it clear, considering a JTAG 20 pinout (look at the diagram for the notch to find pin 1)
JTAG - ESP32
1 - 3.3V (needs this to know what the Voltage is)
3 - EN (Really doesnt matter)
5 - 12 TDI
7 - 14 TMS
9 - 13 TCK
11 - GND
13 - 15 TDO
2 - GND

OpenOcd Installation

From EspressIf we have this document
https://espressif.com/sites/default/fil ... p32_en.pdf

Remember , this is for Mac.

First download the from git to your selected Directory

Code: Select all

git	clone	https://github.com/espressif/openocd-esp32.git
In the directory you will find a file README.OSX which tells you to install additional tools via Port or Brew. DONOT install openocd just the support apps:

Code: Select all

brew install libtool automake libusb [libusb-compat] [hidapi] [libftdi]
Now you have to build openocd

Code: Select all

git	submodule	init
git	submodule	update
./bootstrap
./configure
make install
Test openocd after build

Code: Select all

./src/openocd --version

Open On-Chip Debugger 0.10.0-dev-g90071eb (2017-04-20-17:09)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
USB Connection

Since almost all the JTAG debuggers will be USB based, openocd interfaces define certain parameters for it. A lot of the debuggers are FTDI based as is the case with this one.

For a Mac, that means you need to install the FTDI driver(if not already installed), which you can find at http://www.ftdichip.com/Drivers/VCP.htm. Download the version for Mac for your current OSX

I dont think u need to reboot, but it really doesnt hurt.

The problem with the FTDI driver for Mac is that it has two ports and it "confuses" openocd, so u need to remove the driver (in memory) and load it again with certain parameters EVERY TIME YOU BOOT.

Code: Select all

sudo kextunload -b com.FTDI.driver.FTDIUSBSerialDriver
sudo kextutil -b com.apple.driver.AppleUSBFTDI -p AppleUSBEFTDI-6010-1
OpenOcd Configuration File

EspressIf provides a openocd configuration file for the ESP32. You can find it in the esp-idf directory, docs, and its called esp32.cfg. So path, in my case, is ~/esp(my directory for espressif)/esp-idf/docs/esp32.cfg

Need to edit and change the JTAG debugger name,so change the line

Code: Select all

source [find interface/ftdi/tumpa.cfg] or whatever to 
source [find interface/ftdi/flyswatter2.cfg]
Copy this file to the opencod-esp32 directory.

Ready to Test

At this point you should be able to start the Debugger Server (the device itself).
cd to openocd-esp32 and open a Terminal session

./src/openocd -s ./tcl -f ./esp32.cfg

Should get

Code: Select all

Open On-Chip Debugger 0.10.0-dev-g90071eb (2017-04-20-17:09)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 1000 kHz
force hard breakpoints
Info : clock speed 1000 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.cpu0: Target halted, pc=0x40006737
If you get this (all ones....)

Code: Select all

Open On-Chip Debugger 0.10.0-dev-g90071eb (2017-04-20-17:09)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 1000 kHz
force hard breakpoints
Info : clock speed 1000 kHz
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway...
Error: esp32.cpu0: IR capture error; saw 0x1f not 0x01
Warn : Bypassing JTAG setup events due to errors
Info : esp32.cpu0: Debug controller was reset (pwrstat=0xFF, after clear 0xFF).
Info : esp32.cpu0: Core was reset (pwrstat=0xFF, after clear 0xFF).
Info : esp32.cpu1: Debug controller was reset (pwrstat=0xFF, after clear 0xFF).
Info : esp32.cpu1: Core was reset (pwrstat=0xFF, after clear 0xFF).
you have a cable error. Recheck your connections. Guaranteed a cable problem.

To finally test something, test gdb (open another terminal connection)

Code: Select all

~/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb -ex 'target remote localhost:3333'

You should see this in the OpenOcd terminal

Open On-Chip Debugger 0.10.0-dev-g90071eb (2017-04-20-17:09)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 1000 kHz
force hard breakpoints
Info : clock speed 1000 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.cpu0: Target halted, pc=0x400066C2
Info : accepting 'gdb' connection on tcp/3333
You are now connected....

Try telnet (open another terminal connection)

Code: Select all

telnet locahost 4444
Should see this in the OpenOcd terminal

Code: Select all

Info : accepting 'telnet' connection on tcp/4444
List a register
In the telnet Terminal

reg 1

Code: Select all

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reg 1
ar0 (/32): 0x00000000
> 
If you do not want an open terminal and its display, start the openocd server in background and send the output to dev/null

./src/openocd -s ./tcl -f ./esp32.cfg -l /dev/null&

Next Fight
Interfacing OpenOcd with Eclipse

Enjoy.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: OpenOcd in OSX

Postby ESP_igrr » Sat Apr 22, 2017 11:51 am

Wow, great tip regarding
sudo kextutil -b com.apple.driver.AppleUSBFTDI -p AppleUSBEFTDI-6010-1
We should add this to the guide.

Who is online

Users browsing this forum: niels.1234 and 156 guests