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

Assumptions:
  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:
    Code:
    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”.
Steps:
In case of OpenOCD webpage would be out of service, below is a screenshot:
01_OpenOCD_manuall_installation.png


Add “arm-none-eabi-gdb.exe” from STM32CudeIDE to the PATH:
C:\STMicroelectronics\STM32CubeIDE_1.3.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.7-2018-q2-update.win32_1.0.0.201904181610\tools\bin

Add OpenOCD to the PATH:
C:\Users\defUser\AppData\Roaming\xPacks\OpenOCD\0.10.0-14\bin
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:
C:\STMicroelectronics\STM32CubeIDE_1.3.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.debug.openocd_1.3.0.202002181050\resources\openocd\st_scripts\target
to:
C:\Users\defUser\AppData\Roaming\xPacks\OpenOCD\0.10.0-14\scripts\target
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”:
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": [
        "${workspaceFolder}/path/to/Debug.cfg"
      ],
      "svdFile":
      "C:/STMicroelectronics/STM32CubeIDE_1.3.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.productdb.debug_1.3.0.202002181050/resources/cmsis/STMicroelectronics_CMSIS_SVD/STM32L0x1.svd"
    }
  ]
}
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! :)

Comments

There are no comments to display.

Part and Inventory Search

Blog entry information

Author
niciki
Views
88
Last update

More entries in Uncategorized

More entries from niciki

Top