PlatformIO -> J-Link -> ESP32-DevKitC debugging not working

I’m able to write code in PlatformIO and deploy it successfully to an ESP32-DevKitC. No problem.

Now I’m trying to debug the code through a Segger J-Link. The connection to the probe seems to be wired up correctly because I see status updates in openocd that make it clear that it sees the two Tensilica CPU cores.

It’s unclear to me how to configure this properly on the PlatformIO side. First I tried this:

debug_tool = jlink

I saw that on this page:

https://docs.platformio.org/en/latest/plus/debug-tools/jlink.html

but it fails immediately when I try to debug:

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

I then tried a custom configuration, based on this post:

it looks like this:

debug_tool = custom
debug_server =
  /Users/liyanage/Documents/esp/openocd-esp32/bin/openocd
  -s
  /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/
  -f
  /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/interface/jlink.cfg
  -f
  /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/board/esp-wroom-32.cfg

This was based on an “openocd” command line that I cobbled together that seemed to work.

Now when I try to debug, it rebuilds the project, seems to deploy it, and then eventually starts a debug session. That doesn’t stop at the breakpoint I set early in the startup function app_main(), instead it seems to fail like this:

** Verified OK **
** Verified OK **
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)
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)

cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak app_main`
Note: automatically using hardware breakpoints for read-only addresses.
Info : Target halted. PRO_CPU: PC=0x400D075C (active)    APP_CPU: PC=0x400E09DE 
Target halted. PRO_CPU: PC=0x400D075C (active)    APP_CPU: PC=0x400E09DE 
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
Info : Detected debug stubs @ 3ffc2d44 on core0 of target 'esp32'
[New Thread 1073510396]
[New Thread 1073508496]
[New Thread 1073513052]
[New Thread 1073500704]
[New Thread 1073497436]
[New Thread 1073499232]
[New Thread 1073501836]
[Switching to Thread 1073506380]
Temporary breakpoint 
1, app_main () at src/hello_world_main.c:17
17	{
/Volumes/build/idf/crosstool-NG/.build/src/gdb-7.10/gdb/inline-frame.c:171: internal-error: void inline_frame_this_id(struct frame_info *, void **, struct frame_id *): Assertion `!frame_id_eq (*this_id, outer_frame_id)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? 
(y or n) [answered Y; input not from terminal]
This is a bug, please report it.
For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.
/Volumes/build/idf/crosstool-NG/.build/src/gdb-7.10/gdb/inline-frame.c:171: internal-error: void inline_frame_this_id(struct frame_info *, void **, struct frame_id *): Assertion `!frame_id_eq (*this_id, outer_frame_id)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? 
(y or n) [answered Y; input not from terminal]

Here’s my current config file:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = espidf
; debug_tool = jlink
debug_tool = custom
debug_server =
    /Users/liyanage/Documents/esp/openocd-esp32/bin/openocd
    -s
    /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/
    -f
    /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/interface/jlink.cfg
    -f
    /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/board/esp-wroom-32.cfg

debug_init_break = tbreak app_main

; Serial Monitor options
monitor_speed = 115200

J-Link does not support Espressif chips. See compatible debugging tools for Espressif ESP32 Dev Module here Espressif ESP32 Dev Module — PlatformIO latest documentation

Thanks, I saw that list already. Could you elaborate a bit more for me:

1.) Are you saying the "Unknown debug tool jlink" message is based on the configured platform? If so, that’s really confusing and it would be super helpful if the error message instead clearly said that “jlink” isn’t supported for the particular platform. That’s a big difference from “jlink is a completely unknown debug tool”, which the message currently suggests. That is the message I’d expect if I make a typo.

2.) I know J-link doesn’t directly support ESP32, but there are lots of people who use it successfully with OpenOCD. Can you tell me if my second (“custom”) configuration is supposed to work? It works fine when I run it on the command line, outside of PlatformIO. Also, if you read the error messages more clearly, it looks like there’s a gdb internal issue. But that’s possibly a problem for Espressif to solve because I think it’s their custom xtensa-esp32-elf-gdb.

Below is an example session that shows it working perfectly fine in the terminal instead of with PlatformIO. Given that, is it expected to work in PlatformIO or not?

(gdb) b app_main.c:18
Breakpoint 4 at 0x400d1fea: file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/esp-bootstrap/1hello_world/main/app_main.c, line 18.
(gdb) c
Continuing.
Target halted. PRO_CPU: PC=0x400D1FEA (active)    APP_CPU: PC=0x400E0D92 
[Switching to Thread 1073434996]

Breakpoint 4, app_main ()
    at /Users/liyanage/Dropbox/Documents/esp/esp-workshop/esp-bootstrap/1hello_world/main/app_main.c:18
18	        printf("[%d] Hello world!\n", i);
(gdb) bt
#0  app_main () at /Users/liyanage/Dropbox/Documents/esp/esp-workshop/esp-bootstrap/1hello_world/main/app_main.c:18
#1  0x400d083d in main_task (args=0x0)
    at /Users/liyanage/Dropbox/Documents/esp/esp-workshop/esp-bootstrap/esp-idf/components/esp32/cpu_start.c:470
(gdb) p i
$1 = 6
(gdb) c
Continuing.

Sorry, I didn’t know that it works with J-Link via openOCD. What is your CLI command to run openOCD?

Oh yeah I meant to include that:

First I start OpenOCD like this, using Espressif’s customized OpenOCD:

/Users/liyanage/Documents/esp/openocd-esp32/bin/openocd \
-s /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/ \
-f /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/interface/jlink.cfg \
-f /Users/liyanage/Documents/esp/openocd-esp32/share/openocd/scripts/board/esp-wroom-32.cfg

Then I launch GDB with:

xtensa-esp32-elf-gdb -x gdbinit build/1hello-world.elf

gdbinit:

target remote :3333
mon reset halt
flushregs
thb app_main

Added in Add support for debugging via J-Link · platformio/platform-espressif32@c841fa3 · GitHub

Could you test it with the latest upstream version Espressif 32 — PlatformIO latest documentation?

Please remove any records from your platformio.ini and use just 1 line debug_tool = jlink. See J-LINK — PlatformIO latest documentation

Very cool, I’ll try this out soon and report back here.

I tried it with the following contents of platformio.ini, is this what you meant?

[env:esp32dev]
platform = https://github.com/platformio/platform-espressif32.git
board = esp32dev
framework = espidf
monitor_speed = 115200
debug_tool = jlink

Now it doesn’t reject the “jlink” value. It first compiles everything and then seems to attempt to start a debug session. This looks better than before.

However, the resulting debug session startup looks exactly like what I pasted above, where I used my “custom” debug_tool configuration. See log output below. It seems that it fails at the same point, and a bit after that, I get a crash notification/report for the process xtensa-esp32-elf-gdb from the macOS crash reporter. I assume that has nothing to do with you and is Espressif’s problem.

Preparing firmware for debugging...
Processing esp32dev (platform: https://github.com/platformio/platform-espressif32.git; board: esp32dev; framework: espidf)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 32 > Espressif ESP32 Dev Module
SYSTEM: ESP32 240MHz 320KB RAM (4MB Flash)
DEBUG: CURRENT(jlink) EXTERNAL(esp-prog, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 0 compatible libraries
Scanning dependencies...
No dependencies
Retrieving maximum program size .pioenvs/esp32dev/firmware.elf
Checking size .pioenvs/esp32dev/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   3.9% (used 12928 bytes from 327680 bytes)
PROGRAM: [=         ]  12.6% (used 131647 bytes from 1048576 bytes)
========================= [SUCCESS] Took 15.68 seconds =========================
Reading symbols from /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/firmware.elf...
done.
PlatformIO Unified Debugger > http://bit.ly/pio-debug
PlatformIO: Initializing remote target...
Open On-Chip Debugger 0.10.0-dev (2018-06-04-09:51)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
adapter speed: 20000 kHz
esp32 interrupt mask on
force hard breakpoints
Info : tcl server disabled
Info : telnet server disabled
Info : No device selected, using first device.
Info : J-Link V9 compiled Apr 15 2014 19:08:28
Info : Hardware version: 9.00
Info : VTarget = 3.327 V
Info : Reduced speed from 20000 kHz to 15000 kHz (maximum).
Info : Reduced speed from 20000 kHz to 15000 kHz (maximum).
Info : clock speed 20000 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 : Target halted. PRO_CPU: PC=0x400D0728 (active)    APP_CPU: PC=0x400E083E 
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : accepting 'gdb' connection from pipe
Info : Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400E083E 
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
app_main () at src/app_main.c:15
15	{
Hardware assisted breakpoint 1 at 0x400d0728: file src/app_main.c, line 15.
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)
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
esp32: target state: halted
esp32: target state: halted
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
esp32: target state: halted
esp32: target state: halted
** Programming Started **
** Programming Started **
auto erase enabled
auto erase enabled
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E0 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E0 
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
wrote 20480 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/bootloader.bin in 2.774038s (7.210 KiB/s)
wrote 20480 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/bootloader.bin in 2.774038s (7.210 KiB/s)
** Programming Finished **
** Programming Finished **
** Verify Started **
** Verify Started **
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076DD 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076DD 
read 19424 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/bootloader.bin and flash bank 0 at offset 0x00001000 in 1.080790s (17.551 KiB/s)
contents match
read 19424 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/bootloader.bin and flash bank 0 at offset 0x00001000 in 1.080790s (17.551 KiB/s)
contents match
** Verified OK **
** Verified OK **
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)
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
esp32: target state: halted
esp32: target state: halted
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
esp32: target state: halted
esp32: target state: halted
** Programming Started **
** Programming Started **
auto erase enabled
auto erase enabled
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076DD 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076DD 
wrote 4096 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/partitions.bin in 2.337003s (1.712 KiB/s)
wrote 4096 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/partitions.bin in 2.337003s (1.712 KiB/s)
** Programming Finished **
** Programming Finished **
** Verify Started **
** Verify Started **
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
read 3072 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/partitions.bin and flash bank 0 at offset 0x00008000 in 0.865138s (3.468 KiB/s)
contents match
read 3072 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/partitions.bin and flash bank 0 at offset 0x00008000 in 0.865138s (3.468 KiB/s)
contents match
** Verified OK **
** Verified OK **
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)
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
esp32: target state: halted
esp32: target state: halted
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
esp32: target state: halted
esp32: target state: halted
** Programming Started **
** Programming Started **
auto erase enabled
auto erase enabled
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076DD 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076DD 
wrote 135168 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/firmware.bin in 4.759008s (27.737 KiB/s)
wrote 135168 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/firmware.bin in 4.759008s (27.737 KiB/s)
** Programming Finished **
** Programming Finished **
** Verify Started **
** Verify Started **
Info : Use core0 of target 'esp32'
Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2 
read 133312 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/firmware.bin and flash bank 0 at offset 0x00010000 in 2.408957s (54.043 KiB/s)
contents match
read 133312 bytes from file /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/firmware.bin and flash bank 0 at offset 0x00010000 in 2.408957s (54.043 KiB/s)
contents match
** Verified OK **
** Verified OK **
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)
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
esp32: target state: halted
esp32: target state: halted
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
esp32: target state: halted
esp32: target state: halted
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = thb app_main`
Info : Target halted. PRO_CPU: PC=0x400D0728 (active)    APP_CPU: PC=0x400E083E 
Target halted. PRO_CPU: PC=0x400D0728 (active)    APP_CPU: PC=0x400E083E 
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
[New Thread 1073510396]
[New Thread 1073508496]
[New Thread 1073513052]
[New Thread 1073500704]
[New Thread 1073497436]
[New Thread 1073499232]
[New Thread 1073501836]
[Switching to Thread 1073506380]

Temporary breakpoint 
1, app_main () at src/app_main.c:15
15	{
/Volumes/build/idf/crosstool-NG/.build/src/gdb-7.10/gdb/inline-frame.c:171: internal-error: void inline_frame_this_id(struct frame_info *, void **, struct frame_id *): Assertion `!frame_id_eq (*this_id, outer_frame_id)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? 
(y or n) [answered Y; input not from terminal]

This is a bug, please report it.
  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.


/Volumes/build/idf/crosstool-NG/.build/src/gdb-7.10/gdb/inline-frame.c:171: internal-error: void inline_frame_this_id(struct frame_info *, void **, struct frame_id *): Assertion `!frame_id_eq (*this_id, outer_frame_id)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? 
(y or n) [answered Y; input not from terminal]

This is known issue and we reported it to ESP team

Could you try to debug ESP32 project using Arduino? It seems that issue could be on our side. We wait for the help from ESP team.

Yes you are spot on. It works fine when I use the Arduino framework instead of IDF. Thanks for the pointer to the issue you opened with Espressif.

Somebody at Espressif told me that this issue should be fixed by this commit of the ESP-IDF SDK:

It’s currently in master only:

esp-idf(master) $ git branch -a --contains 3ba63a520c91b961a2632ad7385c8bac9039e197
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

I have that checked out locally and I can use it for command-line development outside of PlatformIO.

I assume that PlatformIO uses its own separate copy of ESP-IDF, and I assume it uses stable versions. Is there a way to configure it to use the master branch version instead? Otherwise I have to wait until the fix makes it into a stable release, and I’d like to avoid waiting for that.

Below is a link to the discussion around the main issue in Espressif’s issue tracker.

This particular comment shows that the solution will have two parts

  • a fix to the toolchain, which won’t be shipped until IDF 4.0
  • a short-term workaround, which should be shipped as part of IDF 3.2

I would still be interested in a way to tell PlatformIO to use the master branch.

We did a quick fix on our side. Could you open PlatformIO IDE Terminal and type

pio update
pio upgrade --dev

Does debugging work now?

I don’t get the GDB crash anymore and it seems to work now. The very first time I tried it, it didn’t start the debug session successfully, it failed as shown below. But on the second attempt, it worked fine.

Thanks!

Do I have to eventually undo anything related to your two “pio” commands?

Preparing firmware for debugging...
Processing esp32dev (platform: https://github.com/platformio/platform-espressif32.git; board: esp32dev; framework: espidf)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 32 > Espressif ESP32 Dev Module
SYSTEM: ESP32 240MHz 320KB RAM (4MB Flash)
DEBUG: CURRENT(jlink) EXTERNAL(esp-prog, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 0 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pioenvs/esp32dev/src/app_main.o
Generating partitions .pioenvs/esp32dev/partitions.bin
Generating LD script .pioenvs/esp32dev/esp32_out.ld
Compiling .pioenvs/esp32dev/bootloader/bootloader_start.o
[... snip ...]
Compiling .pioenvs/esp32dev/wpa_supplicant/src/wps/wps_registrar.o
Compiling .pioenvs/esp32dev/wpa_supplicant/src/wps/wps_validate.o
Archiving .pioenvs/esp32dev/libwpa_supplicant.a
Indexing .pioenvs/esp32dev/libwpa_supplicant.a
Linking .pioenvs/esp32dev/firmware.elf
Building .pioenvs/esp32dev/firmware.bin
Retrieving maximum program size .pioenvs/esp32dev/firmware.elf
Checking size .pioenvs/esp32dev/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   4.0% (used 13108 bytes from 327680 bytes)
PROGRAM: [=         ]  13.0% (used 135971 bytes from 1048576 bytes)
========================= [SUCCESS] Took 77.96 seconds =========================
Reading symbols from /Users/liyanage/Dropbox/Documents/esp/esp-workshop/1helloworld/.pioenvs/esp32dev/firmware.elf...
done.
PlatformIO Unified Debugger > http://bit.ly/pio-debug
PlatformIO: Initializing remote target...
Open On-Chip Debugger 0.10.0-dev (2018-09-20-12:54)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
adapter speed: 20000 kHz
esp32 interrupt mask on
Info : tcl server disabled
Info : telnet server disabled
Info : No device selected, using first device.
Info : J-Link V9 compiled Apr 15 2014 19:08:28
Info : Hardware version: 9.00
Info : VTarget = 3.322 V
Info : Reduced speed from 20000 kHz to 15000 kHz (maximum).
Info : Reduced speed from 20000 kHz to 15000 kHz (maximum).
Info : clock speed 20000 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: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Detected debug stubs @ 3ffc3078 on core0 of target 'esp32'
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : accepting 'gdb' connection from pipe
Info : Target halted. PRO_CPU: PC=0x400E670E (active)    APP_CPU: PC=0x400E670E 
Info : Target halted. PRO_CPU: PC=0x4009175E (active)    APP_CPU: PC=0x400E670E 
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 33 KB
Info : Flash mapping 1: 0x20018 -> 0x400d0018, 91 KB
Info : Target halted. PRO_CPU: PC=0x4009175E (active)    APP_CPU: PC=0x400E670E 
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
Info : Target halted. PRO_CPU: PC=0x4009175E (active)    APP_CPU: PC=0x400E670E 
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 33 KB
Info : Flash mapping 1: 0x20018 -> 0x400d0018, 91 KB
Info : Using flash size 92 KB
Info : Target halted. PRO_CPU: PC=0x4009175E (active)    APP_CPU: PC=0x400E670E 
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 33 KB
Info : Flash mapping 1: 0x20018 -> 0x400d0018, 91 KB
Info : Using flash size 36 KB
0x400e670e in ?? ()
Error: Too large number of threads 1918857313!
Hardware assisted breakpoint 1 at 0x400d0750: file src/app_main.c, line 15.
Loading section .dram0.data, size 0x22e4 lma 0x3ffc0000
Loading section .iram0.vectors, size 0x400 lma 0x40080000
Loading section .iram0.text, size 0x86d0 lma 0x40080400
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)
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
Info : Target halted. PRO_CPU: PC=0x4009175E (active)    APP_CPU: PC=0x40000400 
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)
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
Info : Target halted. PRO_CPU: PC=0x4009175E (active)    APP_CPU: PC=0x40000400 
Loading section .flash.rodata, size 0x5780 lma 0x3f400020
Loading section .flash.text, size 0x10def lma 0x400d0018
Info : Target halted. PRO_CPU: PC=0x4009175E (active)    APP_CPU: PC=0x40000400 
Warn : keep_alive() was not invoked in the 1000ms timelimit. GDB alive packet not sent! (1687). Workaround: increase "set remotetimeout" in GDB
Error: timed out while waiting for target halted / 4 - 2
Info : Target halted. PRO_CPU: PC=0x400911D2 (active)    APP_CPU: PC=0x40000400 
Error: xtensa_wait_algorithm: not halted 0, pc 0x400911d2, ps 0x60025
Error: Faied to wait algorithm (-302)!
Error: Algorithm run faied (-302)!
Error: Faied to run flasher stub (-302)!
Error: error writing to flash at address 0x400d0000 at offset 0x00000018
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)
cpu0: Current bits set: BreakIn BreakOut RunStallIn
cpu1: Current bits set: BreakIn BreakOut RunStallIn
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000 
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400 
.pioinit:12: Error in sourced command file:
Error finishing flash operation
1 Like

Sorry, could you explain in details?

Sorry, I meant: do I have to undo something related to this command sometime in the future when this change makes it into the main distribution:

pio upgrade --dev

We plan to release 3.6.1 version next week and all users will be switched to stable branch automatically. You are now at the latest RC and it’s good.

That sounds great, thanks!

I’m very impressed how responsive you were and how quickly this got fixed/worked around, even though it’s not your problem. This tells me my subscription to PIO Professional was a good investment :slight_smile:

1 Like

Thank you so much for supporting us with PIO Plus! :blush:

Happy coding with PlatformIO!