Skip to content

Instantly share code, notes, and snippets.

@arnabanimesh
Created August 26, 2020 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnabanimesh/451912da8b043d01f42a78f60b617e4f to your computer and use it in GitHub Desktop.
Save arnabanimesh/451912da8b043d01f42a78f60b617e4f to your computer and use it in GitHub Desktop.
Cargo tasks in vscode

Source Repository

VS Code Configuration

Example configuration for debugging programs in-editor with VS Code.

Required Extensions

If you have the code command in your path, you can run the following commands to install the necessary extensions.

code --install-extension rust-lang.rust
code --install-extension marus25.cortex-debug

Otherwise, you can use the Extensions view to search for and install them, or go directly to their marketplace pages and click the "Install" button.

Use

Note: When you open the project in the editor, you must open an *.rs file to trigger the Rust Language Server. Failure to do so will cause a failure to find the build task.

The Debug (OpenOCD): Starts a debug session for a STM32F3DISCOVERY board. It will use the default .cargo/config configuration to build the executable, upload it to the device, and start a debug session.

ITM output, if used, will be written to the Output view SWO: ITM [port: 0, type: console] output.

Git

Files in the .vscode/ directory are .gitignored by default because many files that may end up in the .vscode/ directory should not be committed and shared.
However, a number of files are explicitly tracked, because they define complex debug configurations and should be shared with anyone cloning your project.

SVD File

The SVD file is a standard way of describing all registers and peripherals of an ARM Cortex-M mCU.
Cortex-Debug needs this file to display the current register values for the peripherals on the device.

For licensing reasons, we're unable to include the SVD file in the quickstart repository, but it can be downloaded from the ST's Website.

Download the stm32f3 SVD pack, and copy the STM32F303.svd file into ~/.svd/.
This line of the config tells the Cortex-Debug plug in where to find the file.

"svdFile": "${env:HOME}/.svd/STM32F303.svd",

Personally, I like keeping them in my home directory so I don't have to keep multiple copies of the SVD on disk, but you could also keep the file under .vscode/ if you have a private project where there are no licensing concerns around the SVD file.

"svdFile": "${workspaceRoot}/.vscode/STM32F303.svd",

CPU Frequency

If your device is running at a frequency other than the default 8MHz, you'll need to modify this line of launch.json for the ITM output to work correctly.

"cpuFrequency": 8000000,
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"rust-lang.rust",
"marus25.cortex-debug",
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [
]
}
{
/*
* Requires the Rust Language Server (RLS) and Cortex-Debug extensions
* https://marketplace.visualstudio.com/items?itemName=rust-lang.rust
* https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug
*/
"version": "0.2.0",
"configurations": [
{
/* Launches debug session for currently open example */
"type": "cortex-debug",
"request": "launch",
"name": "Debug Example",
"servertype": "openocd",
"cwd": "${workspaceRoot}",
"preLaunchTask": "cargo build --examples",
"runToMain": true,
"executable": "./target/thumbv7em-none-eabihf/debug/examples/${fileBasenameNoExtension}",
"preLaunchCommands": ["break rust_begin_unwind"],
"device": "STM32F303VCT6",
"configFiles": [
"interface/stlink-v2-1.cfg",
"target/stm32f3x.cfg"
],
"svdFile": "${env:HOME}/.svd/STM32F303.svd",
"swoConfig": {
"enabled": true,
"cpuFrequency": 8000000,
"swoFrequency": 2000000,
"source": "probe",
"decoders": [
{ "type": "console", "label": "ITM", "port": 0 }
]
}
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
/*
* This is the default cargo build task,
* but we need to provide a label for it,
* so we can invoke it from the debug launcher.
*/
"label": "cargo build",
"type": "cargo",
"subcommand": "build",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "cargo build --release",
"type": "process",
"command": "cargo",
"args": ["build", "--release"],
"problemMatcher": [
"$rustc"
],
"group": "build"
},
{
"label": "cargo build --examples",
"type": "process",
"command": "cargo",
"args": ["build","--examples"],
"problemMatcher": [
"$rustc"
],
"group": "build"
},
{
"label": "cargo build --examples --release",
"type": "process",
"command": "cargo",
"args": ["build","--examples", "--release"],
"problemMatcher": [
"$rustc"
],
"group": "build"
},
{
"label": "cargo clean",
"type": "cargo",
"subcommand": "clean",
"group": "build"
},
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment