VS Code Setup - USCRPL/mbed-cmake GitHub Wiki
mbed-cmake and Visual Studio Code make a solid pair, and provide an editing experience equal to or better than Mbed's own IDE for zero dollars down.
Opening the Project
- Make sure the "C/C++", "CMake Tools", "Native Debug", and "CMake" extensions are installed.
- In VS Code, go to File > Open Workspace and select your project folder.
- Optional: Set up your CMake options. You can do this through cmake.configureSettings in settings.json. However, if your project supports multiple targets, you will need to handle this using a CMake variants file. Here's one I wrote for my project with three boards:
buildType:
default: RelWithDebInfo
choices:
RelWithDebInfo:
short: RelWithDebInfo
long: Emit debug information but also optimize
buildType: RelWithDebInfo
debug:
short: debug
long: Emit debug information and don't optimize
buildType: Debug
release:
short: Release
long: Optimize generated code
buildType: Release
board:
default: GroundStationV1
choices:
GroundStationV1:
short: GroundStationV1
settings:
TARGET: GroundStationV1
GroundStationV2:
short: GroundStationV2
settings:
TARGET: GroundStationV2
TransponderV1:
short: TransponderV1
setting:
TARGET: TransponderV1
- Select your kit. Click on the bottom bar where it says "No Kit Selected". Choose "[Unspecified]" from the menu (the Mbed build scripts will find the compilers).
- Select your variant. Use Ctrl-Shift-P and find
CMake: Select Variant
. Then choose the variant you want.
NOTE: if you change variants later, you must do a full rebuild of your project (CMake: Delete Cache and Reconfigure
) or build flags may be wrong.
- The project should now configure.
- If there's a popup asking if CMake should provide IntelliSense information, say yes!
- Done!
Building and Flashing
- Select your target. Use Ctrl-Shift-P and find
CMake: Set Build Target
. Then, choose the target you want from the list. Just like on the command line, targets starting withflash-
flash a program to your Mbed board, while others just build the code. - Start a build, either by pressing the Build button on the bottom toolbar or by pressing F7. The code should compile!
Debugging
As of mbed-cmake 1.6.0, if you have selected a configuration that supports debugging, mbed-cmake will auto-generate a launch.json that will configure VS Code for debugging. To access debugging, first build the gdbserver target. Then, while it's running, go to the Run pane on the left, select your target at the top, then click the play button to start debugging.