For a few months I’m learning and using Rust. I’m still learning, but I’m very impressed by the powerful and cool programming language, the vibrant ecosystem, the advanced concepts behind it and by the tools. With learning Rust I have been using the Visual Studio Code IDE and it works great for Rust. But I was wondering: could I use it for my ‘usual’ C/C++ development on ARM Cortex-M devices too? The answer is a clear ‘yes’, and this mini series of articles should get you up and running too.
Don’t get me wrong: Eclipse is a very mature and great IDE. But with its age and maturity it is not the most advanced IDE any more compared to technologies Microsoft provides with the Visual Studio (Enterprise or Community) edition which I’m mostly using for C# development. Don’t get confused with the Microsoft Visual Studio Code which is provided by Microsoft as freeware and Microsoft has published the source code under a MIT License, while it still contains some binaries built with a proprietary license.
In essence, Visual Studio Code is a very slick, fast and modern IDE with many cool plugins and helpers. It seems not so much used for embedded development, but this certainly might change over time. Getting started with Visual Studio Code and an embedded target can be difficult because there might be no dedicated support from the silicon vendors for it. But with a bit of learning and I hope with the help of this article series you should get up and running.
In this tutorial series I’m using the NXP K22FN512 (FRDM-K22 board), but you should be able to use any other NXP Kinetis or LPC device if supported by the NXP MCUXpresso SDK. I’m going to cover installation, first simple project, debugging it on the target, and finally extending it to a full SDK project and explore some of the advanced features.
So with this: If you don’t know Visual Studio Code, I invite you to a journey into a new world…
For this article I used the version 1.55.2 of Visual Studio Code. The installer is available from https://code.visualstudio.com/ and supports Windows, Mac and Linux:
After the installation, start the IDE:
At anytime I can update the IDE if there are updates available (I will get notifications too):
The IDE incorporates a terminal or console view, open a new one:
The Terminal and Console area is by default in the lower area but can be moved anywhere:
In comparison to other fully integrated IDEs, I have to install other packages in addition to the IDE: IDE extensions, the build tools (compiler, linker, libraries), Cmake and support for the debugger.
To install the IDE plugins, this can be done with the host shell command prompt or directly in the Terminal inside the IDE. To install extensions (aka Plugins in Eclipse) I use the following command format:
code --install-extension <code>
Or I can use in the IDE the menu View > Extensions.
To do embedded development for ARM Cortex-M, I recommend the following extensions:
- C/C++, ms-vscode.cpptools
- Cortex-Debug, marus25.cortex-debug
- CMake Tools, ms-vscode.cmake-tools
- CMake Syntax highlighting, twxs.cmake
- ARM Assembly highlighting, dan-c-underwood.arm
- Linker Script highlighting, zixuanwang.linkerscript
The first three are required, the other are optional but recommended.
The easiest way is to install them from the command prompt inside the IDE:
code --install-extension ms-vscode.cpptools code --install-extension marus25.cortex-debug code --install-extension twxs.cmake code --install-extension dan-c-underwood.arm code --install-extension zixuanwang.linkerscript
Below my installed extensions (menu File > Preferences > Extensions):
CMake can be downloaded and installed from https://cmake.org/download/
Install it with the defaults. I’m using v3.20.2.
Make or Ninja
I’m using both Make and Ninja with CMake. Both shall be present in the PATH so check if you have one already installed:
The installer for Make is available from https://www.gnu.org/software/make/
Ninja is available from https://github.com/ninja-build/ninja/releases. Install it where it is found by the system, I usually place it inside C:\Program Files\CMake\bin
For legacy reasons I still use Make because this is what I grew up. But Ninja is the one I’m using more and more because it is so fast :-).
GNU Arm Embedded Toolchain
The GNU toolchain for ARM is available on https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
I have installed the Version gcc-arm-none-eabi-10-2020-q4-major-win32 with the default settings.
To connect the GDB (debugger) to a target board, I need a debug probe. I’m using the SEGGER J-Link for this. The MCUXpresso IDE already comes with a J-Link installation, so very likely this already exists on your machine. If not you can download the J-Link Software from https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack
Install it with the defaults. I have V7.20 installed with the default settings:
It is be possible to use OpenOCD or PEMicro too. I focus first on the J-Link interface.
With this we should have now all the needed software installed.
In the next article I describe how to create the first project.
Happy Coding 🙂
- Visual Studio Code website: https://code.visualstudio.com/
- CMake website: https://cmake.org/download/
- GNU ARM Embedded Toolchain: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
- SEGGER J-Link Software: https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 1
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 2
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 3
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 4