PlatformIO Community

ESP32 OpenOCD can't set breakpoint

Snip from the debug console:
.
.
.
** Programming Finished **
** Verify Started **
Offset 0x00010000 is out of range of the flash bank
embedded:startup.tcl:480: Error: ** Verify Failed **
in procedure ‘program_esp32’
in procedure ‘program_error’ called at file “C:/Users/Niels/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg”, line 138
at file “embedded:startup.tcl”, line 480
.
.
.

Thread 1 hit Temporary breakpoint 1, app_main () at src\main.c:40
40 int app_main(void) {
Error: esp32: Failed to read insn (-4)!
Error: esp32: Failed to add SW BP!
Error: can’t add breakpoint: resource not available
Warning:
Cannot insert breakpoint 2.
Cannot access memory at address 0x400d3684

It seems that I need to change the OpenOCD appimage_offset like this:
openocd -f board/esp-wroom-32.cfg-c "init; halt; esp32 appimage_offset 0x180000
But where/how do you use this command? Not in debug console it seems. Is it placed in a debug configuration file somewhere?

The ESP32 has hardware limitations regarding the number of breakpoints, and it seems you’re exhausting that (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/jtag-debugging/tips-and-quirks.html). However,

seems to be the real error here – why is it trying to flash to offset 0x10000 and what exact image? Can you share the platformio.ini that makes PlatformIO do that?

Thanks for the prompt response!

I actually made sure that no brake points was set and the app_main() did break when i ran the debugger. I then tried to insert one more break point but got the error shown above.

My platform.ini:

; 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
[platformio]
default_envs = nodemcu-32s

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
;board_upload.flash_size = 8MB
;board_upload.maximum_size = 8388608
board_upload.flash_size = 4MB
board_upload.maximum_size = 4194304
framework = espidf
monitor_speed = 115200
debug_tool = olimex-arm-usb-ocd-h
;board_build.partitions = ESP32_OTA_8M.csv
board_build.partitions = ESP32_OTA_4M.csv

The partition file ESP32_OTA_4M.csv:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     ,        0x4000,
otadata,  data, ota,     ,        0x2000,
phy_init, data, phy,     ,        0x1000,
app0,     app,  ota_0,   ,        0x180000,
app1,     app,  ota_1,   ,        0x180000,

Things seem to go from bad to worse here, now I get this popup notification when trying to start the debugger:
“Failed to launch GDB: .pioinit:11: Error in sourced command file: Remote communication error. Target disconnected.: Success. (from interpreter-exec console “source .pioinit”)”

Only difference from yesterday is that the computer has been turned off yesterday and back on again today. Very strange!

Full log from the debug console:

Processing nodemcu-32s (platform: espressif32; board: nodemcu-32s; framework: espidf)


Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/nodemcu-32s.html
PLATFORM: Espressif 32 (2.0.0) > NodeMCU-32S
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (olimex-arm-usb-ocd-h) External (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)
PACKAGES:

  • framework-espidf 3.40100.200827 (4.1.0)
  • tool-cmake 3.16.4
  • tool-esptoolpy 1.20600.0 (2.6.0)
  • tool-idf 1.0.1
  • tool-mconf 1.4060000.20190628 (406.0.0)
  • tool-ninja 1.9.0
  • toolchain-esp32ulp 1.22851.191205 (2.28.51)
  • toolchain-xtensa32 2.80200.200827 (8.2.0)
    Reading CMake configuration…
    LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 2 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |--
    |-- <mongoose_espidf> 0.1.0
    Building in debug mode
    Compiling .pio\build\nodemcu-32s\esp-idf\src\HWcfg.c.o
    Compiling .pio\build\nodemcu-32s\esp-idf\src\PID.c.o
    Compiling .pio\build\nodemcu-32s\esp-idf\src\StorageManager.c.o
    Compiling .pio\build\nodemcu-32s\esp-idf\src\TempSensor.c.o
    Compiling .pio\build\nodemcu-32s\esp-idf\src\TimeDateMgr.c.o
    Compiling .pio\build\nodemcu-32s\esp-idf\src\WebServer.c.o
    Compiling .pio\build\nodemcu-32s\esp-idf\src\WiFiCfg.c.o
    Compiling .pio\build\nodemcu-32s\esp-idf\src\main.c.o
    Compiling .pio\build\nodemcu-32s\esp-idf\src\systemcfg.c.o
    Generating LD script .pio\build\nodemcu-32s\esp32_out.ld
    Archiving .pio\build\nodemcu-32s\esp-idf\libsodium\liblibsodium.a
    Archiving .pio\build\nodemcu-32s\esp-idf\wpa_supplicant\libwpa_supplicant.a
    Generating project linker script .pio\build\nodemcu-32s\esp32.project.ld
    Linking .pio\build\nodemcu-32s\firmware.elf
    Building .pio\build\nodemcu-32s\firmware.bin
    Retrieving maximum program size .pio\build\nodemcu-32s\firmware.elf
    Checking size .pio\build\nodemcu-32s\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [= ] 11.6% (used 38104 bytes from 327680 bytes)
    Flash: [===== ] 53.6% (used 843218 bytes from 1572864 bytes)
    esptool.py v2.6
    ========================= [SUCCESS] Took 39.06 seconds =========================
    Reading symbols from c:\Users\Niels\Documents\PlatformIO\Projects\nanoBrewer.pio\build\nodemcu-32s\firmware.elf…
    done.
    PlatformIO Unified Debugger -> http://bit.ly/pio-debug
    PlatformIO: debug_tool = olimex-arm-usb-ocd-h
    PlatformIO: Initializing remote target…
    Open On-Chip Debugger v0.10.0-esp32-20190708 (2019-07-08-11:04)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
    adapter speed: 20000 kHz
    Info : Configured 2 cores
    esp32 interrupt mask on
    Info : tcl server disabled
    Info : telnet server disabled
    Info : ftdi: if you experience problems at higher adapter clocks, try the command “ftdi_tdo_sample_edge falling”
    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=0x400803C0 (active) APP_CPU: PC=0x40161B06
    Info : accepting ‘gdb’ connection from pipe
    Error: No symbols for FreeRTOS
    Ignoring packet error, continuing…
    warning: unrecognized item “timeout” in “qSupported” response
    Error: timed out while waiting for target halted / 4 - 2
    Info : Target halted. PRO_CPU: PC=0x400803C0 (active) APP_CPU: PC=0x40161B06
    Error: xtensa_wait_algorithm: not halted 0, pc 0x400803c0, ps 0x60035
    Error: Failed to wait algorithm (-302)!
    Error: Algorithm run failed (-302)!
    Error: Failed to run flasher stub (-302)!
    Warn : Failed to get flash mappings (-302)!
    Error: Target is already running an algorithm
    Error: Failed to start algorithm (-4)!
    Error: Algorithm run failed (-4)!
    Error: Failed to run flasher stub (-4)!
    Error: Target is already running an algorithm
    Error: Failed to start algorithm (-4)!
    Error: Algorithm run failed (-4)!
    Error: Failed to run flasher stub (-4)!
    Error: Failed to probe flash, size 0 KB
    Error: auto_probe failed
    Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use ‘gdb_memory_map disable’.
    Error: attempted ‘gdb’ connection rejected
    Error: error during select: Unknown error
    Warn : Flash driver of esp32.flash does not support free_driver_priv()
    Warn : Flash driver of irom does not support free_driver_priv()
    Warn : Flash driver of drom does not support free_driver_priv()
    .pioinit:11: Error in sourced command file:
    Remote communication error. Target disconnected.: Success.

First of all please use the latest platform version which has openocd updates, which are not yet released. Set in the platformio.ini

platform = https://github.com/platformio/platform-espressif32.git

instead of the old platform = espressif32.

The new code also changes how the ESP32 is programmed and might solve the first problem.

After putting in your suggestions I get this in the debug console:

PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = olimex-arm-usb-ocd-h
PlatformIO: Initializing remote target…
Open On-Chip Debugger v0.10.0-esp32-20200709 (2020-07-09-08:54)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
Info : Configured 2 cores
adapter speed: 20000 kHz
Info : tcl server disabled
Info : telnet server disabled
Info : ftdi: if you experience problems at higher adapter clocks, try the command “ftdi_tdo_sample_edge falling”
Info : clock speed 20000 kHz
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway…
Error: esp32.cpu0: IR capture error; saw 0x00 not 0x01
Warn : Bypassing JTAG setup events due to errors
Info : accepting ‘gdb’ connection from pipe
Error: No symbols for FreeRTOS
Error: Target not examined yet
Error executing event gdb-attach on target esp32:
Error: Target not halted
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use ‘gdb_memory_map disable’.
Error: attempted ‘gdb’ connection rejected
Error: error during select: Unknown error
.pioinit:11: Error in sourced command file:
Remote communication error. Target disconnected.: Success

Seems like loose cables or a too high debugging speed to me. The JTAG data line is just seeing a constant HIGH on the line. The JTAG speed is fast with 20MHz after all which might cause problems. Check the file C:\Users\<user>\.platformio\packages\tool-openocd-esp32\share\openocd\scripts\interface\ftdi\esp32_devkitj_v1.cfg regarding the adapter_khz 20000 setting; e.g, set to 500 kHz.

I don’t seem to be able to change the ‘adapter_khz’, no matter what I write in the “tool-openocd-esp32\share\openocd\scripts\board\esp-wroom-32.cfg” file its still 20000 when I run the debugger?
Am I in the wrong place?

Go into C:\Users\<user>\.platformio\packages. Are there multiple tool-openocd-esp32 folder names which have suffixes in them?

Yes there are one folder with suffix (the oldest one), I used the one without suffix and the ‘esp-wroom-32.cfg’ file in the ‘Board’ folder as shown in the picture below.
It now contains the following:

echo “WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.”
set ESP32_FLASH_VOLTAGE 3.3
adapter_khz 500
source [find target/esp32.cfg]

image

Openocd for windows is available for two package versions, 2.1000.20200709 (newest) and 1.1000.20190709 (version before that). Make sure that the package.json in the tool-openocd-esp32* folder you’re modifying has the most recent version as this is what’s used in your project when you set platform = http:/....

Why in that file? This file doesn’t contain the adapter_khz setting by default.

That setting is as I said in the interface.

So you should revert your changes and modify the above file instead.

Wow that is fast support!
The reason for using ‘esp-wroom-32.cfg’ is because that is what worked before your suggestion on " platform = http:/... ", when I was changing parameters. But I will try the ‘ESP32_devkitj_v1.cfg’, BTW where is the reference to this file in the VScode environment? platformio.ini is not referencing the cfg file.

package.json file:

{
  "name": "tool-openocd-esp32",
  "version": "2.1000.20200709",
  "description": "Open On-Chip Debugger for Espressif ESP32",
  "keywords": [
    "tools",
    "debugger",
    "debug server",
    "uploader",
    "esp32"
  ],
  "homepage": "http://openocd.org",
  "license": "GPL-2.0-or-later",
  "system": [
    "windows_x86",
    "windows_amd64"
  ],
  "repository": {
    "type": "git",
    "url": "https://github.com/espressif/openocd-esp32"
  }
}

I got much further but still some errors when evoking the debugger. Clock speed still 20000 it seem?

Processing nodemcu-32s (platform: https://github.com/platformio/platform-espressif32.git; board: nodemcu-32s; framework: espidf)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/nodemcu-32s.html
PLATFORM: Espressif 32 (2.0.0+sha.07919d0) > NodeMCU-32S
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (olimex-arm-usb-ocd-h) External (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)
PACKAGES:
 - framework-espidf 3.40100.200827 (4.1.0)
 - tool-cmake 3.16.4
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - tool-idf 1.0.1
 - tool-mconf 1.4060000.20190628 (406.0.0)
 - tool-ninja 1.9.0
 - toolchain-esp32ulp 1.22851.191205 (2.28.51)
 - toolchain-xtensa32 2.80200.200827 (8.2.0)
Reading CMake configuration...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 2 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <TempIF>
|-- <mongoose_espidf> 0.1.0
Building in debug mode
Compiling .pio\build\nodemcu-32s\esp-idf\src\HWcfg.c.o
Compiling .pio\build\nodemcu-32s\esp-idf\src\PID.c.o
Compiling .pio\build\nodemcu-32s\esp-idf\src\StorageManager.c.o
Compiling .pio\build\nodemcu-32s\esp-idf\src\TempSensor.c.o
Compiling .pio\build\nodemcu-32s\esp-idf\src\TimeDateMgr.c.o
Compiling .pio\build\nodemcu-32s\esp-idf\src\WebServer.c.o
Compiling .pio\build\nodemcu-32s\esp-idf\src\WiFiCfg.c.o
Compiling .pio\build\nodemcu-32s\esp-idf\src\main.c.o
Compiling .pio\build\nodemcu-32s\esp-idf\src\systemcfg.c.o
Generating LD script .pio\build\nodemcu-32s\esp32_out.ld
Archiving .pio\build\nodemcu-32s\esp-idf\libsodium\liblibsodium.a
Archiving .pio\build\nodemcu-32s\esp-idf\wpa_supplicant\libwpa_supplicant.a
Generating project linker script .pio\build\nodemcu-32s\esp32.project.ld
Linking .pio\build\nodemcu-32s\firmware.elf
Retrieving maximum program size .pio\build\nodemcu-32s\firmware.elf
Building .pio\build\nodemcu-32s\firmware.bin
Checking size .pio\build\nodemcu-32s\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.6% (used 38104 bytes from 327680 bytes)
Flash: [=====     ]  53.6% (used 843218 bytes from 1572864 bytes)
esptool.py v2.6
========================= [SUCCESS] Took 34.05 seconds =========================
Reading symbols from c:\Users\Niels\Documents\PlatformIO\Projects\nanoBrewer\.pio\build\nodemcu-32s\firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = olimex-arm-usb-ocd-h
PlatformIO: Initializing remote target...
Open On-Chip Debugger  v0.10.0-esp32-20200709 (2020-07-09-08:54)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
Info : Configured 2 cores
adapter speed: 20000 kHz

Info : tcl server disabled
Info : telnet server disabled
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
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 0 was reset.
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
Info : accepting 'gdb' connection from pipe
Error: No symbols for FreeRTOS
Info : Target halted. CPU0: PC=0x40161B06 (active)
Info : Target halted. CPU1: PC=0x40161B06
Info : cpu0: Target halted, PC=0x40090153, debug_reason=00000001
Warn : Empty flash mapping!
Warn : Failed to get flash mappings (0)!
Info : cpu0: Target halted, PC=0x40090A5F, debug_reason=00000001
Info : cpu0: Target halted, PC=0x40091856, debug_reason=00000001
Info : Auto-detected flash bank 'esp32.flash' size 4096 KB
Info : Using flash bank 'esp32.flash' size 4096 KB
Info : cpu0: Target halted, PC=0x400906D6, debug_reason=00000001
Warn : Empty flash mapping!
Warn : Failed to get flash mappings (0)!
Info : cpu0: Target halted, PC=0x400830B7, debug_reason=00000001
Info : Using flash bank 'esp32.irom' size 0 KB
Info : cpu0: Target halted, PC=0x400830B7, debug_reason=00000001
Error: Failed to get flash maps (393269)!
Warn : Failed to get flash mappings (-4)!
Info : cpu0: Target halted, PC=0x400830B7, debug_reason=00000001
Info : Using flash bank 'esp32.drom' size 0 KB
warning: Overlapping regions in memory map: ignoring
0x40161b06 in uart_ll_set_stop_bits (stop_bit=UART_STOP_BITS_1, hw=0x800e836e) at C:\Users\Niels\.platformio\packages\framework-espidf\components\soc\esp32\include/hal/uart_ll.h:264
264	        hw->rs485_conf.dl1_en = 1;
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)
Info : cpu0: Target halted, PC=0x40087A63, debug_reason=00000001
cpu0: Target halted, PC=0x40087A63, debug_reason=00000001
Info : esp32: Core 0 was reset.
Info : esp32: Core 1 was reset.
esp32: Core 0 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
** Programming Started **
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
Info : cpu0: Target halted, PC=0x40091856, debug_reason=00000001
cpu0: Target halted, PC=0x40091856, debug_reason=00000001
Error: Transfer data tmo!
Error: Failed to exec algorithm user func (-5)!
Info : cpu0: Target halted, PC=0x400003C0, debug_reason=00000001
Transfer data tmo!
Failed to exec algorithm user func (-5)!
cpu0: Target halted, PC=0x400003C0, debug_reason=00000001
** Programming Finished **
** Verify Started **
** Programming Finished **
** Verify Started **
Info : cpu0: Target halted, PC=0x40091856, debug_reason=00000001
cpu0: Target halted, PC=0x40091856, debug_reason=00000001
embedded:startup.tcl:449: Error: ** Verify Failed **
in procedure 'program_esp'
in procedure 'program_error' called at file "C:/Users/Niels/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 94
at file "embedded:startup.tcl", line 449
embedded:startup.tcl:449: Error: ** Verify Failed **
in procedure 'program_esp'
in procedure 'program_error' called at file "C:/Users/Niels/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 94
at file "embedded:startup.tcl", line 449
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)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
** Programming Started **
Error: timed out while waiting for target halted / 4 - 2
Info : cpu0: Target halted, PC=0x40090158, debug_reason=00000000
Error: xtensa_wait_algorithm: not halted 0, pc 0x40090158, ps 0x60025
Error: Failed to wait algorithm (-302)!
timed out while waiting for target halted / 4 - 2
cpu0: Target halted, PC=0x40090158, debug_reason=00000000
xtensa_wait_algorithm: not halted 0, pc 0x40090158, ps 0x60025
Failed to wait algorithm (-302)!
Error: Algorithm run failed (-302)!
Error: Failed to run flasher stub (-302)!
Error: failed erasing sectors 8 to 8
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp'
in procedure 'program_error' called at file "C:/Users/Niels/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
Algorithm run failed (-302)!
Failed to run flasher stub (-302)!
failed erasing sectors 8 to 8
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp'
in procedure 'program_error' called at file "C:/Users/Niels/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
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)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
** Programming Started **
Error: Target is already running an algorithm
Error: Failed to start algorithm (-4)!
Target is already running an algorithm
Failed to start algorithm (-4)!
Error: Algorithm run failed (-4)!
Error: Failed to run flasher stub (-4)!
Error: failed erasing sectors 16 to 221
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp'
in procedure 'program_error' called at file "C:/Users/Niels/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
Algorithm run failed (-4)!
Failed to run flasher stub (-4)!
failed erasing sectors 16 to 221
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp'
in procedure 'program_error' called at file "C:/Users/Niels/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
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)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
Hardware assisted breakpoint 1 at 0x400d3d14: file src\main.c, line 40.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = thb app_main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug

OpenOCD has a hard time talking to your ESP32. I see several potential causes:

  1. You have selected the incorrect ESP32-board. What is the exact board you are using?

  2. Your firmware uses the JTAG pins (GPIO12 thru GPIO15) for other things than JTAG. Can you try to get the debugging working with a simple blink program?

  3. Your firmware uses some of the pins required for the communication with the flash memory. Does your firmware more or less work when you upload and run it normally?

  4. You are powering the ESP32 through the debug adapter, which in most cases doesn’t work. I assume you have a ARM-USB-OCD-H debug adapter. Do you power both the debug adapter and the ESP32 separately?

What OpenOCD config files are being used is completely separate from VSCode and won’t be in the config files for VSCode. VSCode just gets a task to call into pio debug and PIO will take care of all the intrinsics no getting a GDB server (in this case implemented by openocd) up and running that VSCode can connect to. The .cfg files are partly set in Python code and partly in the board JSON file.

Actually when I look into this code it hits me. Suddenly PlatformIO does a

to set the adapter_khz argument itself based on the debug settings? That wasn’t there until very recently.

Please do the following:

  • revert all adapter_khz changes / additions in the .cfg files that you have done
  • add board_debug.adapter_speed = 500 in the platformio.ini and retry

The platformio,ini now contains the “board_debug.adapter_speed = 500” setting. But adapter speed still seems to be 20000.
I am still puzzled why it’s the ‘ftdi/esp32_devkitj_v1’ that is “interesting”? In the debug log it looks like OpenOCD is using ‘esp-wroom-32.cfg’ with the line " WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release." Also the ‘esp32_devkitj_v1.cfg’ contains a reference to the VID and the PID (ftdi_vid_pid 0x0403 0x6010 0x0403 0x6014) which doesn’t add up with the Olimex ARM-USB-OCD-H VID and PID (0x15ba 0x002b)?
The ‘ftdi/olimex-arm-usb-ocd-h.cfg’ contains the correct ref. to the VID and PID. Should I try and change the setting in ‘ftdi/esp32_devkitj_v1.cfg’ to the correct VID and PID?

Debug console:

Reading symbols from c:\Users\Niels\Documents\PlatformIO\Projects\nanoBrewer.pio\build\nodemcu-32s\firmware.elf…
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = olimex-arm-usb-ocd-h
PlatformIO: Initializing remote target…
Open On-Chip Debugger v0.10.0-esp32-20200709 (2020-07-09-08:54)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
Info : Configured 2 cores
adapter speed: 20000 kHz

Info : tcl server disabled
Info : telnet server disabled
Info : ftdi: if you experience problems at higher adapter clocks, try the command “ftdi_tdo_sample_edge falling”
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 : accepting ‘gdb’ connection from pipe
Error: No symbols for FreeRTOS
Info : Target halted. CPU0: PC=0x40007BA1 (active)
Info : Target halted. CPU1: PC=0x400076DD
Info : cpu0: Target halted, PC=0x4000C02B, debug_reason=00000001
Error: Failed to get flash maps (2146559)!
Warn : Failed to get flash mappings (-4)!
Info : cpu0: Target halted, PC=0x4000C02B, debug_reason=00000001
Info : cpu0: Target halted, PC=0x4000C02B, debug_reason=00000001
Error: Failed to get flash size!
Error: Failed to probe flash, size 0 KB
Error: auto_probe failed

You’re right I overread that your platformio.ini does a debug_tool = olimex-arm-usb-ocd-h. Can you add upload_protocol = olimex-arm-usb-ocd-h to the platformio.ini, then do normal “Build” and then a “Verbose Upload”? The verbose upload log should reveal the exact openocd command used in there with all the -f config file switches. These will tell you what adapter cfg file is used.

Not sure I know how to do a verbose upload?

Check the Advanced section in the environment’s project tasks list (docs).

Alternatively pio run -t upload -v from the commandline.