Continue to Site

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's STM32 project in VSCode?

Assumptions:
  1. STM32CubeIDE needs to be installed. At the time of writing this guide, STM32CubeIDE version is 1.6.1 Build: 9958_20210326_1446 (UTC).
    OpenOCD and GDB server are already preinstalled in STM32CubeIDE, so no need to install separately;
  2. Keil's .uvprojx project needs to be built to .elf file (generated from .axf file);
    Used command:
    Code:
    fromelf.exe example_in.axf --elf --output example_out.elf"
  3. VSCode has plugins: “C/C++” and “Cortex-Debug”.
Steps:
Generate the STM32CubeIDE project for your MCU to get Debug Configuration File for OpenOCD.
To do that, follow [Debug][Keil][STM32CubeIDE] How to debug Keil's STM32 project in STM32CubeIDE? (Part 1)

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


NOTE: If you are missing "Open with Code" option in Context Menu, then reinstall VSCode and make sure that you have checked these options:
1620337306019.png


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”.
1621989263769.png

1621989284564.png


Copy-paste the following template to the newly created “launch.json”:
JSON:
{
  "version": "0.2.0",
  "trace": true,
  "configurations": [
    {
      "name": "Debug stm32 template",
      "type": "cortex-debug",
      "request": "launch",
      "servertype": "openocd",
      "device": "not required to specify here",
      "executable": "${workspaceFolder}/relative/path/to/elf/file.elf",
      "gdbPath": "absolute/path/to/arm-none-eabi-gdb.exe",            // it is required, only if not in PATH
      "serverpath": "absolute/path/to/openocd.exe",                   // it is required, only if not in PATH
      "cwd": "${workspaceRoot}/relative/path/to/dir/with/uvprojx/or/uvproj/project/file/dir",
      "configFiles": [
        "${workspaceFolder}/relative/path/to/generated/in/STM32CubeIDE/debug/configuration/file_Debug.cfg"
      ],
      "searchDir": [
        "absolute/path/to/openocd/st_scripts",
        "or/absolute/path/to/openocd/scripts/with/board/interface/and/target/inside"
      ]
    }
  ]
}

Mine “launch.json” looks as follows:
JSON:
{
  "version": "0.2.0",
  "trace": true,
  "configurations": [
    {
      "name": "Debug stm32",
      "type": "cortex-debug",
      "request": "launch",
      "servertype": "openocd",
      "device": "not required to specify here",
      "executable": "${workspaceFolder}/ci_tmp/[DBG]_UC_PRODUCT_APP/[DBG]_UC_PRODUCT_APP.elf",
      "gdbPath": "C:/ST/STM32CubeIDE_1.6.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924/tools/bin/arm-none-eabi-gdb.exe",
      "serverpath": "C:/ST/STM32CubeIDE_1.6.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.openocd.win32_1.6.0.202101291314/tools/bin/openocd.exe",
      "cwd": "${workspaceRoot}/Projects/MDK-ARM",
      "configFiles": [
        "${workspaceFolder}/Application/project_CubeMX/CubeMX_UC_PRODUCT_APP/CubeMX_UC_PRODUCT_APP_Debug.cfg"
      ],
      "searchDir": [
        "C:/ST/STM32CubeIDE_1.6.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.debug.openocd_1.6.0.202102111023/resources/openocd/st_scripts"
      ]
    }
  ]
}

Hit F5 in VSCode (which corresponds to “Menu->Run->Start Debugging”) and start debugging in VSCode!
1621988962129.png

1621988987618.png

1621989042875.png

1621989085018.png


Hope it was helpful for someone there.

------------------------------------------------------
Is this blog entry helpful or does it need an improvement?
Please leave the comment below.

Comments

There are no comments to display.

Part and Inventory Search

Blog entry information

Author
niciki
Read time
2 min read
Views
5,720
Last update

More entries in Uncategorized

More entries from niciki

Share this entry

Back
Top