Skip to main content
Version: 5.0

Developing M4 Applications Using Visual Studio Code

Visual Studio Code can be used to edit the source code, build the application and finally debug it. Toradex provides the necessary configuration files and instructions to setup your system.

Required Software Components​

In contrast to fully integrated IDEs, setting up Visual Studio Code (short. VSCode) requires you 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:

  1. VSCode and plugins
  2. Arm build tools (compiler etc.)
  3. Debug tools

The packages can be installed in any order (well, almost: VSCode must be installed before VSCode plugins can be installed). Understanding the purpose of individual components helps to debug potential problems and understand the behavior of the system. Therefore I want to first give an overview over these parts.

1. Visual Studio Code and Plugins​

Visual Studio Code​

You 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.

Required Plugins​

C/C++:
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.

Cortex-Debug:
This plugin adds support for debugging ARM executables through a GDB Server.

Optional Plugins​

CMake:
Syntax highlighting for CMakeLists.txt

ARM:
Syntax highlighting for ARM assembly code

Linker Script:
Syntax highlighting for linker scripts

2. Arm build tools​

GNU Arm Embedded Toolchain:
This is the C/C++ compiler und linker along with additional tools. It is used to turn your source code into a binary executable.

CMake:
CMake is a tool which turns compiler-independent project definitions into compiler-specific project definitions.
NXP provides such independent project definitions in CMakeLists.txt files. CMake converts these into makefiles that can be processed by the GNU Arm Embedded Toolchain.

3. Debugger Tools​

Segger J-Link: (for J-Link hardware debugger only)
This software package contains the J-Link GDB server, which connects to VSCode on one side, and to the J-Link JTAG hardware on the other side.

OpenOCD: (for generic hardware debugger)
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 hardware on the other side.

Installation Steps​

Click the tab below to select whether you develop on a Windows or Linux host machine.

Installation Steps for Windows 10 machines​

Visual Studio Code is still undergoing significant development. Therefore I will point out the version used at the time when these instructions were written.

  • Instructions were written in August 2019
  • Tested on a Windows 10 Build 1903

1. Installing Visual Studio Code and Plugins​

Details

Installing the Visual Studio Code Application​

IconNameTested VersionDownload Link
Visual Studio Code1.36.1Visual Studio Code 1.36.1 64-bit
  1. Download the installer VSCodeUserSetup-x64-1.36.1.exe
  2. Execute the installer

Keeping all the default settings for installation is just fine.

Installing Visual Studio Code Plugins​

IconPlugin NameTested VersionRequired /
Optional
Codename
C/C++0.24.1Requiredms-vscode.cpptools
Cortex-Debug0.3.1Requiredmarus25.cortex-debug
CMake Syntax Highlighting0.0.17Optionaltwxs.cmake
ARM Assembly highlighting0.5.0Optionaldan-c-underwood.arm
Linker Script highlighting0.1.0Optionalamapleaf.linker-script

There are two options to install a Visual Studio Code plugin

Option 1: From the Windows Command Prompt

  1. Open a command prompt
  2. enter
$ code --install-extension <Codename>

Use Codename from the table above (without the <angle brackets>)

Option 2: From withing VSCode

  1. Open Visual Studio Code
  2. Select View → Extensions
    This will show the Extension sidebar
  3. In the search box above the Extension sidebar, type the <Codename> from the table above (without the <angle brackets>) or another reasonable search term . Click on the little green Install button which appears next to the found plugin

Use the instructions above to install each of the listed plugins:

2. Installing Build Tools​

Details

Installing GNU Arm Embedded Toolchain​

IconNameTested VersionDownload Link
GNU Arm Embedded Toolchain8-2018-q4-majorgcc-arm-none-eabi-8-2018-q4-major-win32-sha2.exe

Generic:
GNU Arm Embedded Toolchain
  1. Download the installer gcc-arm-none-eabi-8-2018-q4-major-win32-sha2.exe

  2. Execute the installer
    Keeping all the default settings for installation is just fine.

  3. Manual Step: Add a system environment variable ARMGCC_DIR

    • Use your file explorer to identify the path where the GNU Arm Embedded Toolchain has been installed.
      By default, this will be:
      C:\Program Files (x86)\GNU Tools ARM Embedded\8 2018-q4-major
    • Click [START] →type [environment] (without brackets) → select [Edit the system environment variables] → Click [Environment Variables] → in the lower part click [New...] to add a new System variable
    • Variable Name = "ARMGCC_DIR" (without quotes), Variable value = [path which you looked up above], for example "C:\Program Files (x86)\GNU Tools ARM Embedded\8 2018-q4-major" (without quotes)
    • Click [OK] three times to close all dialogs.

Installing CMake​

IconNameTested VersionDownload Link
CMake3.14.4CMake 3.14.4 64bit

Generic:
CMake
  1. Download the installer cmake-3.14.4-win64-x64.msi

  2. Execute the installer
    Keeping all the default settings for installation is just fine.

3. Installing Debugging Tools​

Details

To do hardware debugging, VSCode depends on external GDB servers to access the hardware over JTAG. Depending on your JTAG adapter you might need one or the other software package mentioned below.
The installations can work side by side.

info

This step is only required if you plan to use a Segger J-Link debug hardware adapter.

IconNameTested VersionDownload Link
Segger J-Link supportV6.46 [2019-05-23]JLink_Windows_V646.exe

Generic:
JLink for Windows
  1. Download the installer JLink_Windows_V646.exe

  2. Execute the installer
    Keeping all the default settings for installation is just fine.

Installing OpenOCD​

info

This step is only required if you plan to use a debug hardware adapter other than Segger J-Link.

IconNameTested VersionDownload Link
OpenOCD0.10.0 [2019-07-15]openocd-20190715.7z

Generic:
OpenOCD
danger

The installation instructions of OpenOCD contain a number of manual steps. Depending on your actual hardware and software setup, you may need to adjust the installation.
This is a generic guideline which helps you to avoid certain pitfalls, but Toradex cannot make sure that the instructions will work for all setups. The installation shouldn't be too complex, but it will require some work and some technical understanding to get it running.
We will try to improve the OpenOCD user experience in the future.

  1. Download the installer openocd-0.10.0.7z

  2. Unzip the contents to c:\Program Files (so the binaries end up in c:\Program Files\openocd-0.10.0\bin )

    • Keeping all the default settings for installation is just fine.
  3. Open the VSCode user settings file settings.json:
    File → Preferences → Settings
    Select User settings
    Enter "json" in the search bar (with or without double quotes)
    Locate a link "Edit in settings.json" and click on it. This will open the file C:\Users\YOURNAME\AppData\Roaming\Code\User\settings.json

  4. Add the following two lines to the settings.json file, between the curly braces {}:
    "cortex-debug.armToolchainPath": "C:/PROGRA~2/GNUTOO~1/82018-~1/bin", "cortex-debug.openocdPath": "C:/Program Files/openocd-0.10.0/bin/openocd.exe" Please note:
    (a) The paths on your system might be different. Make sure the path matches your actual file locations.
    (b) The armToolchainPath needs to be given in legacy-compatible 8.3 location. You can use dir /x in the command shell to see the short names.
    (c) All paths in VSCode are defined with forward-slashes /

  5. Save the file settings.json

  6. Locate the OpenOCD configuration file for your JTAG adapter. For the Olimex ARM-USB-OCD-H adapter, the file can be found here:
    C:\Program Files\openocd-0.10.0\share\openocd\scripts\interface\ftdi\olimex-arm-usb-ocd-h.cfg

  7. Create another configuration file:
    C:\Program Files\openocd-0.10.0\share\openocd\scripts\target\imx7_m4.cfg

     set _CHIPNAME imx7
    set _TARGETNAME $_CHIPNAME.cpu_m4
    set _CORESIGHT_JTAG_DP_ID 0x5ba00477

    transport select jtag
    adapter_khz 4000

    jtag newtap imx7 cpu -irlen 4 -ircapture 0x01 -irmask 0x0f -expected-id 0x5ba00477
    dap create imx7.dap -chain-position imx7.cpu

    target create imx7.cpu_m4 cortex_m -dap imx7.dap -ap-num 4
    targets $_TARGETNAME

    The folowing steps need to be done for every project you want to debug:

  8. Open the launch.json file of the project. If you go for one of the default examples, launch.json will already contain a configuration for the J-Link Debug hardware.

  9. Copy the configuration (everything from {"name":... to ] } ). Separate the two configurations with a comma ,.

  10. Adjust the new configuration to look as the one below. Keep the name of the .elf files, add non-existing parameters, and delete extra parameters.

     {
    "name": "OpenOCD Debug PROEJECTNAME",
    "request": "launch",
    "type": "cortex-debug",
    "rtos": "FreeRTOS",
    "servertype": "openocd",
    "interface": "jtag",
    "device": "MCIMX7D5_M4",
    "cwd": "${workspaceRoot}",
    "executable": "armgcc/debug/PROEJECTNAME.elf",
    "configFiles": [
    "C:/Program Files/openocd-0.10.0/share/openocd/scripts/interface/ftdi/olimex-arm-usb-ocd-h.cfg",
    "C:/Program Files/openocd-0.10.0/share/openocd/scripts/target/imx7_m4.cfg"
    ]
    },