How to use "Sipeed RV Debugger" for ESP32 debugging? (on linux)

Hi,

I bought a JTAG debugger with the intention to debug the ESP32.
I settled on the “Sipeed RV Debugger” of which i later found out that it is even documented as a debugger on platformio!

I’ve added that debugger to my platformio.ini configuration as per the documentation. It now looks like:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
  https://github.com/tzapu/WiFiManager.git#development
build_flags =
  -DWM_MDNS=1
  -ggdb
monitor_flags=
    --eol
    LF
debug_tool = sipeed-rv-debugger
debug_init_break = tbreak setup

But upon trying it out i’m hitting one error i can’t find much info on.
I’m getting this error:

Error: Unknown debug tool `sipeed-rv-debugger`. Please use one of `esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa` or `custom`

Hopefully someone here has some experience with this combination?
I’m a bit lost as to where to even debug this.

Cheers,
Mark

The debug tools are not globally usable stand-alone for everything, the platform (in this platform-espressif32) and the board esp32dev has to explicitly support the debugger. The sipeed-rv-debugger is not a listed debugger in the ESP32 platform or the ESP32 dev board.

According to FTDI, the chip used in this debugger, FT2232D, is a “lesser” USB-fullspeed version of the usually used FT2232H chip (usb-highspeed).

The esp-prog debugger has the H version of the chip and should be close enough. Have you tried debug_tool = esp-prog?

Also, if all else fails, PlatformIO can handle arbitrary adapters / programs that can use this adapter to create a GDB server, by directly specifying the debug_server invocation.

Okay this probably won’t work with openOCD and that config file. But I did localize the needed OpenOCD config file for the adapter, sipeed-rv-debugger.cfg, in the tool-openocd-gd32v package.

interface ftdi
ftdi_device_desc "Dual RS232"
ftdi_vid_pid 0x0403 0x6010

#autoexit true

#interface cmsis-dap
transport select jtag
ftdi_layout_init 0x0008 0x001b
ftdi_layout_signal nSRST -oe 0x0020 -data 0x0020

Can you copy this content to ~/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/interface/ftdi/sipeed-rv-debugger.cfg, then cd ~/.platformio/packages/tool-openocd-esp32/ and do

./bin/openocd -s share/openocd/scripts -f interface/ftdi/sipeed-rv-debugger.cfg -c "set ESP32_FLASH_VOLTAGE 3.3" -f target/esp32.cfg

(selects a general ESP32 config with a flash voltage of 3.3V)

What does OpenOCD output on the commandline? Can it connect to the target chip?

JTAG pinout between adapter to the IO pins of the ESP32 can also be looked up at Low-cost ESP32 In-circuit Debugging | by Manuel Bl. | Medium.

Hi,

I’m very sorry for this very belated reply! I did saw it right after you made the post but kinda had to go to bed and forgot to respond each weekend after it :frowning: till now

Again, sorry for that!

So i followed your suggestion and initially got this output:

❯ ./bin/openocd -s share/openocd/scripts -f interface/ftdi/sipeed-rv-debugger.cfg -c "set ESP32_FLASH_VOLTAGE 3.3" -f target/esp32.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202 (2020-12-02-17:38)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
3.3
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
Error: An adapter speed is not selected in the init script. Insert a call to adapter_khz or jtag_rclk to proceed.

openocd: ../src/jtag/core.c:343: jtag_checks: Assertion `jtag_trst == 0' failed.
[1]    198256 abort (core dumped)  ./bin/openocd -s share/openocd/scripts -f  -c "set ESP32_FLASH_VOLTAGE 3.3" -

After googling a bit it looked like i had to set adapter_khz and i did that to the clock speed of this chip.
So my sipeed-rv-debugger.cfg now looks like:

interface ftdi
ftdi_device_desc "Dual RS232"
ftdi_vid_pid 0x0403 0x6010

adapter_khz 6000

#autoexit true

#interface cmsis-dap
transport select jtag
ftdi_layout_init 0x0008 0x001b
ftdi_layout_signal nSRST -oe 0x0020 -data 0x0020

It does seem fix it as the output now is:

❯ ./bin/openocd -s share/openocd/scripts -f interface/ftdi/sipeed-rv-debugger.cfg -c "set ESP32_FLASH_VOLTAGE 3.3" -f target/esp32.cfg
Open On-Chip Debugger  v0.10.0-esp32-20201202 (2020-12-02-17:38)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
3.3
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 : clock speed 6000 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: Detected debug stubs @ 3ffc1fe8
Info : esp32.cpu1: Debug controller was reset.
Info : esp32.cpu1: Core was reset.
Info : esp32.cpu1: Detected debug stubs @ 3ffc1fe8
Info : Listening on port 3333 for gdb connections

Which leads me to think that everything is now setup properly.

However, getting it running in platformio still seems to be a bit of a challenge.
I think - very uncertain… - that i need to set a debug server with this in platformio.ini:

debug_tool = custom
debug_port = localhost:3333
debug_init_break = tbreak setup

Mind you, this does work and after a few minutes it does end up in the setup function!
So yes, we’re getting there! :smiley:

But each debug step is taking so freaking long! As in about 5 seconds for each step i do! Is that how it’s supposed to work?

Also, using the sipeed-rv-debugger still gives the very same error as the initial post i made. Isn’t that supposed to be working now with that adapter config that i added?

Thank you so much for your help thus far!

Good that this is initially working. Now idea about the low speed of debugging, you did set a 6MHz adapter speed which is quite good.

Can you PR / propose the current state of your OpenOCD config file to GitHub - espressif/openocd-esp32: OpenOCD branch with ESP32 JTAG support? They should handle adding that file and then adding proper support. Also say which exact pinmap that is using from the adapter to the ESP32 there.

Yes, i will add a PR there!

Adding this to platformio.ini does seem to make it substantially faster:

debug_speed = 6000

I will add a link to the PR here once i made it.

Ah yes, my bad – in the newer Espressif32 platform version, the openocd invocation does an explicit -c "set adapter_khz ... which defaults to 5000. So not too far away from 6000 but if you say it makes a difference it is so then.

Done: Add support for "Sipeed RV Debugger" (OCD-304) by markg85 · Pull Request #142 · espressif/openocd-esp32 · GitHub

1 Like

There could be more at play here.
The debugger restarts literally tens of times before it finally proceeds in the setup breakpoint. After it does that, it seems stable.

Now i’ve had breakpoints where it took just about a second to step. It’s slow but definitely workable. And i’ve had breakpoints where it definitely leans towards 5 seconds or even more. Both was with the 6000 khz.

Anyhow, just the fact that this works now is awesome on it’s own :smiley:

Side question. Which affordable JTAG debugging board would you recommend that is using the speedier FT2232H chip? I just bought this one as i needed something and it looked compact and feature rich enough for my needs. But in hindsight i might have been better off picking one with an FT2232H chip on it. And on top of this, it still needs to work with the ESP32 :slight_smile: I find it the listings on platformio a bit difficult to figure out which ones are supported for the ESP and which are not. Though it seems my best bet would be the ESP-Prog board?