This week, I learned about Cortex-Debug extension for VS Code. It sounded pretty cool to run GDB and ITM within the context of VSCode. So, I tried it out and found it awesome.

With this extension, I can easily start a debug session with just a click on a button. The graphical front end is really nice. No more opening up separate terminal windows for GDB and ITM. It was like a scenery opening up before my eyes after a long tedious hike. The view is very different from here.

Configuration

Installation was extremely easy. And configuration was not bad either. Since I generated my project with cortex-m-quickstart, the default setting was pretty much all I needed for my Discovery board.

The cortex-m-quickstart template has a folder called .vscode that should look like this:

.vscode
  - extensions.json
  - launch.json
  - tasks.json

We modify launch.json to configure debug features.

Parameters

Here is a list of parameters in launch.json. Configure them for your specific device and environment.

  • "cwd": Path of project
  • "configFiles": OpenOCD configuration file(s) to load
  • "device": Target Device Identifier
  • "interface": Debug Interface type to use for connections (defaults to SWD) - Used for J-Link and BMP probes.
  • "name": Name of configuration; appears in the launch configuration dropdown menu.
  • "preLaunchTask": Task to run before debug session starts. Specify a task defined in tasks.json.
  • "request": Request type of configuration. Can be “launch” or “attach”.
  • "runToMain": If enabled the debugger will run until it the start of the main function.
  • "serialNumber": J-Link specific parameter. J-Link Serial Number - only needed if multiple J-Links are connected to the computer
  • "servertype": GDB Server type - supported types are jlink, openocd, pyocd, pe and stutil
  • "svdFile": Path to an SVD file describing the peripherals of the microcontroller; if not supplied then one may be selected based upon the ‘device’ entered. This may be automatically loaded depending on the "device".
  • "swoConfig": SWO/ITM configuration.
    • "enabled": Enable SWO decoding.
    • "cpuFrequency": Target CPU frequency in Hz.
    • "swoFrequency": SWO frequency in Hz.
    • "source": Source for SWO data. Can either be “probe” to get directly from debug probe, or a serial port device to use a serial port external to the debug probe.
    • "decoders": SWO Decoder Configuration
      • "label": A label for the output window.
      • "port": ITM Port Number

Example 1: Discovery Board / OpenOCD

Here is a configuration for my Discovery board. This is basically cortex-m-quickstart’s default setting.

Out of curiosity, I upgraded Nucleo-F429’s STLink firmware to JLink. So, for my Nucleo with the J-Link firmware, I changed set "servertype" to "jlink" and "interface" to "swd".