Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable remote_bitbang support by default #134

Closed
wants to merge 2 commits into from
Closed

Enable remote_bitbang support by default #134

wants to merge 2 commits into from

Conversation

brainstorm
Copy link

@brainstorm brainstorm commented Jan 2, 2021

Fixes #133

https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/hw-reference/esp32s2/user-guide-saola-1-v1.2.html

First commit fails because this board does not seem to have JTAG_USB support since it's fronted by an FTDI IC instead (UART), resulting in:

$ ../src/openocd -f board/esp32s2-saola-1.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202 (2021-01-02-21:22)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : USB protocol set for esp remote
Info : VID set to 0x303a and PID to 0x1002
Warn : Transport "jtag" was already selected
Info : FreeRTOS creation
Info : FreeRTOS creation
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

Assertion failed: (jtag_trst == 0), function jtag_checks, file src/jtag/core.c, line 343.
Abort trap: 6

Instead the following file in openocd/tcl/interface...:

$ cat tcl/interface/jtag_esp_remote.cfg
interface jtag_esp_remote

jtag_esp_remote_protocol usb
jtag_esp_remote_vid_pid 0x303a 0x1002

#jtag_esp_remote_protocol tcp
#jtag_esp_remote_set_port 5555
#jtag_esp_remote_set_address "127.0.0.1"

... Needs to be edited accordingly:

interface jtag_esp_remote

#jtag_esp_remote_protocol usb
#jtag_esp_remote_vid_pid 0x303a 0x1002

jtag_esp_remote_protocol tcp
jtag_esp_remote_set_port 5555
jtag_esp_remote_set_address "127.0.0.1"

Perhaps this should be documented accordingly somewhere in espressif documentation?

If connecting with a remote JTAG bitbanging Glasgow board like so:

image

And running the following Glasgow applet command:

$ glasgow run jtag-openocd --port A --pin-tck 0 --pin-tms 3 --pin-tdi 2 --pin-tdo 1 -V 3.3 tcp:localhost:5555
I: g.cli: running handler for applet 'jtag-openocd'
I: g.applet.interface.jtag_openocd: port(s) A voltage set to 3.3 V
I: g.applet.interface.jtag_openocd: socket: listening at tcp:localhost:5555

Plus the corresponding OpenOCD command on another terminal:

$ ../src/openocd -f board/esp32s2-saola-1.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202 (2021-01-02-21:22)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : TCP protocol set for esp remote
Info : Set server port to 5555
Info : Set server address to 127.0.0.1
Warn : Transport "jtag" was already selected
Info : FreeRTOS creation
Info : FreeRTOS creation
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Connection to 127.0.0.1 : 5555 succeed
Info : This adapter doesn't support configurable speed

Which should be fixed in VSCode ESP-IDF extension (see issue espressif/vscode-esp-idf-extension#259), ideally ;)

@brainstorm
Copy link
Author

Predictably though, the jtag_esp_remote protocol is not compatible with the OpenOCD "native" remote_bitbang protocol and so any attempt at GDB fails miserably:

(gdb) target remote :5555
Remote debugging using :5555
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Ignoring packet error, continuing...
Remote replied unexpectedly to 'vMustReplyEmpty': timeout
(gdb) 

Garbling the OpenOCD side with bad commands (I guess?):

$ ../src/openocd -f board/esp32s2-saola-1.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202 (2021-01-02-21:22)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : TCP protocol set for esp remote
Info : Set server port to 5555
Info : Set server address to 127.0.0.1
Warn : Transport "jtag" was already selected
Info : FreeRTOS creation
Info : FreeRTOS creation
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Connection to 127.0.0.1 : 5555 succeed
Info : This adapter doesn't support configurable speed
Info : TAP esp32.cpu0 has invalid IDCODE (0xcccccccc)
Info : TAP esp32.cpu1 has invalid IDCODE (0x66666666)
Info : JTAG tap: auto0.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto1.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto2.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto3.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto4.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto5.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto6.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto7.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto8.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto9.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto10.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto11.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto12.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto13.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto14.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto15.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto16.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto17.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Info : JTAG tap: auto18.tap tap/device found: 0x33333333 (mfg: 0x199 (Centon Electronics), part: 0x3333, ver: 0x3)
Warn : Unexpected idcode after end of chain: 610 0x33333333
Error: double-check your JTAG setup (interface, speed, ...)
Error: Trying to use configured scan chain anyway...
Error: esp32.cpu0: IR capture error; saw 0x0c not 0x01
Warn : Bypassing JTAG setup events due to errors
Info : Listening on port 3333 for gdb connections
shutdown command invoked
Error: Failed to clear OCDDCR_ENABLEOCD!
Error: Failed to clear OCDDCR_ENABLEOCD!

@brainstorm
Copy link
Author

Fortunately in this PR, the "classic" OpenOCD remote_bitbang is re-enabled and things seem to work between Glasgow and ESP32S3 Saola-1 dev board:

$ ../src/openocd -f board/esp32s2-saola-1.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202-2-g7e342cad (2021-01-02-23:47)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Warn : Transport "jtag" was already selected
Info : FreeRTOS creation
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Initializing remote_bitbang driver
Info : Connecting to localhost:5555
Info : remote_bitbang driver initialized
Info : This adapter doesn't support configurable speed
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Core was reset.
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Warn : No symbols for FreeRTOS!

@igrr
Copy link
Member

igrr commented Jan 4, 2021

Hi @brainstorm, thanks for the PR.
We can definitely enable remote_bitbang in the next release.

Regarding tcl/board/esp32s2-saola-1.cfg — i'm not sure about adding this file. Normally we add board-specific TCL files only when the board has a built-in JTAG interface. In other cases, if the board doesn't contain the JTAG interface, you can run OpenOCD specifying a pair of config files: one for the target, and one for the interface. This way every user can choose which interface to use. You can probably agree that "remote_bitbang" as the default for Saola is no better than any other interface that can be connected externally (JLink, FT2232H, etc).

We can add a trivial config file for remote_bitbang interface, so that you can run OpenOCD like this:

openocd -f target/esp32s2.cfg -f interface/remote_bitbang.cfg

Would this work for you?

@brainstorm
Copy link
Author

You are totally right, Igor, I see your point.

Your suggestion would work for me as well, so I'll get rid of the Saola config and put in place what you propose.

I'll fix it tonight, thanks for the speedy review!

@brainstorm
Copy link
Author

@igrr Actually instead of your command:

openocd -f target/esp32s2.cfg -f interface/remote_bitbang.cfg

It would be with the argument flipped like this:

$ openocd -f interface/remote_bitbang.cfg -f target/esp32s2.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202-2-g7e342cad (2021-01-02-23:47)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Warn : Transport "jtag" was already selected
Info : FreeRTOS creation
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Initializing remote_bitbang driver
Info : Connecting to localhost:5555
Info : remote_bitbang driver initialized
Info : This adapter doesn't support configurable speed
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Core was reset.
Info : Listening on port 3333 for gdb connections

Otherwise I get the following error:

$ openocd -f target/esp32s2.cfg -f interface/remote_bitbang.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202-2-g7e342cad (2021-01-02-23:47)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Error: Debug adapter doesn't support any transports?
target/esp32s2.cfg:2: Error:
in procedure 'script'
at file "embedded:startup.tcl", line 26
at file "target/esp32s2.cfg", line 2

So ready to merge as-is now... would you document this somewhere in official docs? I don't want other people to go through this again :P

Thanks!

@brainstorm brainstorm changed the title Saola-1 board support Enable remote_bitbang support by default Jan 5, 2021
@igrr
Copy link
Member

igrr commented Jan 6, 2021

Thanks @brainstorm. Regarding documenting this, I've added a task in the internal issue tracker. Once a new OpenOCD release is made and IDF is updated to use it, we'll mention this in the docs.

May I ask you to combine the 6 commits in your branch into one commit, e.g. "interface: enable remote_bitbang by default and add cfg file"? If you are unsure how, you can also leave it as is and I will do it for you, keeping your authorship.

@brainstorm
Copy link
Author

brainstorm commented Jan 6, 2021

Sure @igrr rebased, reworded, squashed and pushed right now. Eager to see the new release so I don't have to fiddle with it across updates anymore:

Adding ESP-IDF tools to PATH...
ERROR: tool openocd-esp32 has no installed versions. Please run '/Users/romanvg/dev/esp-idf/install.sh' to install it.

There seems to be a bunch of version-checking logic in idf_tools.py which do not like ad-hoc clones like I did ;)

Thanks!

@brainstorm
Copy link
Author

brainstorm commented Jan 10, 2021

@igrr happy to write that up in the docs too if that helps speeding up the merge? Just point me a repo or .md file and I'll try to do the rest once it works consistently for me ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable remote_bitbang by default on next release? (OCD-696)
2 participants