Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Debug][Keil][VSCode] How to debug Keil project in VSCode

  1. At the time of writing this guide, STM32CubeIDE version was 1.3.0 and OpenOCD version was 0.10.0-14.
  2. Keil's .uvprojx project is built to .elf file (generated from .axf file). Used command:
    fromelf.exe file_in.axf --elf --output file_out.elf"
  3. STM32CubeIDE is installed (GDB server is in STM32CubeIDE, so no need to install separately) - Version: 1.3.0, Build: 5720_20200220_1053 (UTC).
  4. OpenOCD is installed in “C:\Users\user\AppData\Roaming\xPacks\OpenOCD\0.10.0-14” from https://github.com/xpack-dev-tools/openocd-xpack/releases/ and according to guide: https://xpack.github.io/openocd/install/#windows_1
  5. VSCode has plugins: “C/C++” and “Cortex-Debug”.
In case of OpenOCD webpage would be out of service, below is a screenshot:

Add “arm-none-eabi-gdb.exe” from STM32CudeIDE to the PATH:

Add OpenOCD to the PATH:
NOTE: After changing PATH sometimes close/open VSCode is sufficient, but sometimes logout/login to the Windows is needed.

Generate the STM32CubeIDE project for your uC to get “Debug.cfg” file for OpenOCD.
The beginning of this file is as follows:
# This is an genericBoard board with a single STM32L041G6UxS chip
# Generated by STM32CubeIDE
# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch
configuration setup(s)
source [find interface/stlink.cfg]
Copy that “Debug.cfg” file to your Keil's Project location.

Copy missing (NOT ALL, BUT ONLY MISSING!) uC target .cfg files from:
NOTE: The reason for copying is that VSCode uses preconfigured folder path “../scripts” not “../st_scripts” for searching path. That is the only reason for installing OpenOCD separately.

Open Keil's Project location by “Open with Code” integrated menu in Windows - the place where you have /Src, /Inc, etc.

Create “launch.json” file by hitting F1 in VSCode (which corresponds to “Menu->View->Command Palette”) and start typing “launch”.
Select “Debug: Open launch.json” and then select “Cortex Debug”.

Copy-paste the following to the “launch.json”:
  "trace": true,
  "configurations": [
      "cwd": "${workspaceFolder}",
      "executable": "${workspaceFolder}/path/to/file.elf",
      "name": "Debug stm32",
      "request": "launch",
      "type": "cortex-debug",
      "servertype": "openocd",
      "device": "STM32L041G6",
      "configFiles": [
NOTE: “device" and "svdFile" must be changed according to your uC. SvdFiles are deep in CubeIDE locations as presented. Find similar .svd file for your uC.

Hit F5 in VSCode (which corresponds to “Menu->Run->Start Debugging”)

Start debugging in VSCode! :)


There are no comments to display.

Part and Inventory Search

Blog entry information

Last update

More entries in Uncategorized

More entries from niciki