Improving debug speed on an Altera USB Blaster clone

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Improving debug speed on an Altera USB Blaster clone

Postby Xavi92 » Thu Mar 28, 2019 5:22 pm

I got a cheap ~3$ Altera USB Blaster (https://bit.ly/2UfJLTx) debugging on a ESP WROOM-32 development kit by using openocd and xtensa-esp32-elf-gdb, similarly as described on Espressif's official guide "JTAG debugging". These are the steps I made:

1. Download openocd branch for esp32 from Espressif's Github repo: https://github.com/espressif/openocd-esp32

2. Configure openocd-esp32 as:

Code: Select all

$ ./configure --prefix=/usr/local/openocd-esp32/ --enable-usb-blaster
It is very important "--enable-usb-blaster" is indicated. Otherwise, when config.h is generated, the following line is missing:

Code: Select all

#define BUILD_USB_BLASTER 1
Causing usb_blaster.c not to include a drvs_map instance on lowlevel_drivers_map[]. This means openocd-esp32 is then unable to find a low-level driver when usb_blaster interface is to be used.

Code: Select all

static struct drvs_map lowlevel_drivers_map[] = {
#if BUILD_USB_BLASTER
	{ .name = "ftdi", .drv_register = ublast_register_ftdi },
#endif
#if BUILD_USB_BLASTER_2
	{ .name = "ublast2", .drv_register = ublast2_register_libusb },
#endif
	{ NULL, NULL },
};
3. openocd-esp32 would not compile out of the box for me because of some (reasonable) compiler errors, using gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0. The buffers below do not allocate enough bytes and some variables would not fit into it when calling snprintf().

Therefore, I applied the following quick patches so the compiler errors disappear:

Code: Select all

diff --git a/src/flash/nor/xmc4xxx.c b/src/flash/nor/xmc4xxx.c
index 78ed2258..d47fea3d 100644
--- a/src/flash/nor/xmc4xxx.c
+++ b/src/flash/nor/xmc4xxx.c
@@ -931,7 +931,7 @@ static int xmc4xxx_get_info_command(struct flash_bank *bank, char *buf, int buf_
 
        /* If OTP Write protection is enabled (User 2), list each
         * sector that has it enabled */
-       char otp_str[14];
+       char otp_str[28];
        if (otp_enabled) {
                strcat(prot_str, "\nOTP Protection is enabled for sectors:\n");
                for (int i = 0; i < bank->num_sectors; i++) {

Code: Select all

diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c
index 828610bb..634004c0 100644
--- a/src/target/arm_adi_v5.c
+++ b/src/target/arm_adi_v5.c
@@ -1123,7 +1123,7 @@ static int dap_rom_display(struct command_context *cmd_ctx,
        int retval;
        uint64_t pid;
        uint32_t cid;
-       char tabs[16] = "";
+       char tabs[32] = "";
 
        if (depth > 16) {
                command_print(cmd_ctx, "\tTables too deep");
4. It seems USB Blaster does not allow speed configuration, so they must be removed from ESP-WROOM-32 configuration file.

Code: Select all

--- a/tcl/board/esp-wroom-32.cfg
+++ b/tcl/board/esp-wroom-32.cfg
@@ -34,7 +34,7 @@ transport select jtag
 #
 # On DevKit-J, this can go as high as 20MHz if CPU frequency is 80MHz, or 26MHz
 # if CPU frequency is 160MHz or 240MHz.
-adapter_khz 20000
+#adapter_khz 20000
5. After these changes, openocd-esp32 can be happily compiled and installed into the designated prefix.

Debugging:

I used to following pinout:

Image

Code: Select all

$ /usr/local/openocd-esp32/bin/openocd -s share/openocd/scripts -f interface/altera-usb-blaster.cfg -f board/esp-wroom-32.cfg -c "init; reset halt"
Wait until openocd waits for connections from GDB on port 3333.

Code: Select all

$ esp32-openocd -s share/openocd/scripts -f interface/altera-usb-blaster.cfg -f board/esp-wroom-32.cfg -c "init; reset halt"
Open On-Chip Debugger  v0.10.0-esp32-20190313-dirty (2019-03-27-15:43)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Warn : Adapter driver 'usb_blaster' did not declare which transports it allows; assuming legacy JTAG-only
Info : only one transport option; autoselect 'jtag'
Warn : Transport "jtag" was already selected
Info : Configured 2 cores
esp32 interrupt mask on
Info : usb blaster interface using libftdi
Error: unable to get latency timer
Info : This adapter doesn't support configurable speed
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 : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
Info : Listening on port 3333 for gdb connections

Code: Select all

$ xtensa-esp32-elf-gdb build/Handheld.elf --tui
Inside GDB:

Code: Select all

(gdb) set remotetimeout 10000
This avoids packet timeouts between openocd and gdb. It seems like openocd communicates against the ESP32 at a really slow pace, so the default timeout (2000 ms) is not enough.

Code: Select all

(gdb) target localhost:3333
Once gdb has successfully connected to the board (this step can take up to several minutes), the following message will appear:

Code: Select all

Remote debugging using localhost:3333
0x40000400 in ?? ()
Finally, place a breakpoint wherever you need and let the code execute. For example:

Code: Select all

(gdb) break app_main
(gdb) continue
Now my question is...
Debugging works fine: I can step, set breakpoints, watch variables... However, speed really sucks. For example, a single "step" operation takes around 30 seconds. Tracebacking via "tb" works relatively fast (around 2 seconds). Flashing a ~170 KiB image takes up to 2 minutes.

How can we improve speed so debugging experience is a bit less painful?

Thanks for reading,
Xavi

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Improving debug speed on an Altera USB Blaster clone

Postby ESP_Angus » Fri Mar 29, 2019 12:38 am

Hi Xavi,

Thanks for posting these detailed steps. Regarding the compile issues in openocd, I think the Espressif openocd team are working on updating openocd-esp32 to a new upstream openocd version soon so these patches should not be necessary.

Xavi92 wrote:
Thu Mar 28, 2019 5:22 pm
How can we improve speed so debugging experience is a bit less painful?
Unfortunately, the answer is probably "don't use a $3 USB blaster clone":
From https://github.com/espressif/openocd-es ... CheapClone :
Throughtput in bytes/s: 11kBytes/s
...
Contrary to the original USB Blaster, the cheap clone will never reach high
transfer speeds over JTAG.
The USB Blaster target in openocd does support a jtag_khz command to set the adapter clock speed, but it sounds like in this particular case it won't help.[*]

If your budget will stretch to a FT2232H breakout (or a FT2232H-based debug adapter), you should be able to clock it at 10MHz or higher (depending on the JTAG cabling, etc).

[*] You could figure that 11kB/sec should still give a better flashing rate than the ~1kB/sec you have now. The answer to this is that the Xtensa debug protocol and interacting with the flash registers adds some overhead. And also that there are probably some other overheads between each JTAG transaction in the cheap adapter's firmware.

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: Improving debug speed on an Altera USB Blaster clone

Postby Xavi92 » Mon Apr 01, 2019 1:59 pm

Hi Angus,

Thanks for your quick response. It is a shame the adapter itself is to blame, but I guess $3 was in fact too cheap. However, back when I bought it I was (and still am) unsure of which FT2232H-based adapter would do the trick. Would you recommend this one? Are there any cheaper alternatives?

Thank you,
Xavi

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Improving debug speed on an Altera USB Blaster clone

Postby ESP_Sprite » Wed Apr 03, 2019 4:04 am

That one should work fine. Not sure if there are cheaper versions worth buying: the FT2232H is a somewhat expensive chip by itself, and that drives the cost of most boards.

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: Improving debug speed on an Altera USB Blaster clone

Postby Xavi92 » Mon Apr 08, 2019 1:32 pm

Thanks for your help, I'll then get one of those. Would it be possible to include the info I wrote above somewhere in the docs so other people know about the limitations of using a cheap USB Blaster clone?

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: Improving debug speed on an Altera USB Blaster clone

Postby Xavi92 » Sat Apr 13, 2019 10:26 am

I have tested the same configuration on another computer as in my first post with much better results: flashing a 102400 bytes image took 21.19s (4.719 KiB/s), which is between 4 and 5 times faster than my previous results. Debugging is also much more enjoyable, as step instructions take around 2-5 seconds each. I have tested both USB 3.0 and 2.0 ports, where flashing the same image took 25.43s (3.931 KiB/s) on a USB 2.0 port.

User avatar
arunbm123
Posts: 97
Joined: Fri Feb 23, 2018 5:36 am

Re: Improving debug speed on an Altera USB Blaster clone

Postby arunbm123 » Sat Apr 13, 2019 10:51 am

hi


For me this debugger https://www.aliexpress.com/item/New-FT2 ... st=ae803_3

is not Working
Kindly help with wiring

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: Improving debug speed on an Altera USB Blaster clone

Postby Xavi92 » Mon Nov 25, 2019 9:54 pm

I am sorry for reviving such an old topic, but I wanted to bring some news on this area. Finally I got one of these units and debugging is now as responsive as one could expect. I used the esp32_devkitj_v1.cfg script included on the openocd fork by Espressif, but had to make a couple of slight modifications to make it work.
This is the configuration file needed by openocd:

Code: Select all

#
# Driver for the FT2232C JTAG chip
#
 

interface ftdi
ftdi_vid_pid 0x0403 0x6010
# adapter_khz was mandatory. 20 MHz worked for me,
# but feel free to test any other value
adapter_khz 20000
# interface 1 is the uart
# esp32_devkitj_v1.cfg used "0", but "1" had to use for this unit
ftdi_channel 1
# just TCK TDI TDO TMS, no reset
ftdi_layout_init 0x0008 0x000b
reset_config none
I hope this is useful for anyone that needs debugging for the ESP32 for 17US$. Actually, this unit was bundled with a nice box, 1 USB cable and Dupont cables, so there must be cheaper boards somewhere. OTOH, the USB Blaster is an even cheaper working alternative (around 3US$, as I posted above), but you will need to face the consequences (very slow).

Who is online

Users browsing this forum: No registered users and 118 guests