Cortex-Debug for Visual Studio Code
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 intasks.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.
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "cortex-debug", | |
"request": "launch", | |
"name": "Debug (OpenOCD)", | |
"servertype": "openocd", | |
"cwd": "${workspaceRoot}", | |
"preLaunchTask": "cargo build", | |
"runToMain": true, | |
"executable": "./target/thumbv7em-none-eabihf/debug/project-name", | |
"device": "STM32F303VCT6", | |
"configFiles": [ | |
"interface/stlink-v2-1.cfg", | |
"target/stm32f3x.cfg" | |
], | |
"svdFile": "${workspaceRoot}/.vscode/STM32F303.svd", | |
"swoConfig": { | |
"enabled": true, | |
"cpuFrequency": 8000000, | |
"swoFrequency": 2000000, | |
"source": "probe", | |
"decoders": [ | |
{ "type": "console", "label": "ITM", "port": 0 } | |
] | |
} | |
} | |
] | |
} |
Example 2: Nucleo-F429ZI Board / J-Link
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"
.
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "cortex-debug", | |
"request": "launch", | |
"name": "Debug (J-Link)", | |
"cwd": "${workspaceRoot}", | |
"executable": "./target/thumbv7em-none-eabihf/debug/project-name", | |
"servertype": "jlink", | |
"device": "STM32F429ZI", | |
"interface": "swd", | |
"serialNumber": "", | |
"preLaunchTask": "cargo build", | |
"runToMain": true, | |
"svdFile": "${workspaceRoot}/.vscode/STM32F429.svd", | |
"swoConfig": { | |
"enabled": true, | |
"cpuFrequency": 8000000, | |
"swoFrequency": 2000000, | |
"source": "probe", | |
"decoders": [ | |
{ "type": "console", "label": "ITM", "port": 0 } | |
] | |
} | |
}, | |
] | |
} |