Skip to content

Advanced features

Automatic IntelliSense configuration

The extension is able to automatically configure IntelliSense in the C/C++ for Visual Studio Code extension. The configuration is inferred by matching the current file in the editor to the build configuration and source tree it belongs to. The extension parses the build configuration, collects all the relevant compiler options, and configures IntelliSense for the current file.

Source files that are shared by different build configurations can be opened simultaneously. This is due to the structure and dependencies of an application source tree and the fact that you can work with multiple applications and build configurations in your workspace, for example nRF Connect SDK source files. In such cases, the extension tries to match the compiler options to the selected active application and build configuration.

If your settings contain C/C++ extension (C_Cpp.defaults.*) configurations, these might conflict or override the auto-configured settings. To check which settings are applied, use the C/C++: Log Diagnostics command from the Command Palette.

Custom launch and debug configurations

The nrf-connect debug configuration type wraps the Cortex-Debug extension, which sets up the required configuration parameters for the selected build configuration. The debug configuration type accepts all parameters supported by Cortex-Debug, so you can tweak the configuration for your specific setup.

To use the nRF Connect debug configuration:

  1. Open the Run menu in the top level menu bar.
  2. Click Add configuration... and choose nRF Connect.

Alternatively, click the cogwheel icon in the top of the VS Code Debug sidebar view and add a debug configuration with the nrf-connect type.

The following example shows a launch.json file using the nrf-connect debug type.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "nrf-connect",
            "request": "launch",
            "name": "Launch active build configuration",
            "config": "${activeConfig}",
            "runToEntryPoint": "main",
            "preLaunchTask": "nRF Connect: Build active configuration"
        },
        {
            "name": "Launch build_nrf52840dk_nrf52840",
            "type": "nrf-connect",
            "request": "launch",
            "config": "c:\\Users\\joe\\workspace\\apps\\hello_world\\build_nrf52840",
            "runToEntryPoint": "main"
        }
    ]
}

Custom task configurations

The extension provides its own task and debug configuration types.

The nrf-connect-build and nrf-connect-flash task types can be used for building and flashing a build configuration, respectively. The following task.json file shows the custom types with some of the accepted parameters.

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "nrf-connect-build",
            "config": "${workspaceFolder:hello_world}\\build_nrf52840",
            "runCmake": false,
            "problemMatcher": [
                "$gcc",
                "$cmake",
                "$kconfig",
                "$kconfig_syntax",
                "$kconfig_syntax_files",
                "$dts",
                "$dts_syntax"
            ],
            "group": "build",
            "label": "nRF Connect: Build build_nrf52840 (active)"
        },
        {
            "type": "nrf-connect-flash",
            "config": "${workspaceFolder:hello_world}\\build_nrf52840",
            "snr": "683888634",
            "erase": false,
            "problemMatcher": [],
            "label": "nRF Connect: Flash build_nrf52840 (active)"
        }
    ]
}

Bind Task to Action

Custom tasks can be bound to the Build and Flash actions. When bound, these tasks will run instead of the standard Build and Flash commands. This is useful if you want to run a custom script that hooks into your own build system, or that performs pre- or postprocessing steps.

To bind a task to an action, right-click on Build or Flash from the Actions panel, and then click on Bind Task to Action.

Binding two custom tasks to an action

You can manually create task bindings in the settings file by referencing the tasks defined in the correct tasks.json file. You can read more about how this works and how to configure tasks in the correct file in the Manually adding and customizing tasks section of this page.

Once you have bound tasks to an action, view them by hovering your mouse over Build or Flash, whichever you have bound the task to, and they will appear in the help text.

Note

Bindings only apply to the primary Build and Flash commands. They do not apply to the actions Build All or Erase and Flash.

Unbinding tasks

To unbind tasks from an action, right-click on Build or Flash and then click Remove Task Binding. If multiple tasks are bound, select which one you wish to remove.

Manually adding and customizing tasks

Bound tasks can be defined in several locations, depending on the structure of your workspace. If your project consists of a single folder, add them to the .vscode/tasks.json file. If you are working with multiple folders that open in a single workspace, define them under the tasks key in your workspace file. For more information on where tasks should be defined and the format they should take, visit the VS Code tasks documentation.

Bindings can be created using the interface mentioned in the section above Bind Task to Action. Bindings created through the interface are stored in the nrf-connect.taskBindings property of your settings.json file. This property can also be modified manually, which can be easier if you have many bindings or a complicated setup.

Single task example

For example, if you have a tasks.json file that look like the example below, and only one task you would like bind to an action:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "My custom flash",
            "command": "${workspaceFolder}/my-flash-script.sh",
            "args": ["--build", "--erase", "--nrf52"],
            "presentation": {
                "echo": true,
                "reveal": "never",
                "clear": true
            }
        }
    ]
}

By adding the following to the nrf-connect.taskBindings configuration options, the My custom flash task will be executed whenever the Build action is run:

{
    "nrf-connect.taskBindings": {
        "build": [{ "taskName": "My custom flash" }]
    }
}

Tasks are matched by their label attribute. If a task is referenced in the configuration but is not defined in the tasks.json file or contributed by an extension, a warning message appears until the binding is removed.

Task bindings can also be restricted to a given build configuration or a set of build configurations. For example:

{
    "nrf-connect.taskBindings": {
    "flash": [
      {
        "taskName": "My custom flash",
        "buildConfigs": [
          "build",
          "${workspaceFolder}/hello_world/build_1"
          "${workspaceFolder}/samples/bluetooth/perihperal_hids/build",
        ]
      }
    ]
  }
}

With this configuration, the My custom flash task will only be executed if the path of the active build matches the one that is listed in the buildConfigs property.

Note

The buildConfigs property is optional. If this property is not defined, then the binding will apply to all configurations.

Multiple tasks example

Multiple tasks can be bound to a build configuration. For example:

{
    "nrf-connect.taskBindings": {
        "build": [
            { "taskName": "My custom build" },
            { "taskName": "Staging build", "buildConfigs": ["build"] },
            { "taskName": "Release build", "buildConfigs": ["build"] },
        ]
    }
}

In this instance, three tasks have been bound to the build build configuration. The My custom build task was bound implicitly since no builds were declared in the binding, and the remaining two were bound by explicitly naming the build build configuration. When multiple tasks are bound, you will be given a choice of which to execute when you run the action.

nRF Connect terminal profile

The extension includes an nRF Connect terminal profile that is configured to work with west and the rest of the nRF Connect Toolchain and nRF Connect SDK environment.

To access the terminal profile:

  1. Click the Launch Profile... drop-down list (the plus sign icon) located in the terminal view.
  2. Click on the icon and choose nRF Connect from the list.

Alternatively, run the nRF Connect: Create Shell Terminal command to access the terminal profile.

The version of the nRF Connect SDK used depends on the value of the nrf-connect.toolchain.path setting at the time the terminal is created. Changes to this value are not picked up by existing terminal instances, and you need to create a new terminal to use the new environment.

All changes to the terminal environment are limited to this profile, so the default integrated terminal profile works as before.

nRF Connect Toolchain path resolution

The extension resolves paths to the build tools, such as west or cmake, using the nrf-connect.toolchain.path setting. These paths are then set in the PATH environment variable in the environment that is used to call west for actions such as building or flashing.

To allow for this, the CMake NCS_TOOLCHAIN_VERSION variable is set to NONE when calling west. This instructs the build system to look for the necessary tools on PATH rather than resolve the paths internally.

When pasting command line invocations of west from the integrated terminal to an external terminal, make sure that the tools available on PATH in the external terminal are the same as the tools indicated by nrf-connect.toolchain.path.

Creating device aliases

The extension supports creating names or aliases for connected devices so that you do not have to remember their serial numbers to interact with them.

To create a device alias:

  1. Right-click on the device in the Connected Devices panel.
  2. Choose Rename Device.

To remove a device alias:

  1. Right-click on the device.
  2. Choose Remove Device Alias.

In the example below, the device was renamed to the alias "Light Switch".

Connected Devices panel with device aliased to "Light Switch"

If you have created aliases using nRF Connect for Desktop, then the extension uses those and reads and writes to the same configuration file. If that configuration file does not exist, then aliases are remembered by the extension. Aliases in the configuration file take precedence over aliases in the extension memory.

Application-specific flash options

If required, applications can be configured with specific flash options. These options will be applied to all flash commands run through the UI that target that application.

The available options are as follows:

  • softreset - if true, it applies the --softreset argument using reset instead of pin reset.
  • skipBuild - if true, it skips the build step before flashing to the device.

To apply these options, open your VS Code settings.json file and create the following entry, customizing it to your needs:

{
    "nrf-connect.applicationOptions": {
        "/path/to/your/application": {
            "flash": {
                "softreset": true,
                "skipBuild": true
            }
        }
    }
}
Back to top