Mistake on this page?
Submit a change in GitHub or email us

Visual Studio Code

This document explains how to build and debug Arm Mbed OS applications using Visual Studio Code. Before starting, first configure your local debug toolchain.

Installing Visual Studio Code

You need to install Visual Studio Code with the C/C++ extensions to begin.

  1. Install Visual Studio Code.

  2. Open Visual Studio Code, and click on the Extensions button.

  3. Search for the C/C++ plugin (by Microsoft) and click Install.

    Installing the C/C++ plugin in Visual Studio Code

  4. When prompted, restart the IDE.

Exporting a project

To export your project to Visual Studio Code, you can use either the Online Compiler or Arm Mbed CLI.

Online Compiler

  1. Right click on your project.

  2. Select Export Program....

  3. Under Export toolchain, select Visual Studio Code (GCC ARM).

    Tip: For most targets, you can also export to IAR or ARMCC.

  4. Click Export, and unpack at a convenient location.

    Exporting to Visual Studio Code

Arm Mbed CLI

In your project folder, run:

# alternatively, use -i vscode_armc5 for ARMCC, or -i vscode_iar for IAR
# replace K64F with your target board

$ mbed export -i vscode_gcc_arm -m K64F --profile mbed-os/tools/profiles/debug.json

Configuring the debugger

To configure the debugger for your project:

  1. Open the folder in Visual Studio Code.

  2. Open the .vscode/launch.json file.

  3. If you're using pyOCD as your debug server, verify that debugServerPath is set to the location of pyocd-gdbserver.

  4. If you're using OpenOCD as your debug server:

    1. Change debugServerPath to point to the location of openocd.
    2. Change debugServerArgs to include your OpenOCD arguments. For more info, read our toolchain document.

    Configuring the debugger

Note: If you installed the GNU Arm Embedded Toolchain in a nondefault location (for example, through the Arm Mbed CLI installer), you need to update the MIDebuggerPath to the full path of your copy of arm-none-eabi-gdb. To find the new path, open a terminal, and run where arm-none-eabi-gdb (Windows) or which arm-none-eabi-gdb (macOS and Linux).

Debugging your project

  1. On the Debug tab, click the Play icon.

    Starting the debug session

  2. The project builds, and debugging starts when the build succeeds.

  3. To see warnings or errors, select View > Problems.

  4. Click on the Debug Console button to see the debug output (this is not activated automatically).

    Running the debugger

Tip: You can use the Debug Console to interact with the device over GDB and use functionality the UI does not expose. For example, to see the registers, type -exec info registers. To put a watch on a memory location, type -exec watch *0xdeadbeef.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.