5 years, 6 months ago.

Debugging on Visual Studio Code with openocd

On Windows 10 with openocd on an STM32F4 and using the example launch. json and tasks.json files provided at https://os.mbed.com/users/janjongboom/notebook/debugging-ublox_evk_odin_w2-with-openocd-and-visua/# (changing only the paths and target) and after thoroughly reviewing https://os.mbed.com/questions/79289/How-to-get-vscode-debugging-working-with/, https://os.mbed.com/docs/v5.9/tutorials/visual-studio-code.html, and elsewhere, I get the following output on the VSC debug console:

1: (653) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
1: (694) LaunchOptions  ExePath='C:\Users\jgree\Projects\VoboNode_vsc_nucleo_f411RE\VoBoNode\BUILD\MTS_MDOT_F411RE\GCC_ARM-DEBUG\VoBoNode.elf'
1: (694) LaunchOptions  WorkingDirectory='C:\Users\jgree\Projects\VoboNode_vsc_nucleo_f411RE\VoBoNode'
1: (694) LaunchOptions  ExeArguments=''
1: (694) LaunchOptions MIMode='gdb'
1: (694) LaunchOptions  MIDebuggerPath='C:\Program Files (x86)\GNU Tools ARM Embedded\6 2017-q2-update\bin\arm-none-eabi-gdb.exe'
1: (694) LaunchOptions  WaitDynamicLibLoad='false'
1: (694) LaunchOptions  DebugServer='C:\openOCD\openocd-0.10.0\bin\openocd.exe'
1: (694) LaunchOptions  DebugServerArgs='-f C:/OpenOCD/openocd-0.10.0/scripts/board/st_nucleo_f4.cfg -f C:/OpenOCD/openocd-0.10.0/scripts/interface/stlink-v2-1.cfg -c init -c "reset init"'
1: (694) LaunchOptions  ServerStarted='target halted due to debug-request, current mode: Thread'
1: (694) LaunchOptions  FilterStderr='true'
1: (694) LaunchOptions  ServerLaunchTimeout='20000'
1: (694) LaunchOptions>
1: (694) LaunchOptions    <SetupCommands>
1: (694) LaunchOptions        <Command IgnoreFailures='false' Description=''>-environment-cd C:\Users\jgree\Projects\VoboNode_vsc_nucleo_f411RE\VoBoNode\BUILD\MTS_MDOT_F411RE\GCC_ARM-DEBUG\</Command>
1: (695) LaunchOptions        <Command IgnoreFailures='false' Description='connect to target'>-target-select remote localhost:3333</Command>
1: (695) LaunchOptions        <Command IgnoreFailures='false' Description='load file'>-file-exec-and-symbols VoBoNode.elf</Command>
1: (695) LaunchOptions        <Command IgnoreFailures='false' Description=''>-interpreter-exec console "monitor endian little"</Command>
1: (695) LaunchOptions        <Command IgnoreFailures='false' Description=''>-interpreter-exec console "monitor reset"</Command>
1: (695) LaunchOptions        <Command IgnoreFailures='false' Description=''>-interpreter-exec console "monitor halt"</Command>
1: (695) LaunchOptions        <Command IgnoreFailures='false' Description=''>-interpreter-exec console "monitor arm semihosting enable"</Command>
1: (695) LaunchOptions        <Command IgnoreFailures='false' Description='flash target'>-target-download</Command>
1: (695) LaunchOptions    </SetupCommands>
1: (695) LaunchOptions</LocalLaunchOptions>
1: (837) Starting: "C:\openOCD\openocd-0.10.0\bin\openocd.exe" -f C:/OpenOCD/openocd-0.10.0/scripts/board/st_nucleo_f4.cfg -f C:/OpenOCD/openocd-0.10.0/scripts/interface/stlink-v2-1.cfg -c init -c "reset init"
1: (1043) "C:\openOCD\openocd-0.10.0\bin\openocd.exe" exited with code 1 (0x1).
1: (1062) <-logout

For whatever reason, the openocd server session is not launching. I can compile (with mbed-cli) and launch both openocd and GDB servers from a command line so I am pretty sure my desktop is configured properly. Any ideas why openocd is not launching?

1 Answer

5 years, 6 months ago.

Hi, I had same issue. I not remmember full description of "exited with code 1 (0x1)" but it's error about correct path of server references

My tips:

First when you call directly a board config file like here

your cmdline output

DebugServerArgs='-f C:/OpenOCD/openocd-0.10.0/scripts/board/st_nucleo_f4.cfg -f C:/OpenOCD/openocd-0.10.0/scripts/interface/stlink-v2-1.cfg -c init -c "reset init"'

you not need call the stlink confing file, because in the board config file is set target device config and interface (stlink) config files. And I'm not sure you need whole patch of config files. So you can call...

my lauch.jason

"debugServerArgs": "-f board/st_nucleo_f4.cfg -c init -c \"reset init\"",

How you wrote

Quote:

I am pretty sure my desktop is configured properly.

Super, so open your lauch.json and copy your debugServerPath and debugServerArgs strings and put it together. Your string will probably look like...

"C:\openOCD\openocd-0.10.0\bin\openocd.exe" -f C:/OpenOCD/openocd-0.10.0/scripts/board/st_nucleo_f4.cfg -f C:/OpenOCD/openocd-0.10.0/scripts/interface/stlink-v2-1.cfg -c init -c "reset init" 

Put this string into the cmdline and it must run. If not your debugServer settings from lauch.jason are wrong.

my lauch.jason

….
"debugServerArgs": "-f board/st_nucleo_f4.cfg -c init -c \"reset init\"",
….
"debugServerPath": "C:/Program Files (x86)/openocd/bin-x64/openocd64.exe",
….

together and working in cmdline

"C:/Program Files (x86)/openocd/bin-x64/openocd64.exe" -f board/st_nucleo_f4.cfg -c init -c \"reset init\"

And in the task.jason file exist row with "args": ["-j"] rewrite to "args": ["All"]

Sorry for my bad english and good luck

Accepted Answer

Thanks, Jan. Your English is fine. And your guidance is spot on. I had addressed the configuration/json setup issues you highlight, though, prior to asking the question (apologies as I should have made that a little clearer). The problem I was experiencing appears to have been something to do with content from previous builds being present in the location the VS Code build looks for to load for debugging. Deleting the entire folder and allowing VS Code to repopulate it through a new build resolved the openOCD error. And now the build works even if I don't delete the contents from previous builds. Not entirely sure why this worked but it did.

Thanks again for your feedbak/response.

posted by John Greene 16 Oct 2018