Improving debug speed on an Altera USB Blaster clone
Posted: 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:
It is very important "--enable-usb-blaster" is indicated. Otherwise, when config.h is generated, the following line is missing:
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.
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:
4. It seems USB Blaster does not allow speed configuration, so they must be removed from ESP-WROOM-32 configuration file.
5. After these changes, openocd-esp32 can be happily compiled and installed into the designated prefix.
Debugging:
I used to following pinout:
Wait until openocd waits for connections from GDB on port 3333.
Inside GDB:
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.
Once gdb has successfully connected to the board (this step can take up to several minutes), the following message will appear:
Finally, place a breakpoint wherever you need and let the code execute. For example:
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
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
Code: Select all
#define BUILD_USB_BLASTER 1
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 },
};
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");
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
Debugging:
I used to following pinout:
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"
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
Code: Select all
(gdb) set remotetimeout 10000
Code: Select all
(gdb) target localhost:3333
Code: Select all
Remote debugging using localhost:3333
0x40000400 in ?? ()
Code: Select all
(gdb) break app_main
(gdb) continue
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