'wsl ubuntu debug stm32 with openocd in vscode
When I call openocd which is linux executable , it give me :
./openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /mnt/c/Users/Administrator/Desktop/work/ODrive/Firmware -f interface/stlink.cfg -f target/stm32f7x.cfg -c "reset_config none separate"
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-12-07-17:30)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
none separate
Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : clock speed 2000 kHz
Error: open failed
Because of we cant call avalible usb device from WSL , so we call .exe in WSL for instead .
/mnt/c/openocd/bin/openocd.exe -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /mnt/c/Users/Administrator/Desktop/work/ODrive/Firmware -f interface/stlink.cfg -f target/stm32f7x.cfg -c "reset_config none separate"Open On-Chip Debugger 0.11.0+dev-00572-g94e7535be (2022-02-19-14:36)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
none separate
Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V2J29M18 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.224258
Info : stm32f7x.cpu: Cortex-M7 r1p1 processor detected
Info : stm32f7x.cpu: target has 8 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f7x.cpu on 50000
Info : Listening on port 50000 for gdb connections
then we successfully detect stm device in WSL
But when I start from VSCode . with
{
// For the Cortex-Debug extension
"type": "cortex-debug",
"servertype": "openocd",
"request": "launch",
"name": "Debug ODrive v4.x - ST-Link",
"executable": "${workspaceRoot}/build/ODriveFirmware.elf",
"configFiles": [
"interface/stlink.cfg",
"target/stm32f7x.cfg",
],
"showDevDebugOutput": "both",
"openOCDLaunchCommands": [
"reset_config none separate"
],
"svdFile": "${workspaceRoot}/Private/v4/STM32F722.svd",
"cwd": "${workspaceRoot}"
},
The command automatically add
-f /home/ubuntu/.vscode-server/extensions/marus25.cortex-debug-1.2.2/support/openocd-helpers.tcl
which cause
pen On-Chip Debugger 0.11.0+dev-00572-g94e7535be (2022-02-19-14:36)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
embedded:startup.tcl:26: Error: Can't find /home/ubuntu/.vscode-server/extensions/marus25.cortex-debug-1.2.2/support/openocd-helpers.tcl
in procedure 'script'
at file "embedded:startup.tcl", line 26
Then I do an test whihc delete file locate in Windows openocd\share\openocd\scripts I find when execute openocd.exe in WSL it will search path whihc on Windows instead of ubuntu file . which means it can't find /home/ubuntu/.vscode-server/extensions/marus25.cortex-debug-1.2.2/support/openocd-helpers.tcl the isn't exsit on Window But on WSL .
My question why vscode server insert that file and how I Solve problem like this?
Solution 1:[1]
I ran into something similar; I don't know if these changes will help you. The Cortex Debugger was updated in Feb 2022 and in order for me to continue to use it, I added this line to .vscode/launch.json for all my launch specifications:
"searchDir": ["/mnt/c/openocd/tcl", "//wsl$/Ubuntu-18.04"]
You can find other debug attributes in https://github.com/Marus/cortex-debug/blob/master/debug_attributes.md. The addition "//wsl$/Ubuntu-18.04" to the searchDir allowed GDB to find the cortex settings in my ubuntu home path (~/.vscode-server/extensions/marus25.cortex-debug-1.2.2). I don't know if you need "/mnt/c/openocd/tcl", but you would need to include other paths your setup previously used.
Other changes you may want to consider are
- Change "runToMain": true, to "runToEntryPoint": "main": Cortex Debugger has deprecated runToMain.
- Change ${workspaceRoot} to ${workspaceFolder} : this is not a Cortex-debugger deprecation, rather a VSCode deprecation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | muddy_gardener |
