Help setting up openocd with ST-LINK in WSL2

Hello,

Following this guide I am trying to set up hardware debugging with the following hardware:

Software/Configuration:

  • Latest Arduplane firmware
  • WSL2. Everything happens inside the WSL2 (coding, building, etc) according to this guide.
  • BRD_OPTIONS = 9 (tried also 8)
  • sudo apt install openocd
  • this is my ./build/Arduplane/bin/openocd.cfg file
source [find interface/stlink-v2.cfg] # tried also stlink.cfg and stlink-v2-1.cfg
source [find target/stm32f7x.cfg]
init
$_TARGETNAME configure -rtos auto

I get the following output when I run openocd (tried with sudo as well)

Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2-1.cfg is deprecated, please switch to interface/stlink.cfg
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 : clock speed 2000 kHz
Error: open failed


Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

Did not move to the next steps (setting up GDB) as there was no point. I suspect the error has to do with fact that I am using WSL2 instead of native Ubuntu. Any ideas?

EDIT

Needed to install USBIPD (instructions for windows10 if anyone faces issues here) for usb forwarding in WSL2. Now the error is different. According to this video this is solved by setting BRD_OPTION to 9. Tried it, however without any luck.

Open On-Chip Debugger 0.11.0
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 : clock speed 2000 kHz
Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.230647
Error: init mode failed (unable to connect to the target)


Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

Solved.

It was actually a wrong connection issue. So the steps above work, if anyone faces similar issues with debugger in WSL2.