6 years, 5 months ago.

How to get vscode debugging working with openocd?

Hey,

I have a STM32 NUCLEO F429ZI that I would like to debug via vscode. I've managed to get openocd working with the board (required a slightly modified config file, with increased WORKAREASIZE), and I can debug a program via `arm-none-eabi-gdb`. However, when following the guide at https://docs.mbed.com/docs/mbed-os-handbook/en/latest/debugging/vscode/ I can't get it to work.

OS: Ubuntu 16.04 MBed OS: 5.6.2 gcc/gdb - 6-2017-q2 Program: https://github.com/ARMmbed/mbed-os-example-blinky updated to mbed-os @ 6e0d01cd13e8aca7bf4d697c3699ec9225386881

launch.json config - https://pastebin.com/1x5LhS3S

Log from vscode debug console - https://pastebin.com/h64rxqd4

6 Answers

6 years, 3 months ago.

The VS CODE MBED extension version 0.2.0 code will not work on a Window platform. The Java Script code which implements the extent Windows ension contains UNIX specific commands One will see a Warning message that the mbed is not installed in the VSCode Header Status bar If one views the console log In VScode click on the Help Menu Item and selected Toggle Developer Tools on the drop down menu, Select the Console Tab in the tool's window, One see a message " which failed to find mbed executable" The mbed cli installer puts the mbed executable file in c:/Payton2.7/scripts The problem is "which" is a UNIX only command. The equivalent Windows command is "where" I modified the script to use where when running on Windows and VS CODE not longer thinks the mbed-cli is not installed.

however the script still crashes when one clicks the compile button

VS Code Widnow show compile code message and nothing more Console Log show Node.js crashing the script's attempt to spawn the mbed executable with EONENT error

I know that now. I wrote (4.12.2017) to semonec, probably owner/creator of the VSCode Mbed extenstion, about this extension not working me. His aswer was "Sorry for that. If you are running it on Windows, then It'll not work correctly. Current version (0.2.0) of that is works only Mac OSX. And I'm updating it with new features. After update done, please use that again.". We will seen in the future.

Best regards J.

posted by Jan Kamidra 19 Dec 2017
6 years, 3 months ago.

Hello,

On a Windows 7 (or Windows 10) system you could try the following :

  • Download and install OpenOCD onto your Windows system as explained here.
  • Notice the path to the OpenOCD folder. You will need it later.
  • Install Visual Studio Code IDE according to the tutorial.
  • Export a project from the online compiler as described in the tutorial.
  • Open the project's folder in VS Code as per the tutorial.
  • If it doesn't exist yet, create a new .vscode folder in the project using VS Code.
  • Copy the tasks.json and launch.json files to the .vscode folder using VS Code.
  • To ensure that debug information will be generated, open the Makefile in VS Code and append '-O0' '-g' at the end of line CPP = 'arm-none-eabi-g++' '-std=gnu++98' ... '-mthumb', so it becomes
    CPP = 'arm-none-eabi-g++' '-std=gnu++98' ... '-mthumb' '-O0' '-g'
  • Open the BUILD folder and delete the .elf file if any.
  • In the Tasks menu select Run Build Task...
  • Open the launch.json file located in the .vscode folder and replace the Windows section with the following one:

            "windows": {
                "preLaunchTask": "make.exe",
                "MIMode": "gdb",
                "MIDebuggerPath": "D:/mcu/arm/gcc-arm/bin/arm-none-eabi-gdb.exe",
                "setupCommands": [
                    { "text": "-environment-cd ${workspaceRoot}/BUILD" },
                    { "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
                    { "text": "-file-exec-and-symbols ${workspaceRootFolderName}.elf", "description": "load file", "ignoreFailures": false},
                    { "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
                    { "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
                    { "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
                    { "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
                    { "text": "-target-download", "description": "flash target", "ignoreFailures": false },
                    { "text": "-environment-cd ${workspaceRoot}" }
                ]
            }
  • Update the MIDebuggerPath according to the actual location of the arm-none-eabi-gdb.exe file on your system and save the file.
  • In a folder of your choice create .bat files for your target boards (e.g. NUCLEO-F103RB.bat, NUCLEO-F446RE.bat ... etc.).
  • For example, depending on the location of the OpenOCD folder (see step two) the NUCLEO-F446RE.bat would contain the following text: cmd /k openocd.exe -s D:\mcu\arm\OpenOCD\scripts -f D:\mcu\arm\OpenOCD\scripts\board\st_nucleo_f4.cfg
  • Connect your target board over USB cable to your PC.
  • Run the batch file you have created in the previous step for the connected target board (e.g. NUCLEO-F446RE.bat), for example by double clicking on it the File Explorer.
  • Go back to VS Code IDE and open the main.cpp file.
  • Finally, in the Debug menu select Start Debugging.
  • Once you finish debugging remember to close the OpenOCD server's Command prompt window.

You can apply a similar approach (OpenOCD server batch files for target boards) also on a Linux or Mac system.

Happy debugging :)

6 years, 3 months ago.

This is how I do it on ODIN-W2 board with OpenOCD: https://os.mbed.com/users/janjongboom/notebook/debugging-ublox_evk_odin_w2-with-openocd-and-visua/#

6 years, 2 months ago.

Another easy way for debugging is to use gdb with split view via "enable tui"

6 years, 4 months ago.

Hi,

do you have any solution? I have same Issue.

I follow these guides: https://os.mbed.com/docs/v5.6/tutorials/visual-studio-code.html https://os.mbed.com/docs/v5.6/tools/setting-up-a-local-debug-toolchain.html pyOCD probably does not support my boards (I have Nucleo's F767ZI and F446RE.). OpenOCD can't run cuz of in downloaded (tutorial link) OpenOCD 0.10.0 folders not exist folder "bin" and executable openocd.exe. I do not know how to do...

Later I tried VSCode with Mbed extension (I do not know who made it) but after call Mbed new and after 1 hour of waiting still only... output: > Running `mbed new Test_project`...

Later tried SW4STM32 with.. http://www.openstm32.org/Importing%2Ban%2Bmbed%2Bprogram and now problem with different folders in guide and in real Mbed exported files.

I am confused... I need guide for idiots and google can't help me :)

J.

6 years, 4 months ago.

This may be help.


https://os.mbed.com/users/MACRUM/notebook/how-to-setup-vscode-debugging-for--stm32-platforms/

Hi, first I want to thank you for your time. I tried to follow you instruction step by step and i achieve better result but still not working me.

Make.exe in debugging/compiling proces return error 1 many times and compiling ending with "make.exe: * [all] Error 2"

But when I run 3 times around... "===== bin file ready to flash: BUILD/mbed-os-example-blinky.bin =====" and debug console running but end with "1: (219) "C:\Program Files (x86)\OpenOCD\bin\openocd.exe" exited with code 1 (0x1)."

Edit:

Solved...

OpenOCD download from here http://www.freddiechopin.info/en/download/category/4-openocd

I tested all in cmd.exe and all work well but in VSCode not. In task.json "args": ["-j"] change to "ALL". This eliminate 3 times compiling and eliminate error code 1 and 2. But still not work. I found problem in launch.json. I copy paste the path but spaces was broken. The path of commands for OpenOCD looked like "C:\ProgramáFilesá(x86)..." in VSCode terminal and in launch.json looked normal.

posted by Jan Kamidra 26 Nov 2017