How to use CMSIS-DAP for debugging ESP32

I am using the latest platform and toolchain.But now some problems have arisen and I am unable to start the debugging process.I attempted to obtain more information by using commands in the PlatformIO Core CLI.

Use the following instructions to attempt to start openocd.Here i have an unusual OCD_ID = ffffffff.

PS E:\ARDUINO_PROJECT\PIO_P\DS66TEST> C:\Users\19218\.platformio\packages\tool-openocd-esp32\bin\openocd.exe -f openocd.cfg -f custom-esp32.cfg 
Open On-Chip Debugger v0.12.0-esp32-20250707 (2025-07-06-17:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
trst_only separate trst_push_pull
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.1.0
Info : CMSIS-DAP: Serial# = 1304000300272162046b596800000e1f0000000097969921
Info : CMSIS-DAP: Interface Initialised (JTAG)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 100 kHz
Info : cmsis-dap JTAG TLR_RESET
Info : cmsis-dap JTAG TLR_RESET
Info : JTAG tap: esp32.tap1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: auto0.tap tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Warn : AUTO auto0.tap - use "jtag newtap auto0 tap -irlen 5 -expected-id 0x120034e5"
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : cmsis-dap JTAG TLR_RESET
Info : cmsis-dap JTAG TLR_RESET
Info : JTAG tap: esp32.tap1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: auto0.tap tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Warn : [esp32.cpu1] Unexpected OCD_ID = ffffffff
Error: [esp32.cpu1] Examination failed
Warn : target esp32.cpu1 examination failed
Info : [esp32.cpu1] starting gdb server on 3333
Info : Listening on port 3333 for gdb connections

Then I attempted to use gdb for connection and debugging.

PS E:\ARDUINO_PROJECT\PIO_P\DS66TEST> C:\Users\19218\.platformio\packages\toolchain-xtensa-esp32\bin\xtensa-esp32-elf-gdb.exe .pio\build\pico32\firmware.elf
>> 
C:\Users\19218\.platformio\packages\toolchain-xtensa-esp32\bin\xtensa-esp32-elf-gdb.exe: warning: Couldn't determine a path for the index cache directory.
GNU gdb (crosstool-NG esp-2021r2-patch5) 9.2.90.20200913-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=xtensa-esp32-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from .pio\build\pico32\firmware.elf...
(gdb) target remote :3333
Remote debugging using :3333
Remote communication error.  Target disconnected.: (undocumented errno 10061).
(gdb) 

At this point, openocd reported an error.

Warn : [esp32.cpu1] Unexpected OCD_ID = ffffffff
Error: [esp32.cpu1] Examination failed
Warn : target esp32.cpu1 examination failed
Info : [esp32.cpu1] starting gdb server on 3333
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Error: Target not examined yet
Error: [esp32.cpu1] Execution of event gdb-attach failed:

Error: [esp32.cpu1] Target not examined yet, refuse gdb connection 1!
Error: attempted 'gdb' connection rejected

the openocd.cfg

adapter driver cmsis-dap
transport select jtag
set _ONLYCPU 1
adapter speed 100
reset_config trst_only

the custom-esp32.cfg

set _CHIPNAME esp32
set _CPUTAPID 0x120034e5
set _ESP_ARCH xtensa
set _ONLYCPU 1
set _ESP_SMP_TARGET 0
set _HP_TAPNUM 1


jtag newtap $_CHIPNAME tap1 -irlen 5 -expected-id $_CPUTAPID
target create $_CHIPNAME.cpu1 $_ESP_ARCH -chain-position $_CHIPNAME.tap1 -coreid 1
$_CHIPNAME.cpu1 configure -work-area-phys 0x3FFE0000 -work-area-virt 0x3FFE0000 -work-area-size 0x18000 -work-area-backup 1
$_CHIPNAME.cpu1 configure -event gdb-attach {
    halt 1000
    reset halt
    esp32 cpu1 arp_examine
}

jtag init
source [find target/xtensa-core-esp32.cfg]

additional information

platformio.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

[env:pico32]
platform = espressif32
board = pico32
framework = arduino
lib_deps = nhatuan84/ESP32CAN @ ^1.0.0
build_flags = -I src  -DCONFIG_ESP32_DEBUG_OCD_AWARE=1
monitor_speed = 115200
build_type = debug
debug_build_flags = -Og -g3
debug_tool = cmsis-dap
debug_init_break = setup
debug_server = 
	${platformio.packages_dir}/tool-openocd-esp32/bin/openocd.exe
	-f
	openocd.cfg
	-f
	custom-esp32.cfg

and my esp32

Retrieving maximum program size .pio\build\pico32\firmware.elf
Checking size .pio\build\pico32\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.1% (used 23424 bytes from 327680 bytes)
Flash: [==        ]  22.2% (used 290601 bytes from 1310720 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Using manually specified: COM11
Uploading .pio\build\pico32\firmware.bin
esptool.py v4.5.1
Serial port COM11
Connecting.....
Chip is ESP32-PICO-D4 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: d4:d4:da:bd:2c:5c