Yesterday I applied what I learned yesterday and ran into new issues and solved a few of them.
Yes, esp-idf does contain OpenOCD as it should, but it was in a folder I did not expect and buried quite deep. It may have set it up that way, but that was months ago and I understood nothing about this development environment. I installed stuff in a file alongside my esp-idf installation called SDK. Similar paths for other installations in Windows should apply to other users.
I added an environment variable:
OPENOCD_SCRIPTS = "C:\projects\Espressif_prj\sdk\tools\openocd-esp32\v0.11.0-esp32-20220411\openocd-esp32\share\openocd\scripts".
I also added:
"C:\projects\Espressif_prj\sdk\tools\openocd-esp32\v0.11.0-esp32-20220411\openocd-esp32\bin" and "C:\projects\Espressif_prj\sdk\tools\openocd-esp32\v0.11.0-esp32-20220411\openocd-esp32\share\openocd\scripts" to my path variable.
I'm not sure if I need the all, but I know adding them to path allowed me to run OpenOCD from the command prompt with the simple "openocd -f board/esp32c3-builtin.cfg" command. Alos these path changes required me restarting VSCode before they started to work correctly.
My hardware setup is an ESP32-C3DevkitM-1V1.0 with a USB plugged into the mini USB port and a second USB with the two data lines broken out connecting the header on the board. The green wire goes to pin 19 and the white goes to pin 18. This solved the second issue that came up after getting OpenOCD to run the esp-idf version where it could not find the hardware. Makes sense since it was not plugged in. I was under the assumption that the existing USB already connected to the D+ and D- pins on the board. However the more I read, the more I found references to having two USB ports visible in the device manager. The mini USB shows up as a Silicon Labs CP210x device and the second deice is just a regular COM port. I did have to use the USB Driver Tool
https://visualgdb.com/UsbDriverTool/ or Zadig
https://github.com/pbatard/libwdi/wiki/Zadig to change the drive to the WinUSB driver.
With the correct driver I could get it connect using this launch.json file:
Code: Select all
{
"version": "0.2.0",
"configurations": [
{
"preLaunchTask": "preRun",
"name": "ESP debug",
"type": "cppdbg",
"request": "launch",
"MIMode": "gdb",
"miDebuggerPath": "${command:espIdf.getXtensaGdb}",
"program": "${workspaceFolder}/build/${command:espIdf.getProjectName}.elf",
"windows": {
"program": "${workspaceFolder}\\build\\${command:espIdf.getProjectName}.elf"
},
"cwd": "${workspaceFolder}",
"environment": [{ "name": "PATH", "value": "${config:idf.customExtraPaths}" }],
"setupCommands": [
{ "text": "target remote localhost:3333" },
{ "text": "set remote hardware-watchpoint-limit 2"},
{ "text": "mon reset halt" },
{ "text": "thb app_main" },
{ "text": "flushregs" }
],
"externalConsole": false,
"logging": {
"engineLogging": true
}
}
]
}
// ESP-IDF Debug Adapter:
// {
// "version": "0.2.0",
// "configurations": [
// {
// "preLaunchTask": "preRun",
// "name": "ESP OpenOCD",
// "type": "cppdbg",
// "request": "launch",
// "cwd": "${workspaceFolder}/build",
// "program": "${workspaceFolder}/build/myLifterESP.elf",
// "miDebuggerPath": "C:/projects/Espressif_prj/sdk/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gdb.exe",
// "setupCommands": [
// { "text": "target remote 127.0.0.1:3333" },
// // { "text": "target remote :3333" },
// { "text": "set remote hardware-watchpoint-limit 2"},
// { "text": "monitor reset halt"},
// { "text": "flushregs"},
// // { "test": "mon program_esp build/bootloader.bin 0x1000 verify"},
// // { "test": "mon program_esp build/partition_table/partition-table.bin 0x8000 verify"},
// // { "test": "mon program_esp build/myLifterESP.bin 0x10000 verify"},
// // { "text": "monitor reset halt"},
// // { "text": "flushregs"}
// ]
// }
// ]
// }
The commented out section is based on the tutorial I referenced in the first post and the active code is mostly what came in the file already. Either one gives me an error with "target remote" and "mon" setup commands. I commented those out and it will run for a second and then quit with the error "ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Don't know how to run. Try "help target"." WIthout commenting out "target remote" I get "and erro message after it tried to run for a few seconds saying "Unable to start debugging. Unexpected GDB output from command "-interpreter-exec console "target remote localhost:3333"". localhost:3333: (undocumented errno 138)."
I think it should run with those lines of code, but I'm not sure where to look next?
I have a preRun task that starts OpenOCD when pressing the debug button that looks like this:
Code: Select all
"tasks": [
{
"label": "preRun",
"type": "shell",
"windows":{
"command": [
"clear",
"start openocd -c \"set ESP_RTOS none\" -f board/esp32c3-builtin.cfg",
"exit"
]
}
}
I found this thread that seems to have the same issue, but it has gone unanswered for several months now:
https://esp32.com/viewtopic.php?t=27043.
Where do I begin to fix this?