Developing Cortex M3 Applications Using Visual Studio Code
Developing Cortex M3/M4 Applications Using Visual Studio Code
Visual Studio Code (VSCode) can be used to edit the source code, build the application and finally debug it.
Required Software Components
In contrast to fully integrated IDEs, setting up Visual Studio Code requires us to setup a number of software packages, which finally work together to build the complete development environment. The software packages can be split into three groups:
- VSCode and plugins
- ARM Build Tools (compiler etc.)
- Debug tools
- The packages can be installed in any order
- VSCode must be installed before VSCode plugins can be installed.
1. Visual Studio Code and Plugins
Visual Studio Code
We can look at VSCode as an intelligent text editor which provides an extensive framework to add functionality through plugins. VSCode includes a project explorer, which can show the contents of one or multiple folders as a workspace. There is more information on required plugins further down in this list.
This plugin offers many features to simplify editing of C/C++ code, including Syntax highlighting, Intellisense (finding definitions of symbols), auto-completion of keywords and identifier names, and marking syntax errors while typing. For more details, please refer the following documents:
- C/C++ for Visual Studio Code
- Using C++ on Linux in VSCode
- Using GCC with MinGW
- Configure VSCode for Microsoft C++
This plugin adds support for debugging ARM Cortex-M devices executable through a GDB Server.
CMake Language Support for Visual Studio Code.
Syntax highlighting for ARM assembly code
Syntax highlighting for linker scripts
2. ARM Build Tools
GNU ARM Embedded Toolchain
GNU ARM Embedded Toolchain is the C/C++ compiler and linker along with additional tools. It is used to turn your source code into a binary executable.
CMake is a tool which turns compiler-independent project definitions into compiler-specific project definitions. CMake converts these into makefiles that can be processed by the GNU ARM Embedded Toolchain.
3. Debugger Tools
OpenOCD is an open-source debugger, supporting a wide variety of JTAG hardware interfaces. For customers using a JTAG adapter other than the J-Link, this probably is the matching software. The package contains a GDB server, which connects to VSCode on one side, and to the J-Link JTAG/SWD hardware on the other side.
Chocolatey (The Package Manager For Windows)
The Windows versions of required software will be installed using Chocolately
- Launch Power shell as an administrator, then run the following command:
If it returns Restricted, then run Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass -Scope Process.
Now run the following command:
> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
If you don't see any errors, you are ready to use Chocolatey! Type choco or choco -? now, or see following documents for more info:
- Install Chocolatey on windows 10
- Install package(s)
- upgrade package(s)
- Search for available packages
- Uninstall package(s)
Note: Always run Chocolatey (choco) under Windows Power Shell (as an administrator)
4. Install VSCode
- Please follow this link to install Visual Studio Code Application.
- For more options, please refer to the Visual Studio Code setup page.
- You can also Download Visual Studio Code and install.
> choco install vscode
5. Installing Visual Studio Code Plugins
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
Or we can use in the IDE the menu View > Extensions.
- Open VSCode
- Select View → Extensions
- This will show the Extension sidebar
- In the search box above the Extension sidebar, type the Code name from the above table (without the angle brackets) or another reasonable search term
- Click on the little green Install button which appears next to the found plugin.
Below is our installed extensions (menu File > Preferences > Extensions):
6. Install Build Tools
GNU Arm Embedded Toolchain
- Please follow this link to install GNU ARM Embedded Toolchain
- OR, we can install using apt
$ sudo apt update $ sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi
Make and CMake
$ sudo apt update $ sudo apt install make cmake
GNU Arm Embedded Toolchain
> choco install gcc-arm-embedded
> choco install make
> choco install cmake
7. Install Debugging Tools
$ sudo apt update $ sudo apt install openocd
> choco install openocd
Please refer following documents to know more about how to run OpenOCD:
- OpenOCD Ubuntu Package
- OpenOCD Config Files
- OpenOCD Config File Paths
- Running OpenOCD on Linux
- Running OpenOCD on Windows
- Accessing Devices without sudo
- Configuring Windows 7 for OpenOCD
You can download sample project from here