Actions

EmSys

Using Visual Studio Code for ARM Development – Include Paths

From EdWiki

Revision as of 04:20, 3 January 2020 by Jshankar (Talk | contribs) (Created page with "__NOTOC__ == Using Visual Studio Code for ARM Development – Include Paths == This article will describe how to set up the Include Paths for C/C++ in [https://code.visualstud...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Using Visual Studio Code for ARM Development – Include Paths

This article will describe how to set up the Include Paths for C/C++ in Visual Studio Code to support ARM development.

Visual Studio Code with the C/C++ plugin has many useful features while you are writing your code: syntax highlighting, error checking while you type, and automatic code completion, where it guesses while you type. This can help you reduce errors and write faster. However, if the plugin is not correctly set up, these features will not work correctly or at all.

In order for Visual Studio Code and the C/C++ language plugin to understand your code, it needs to be able to find all of the header files referenced in your program. A header can further reference other headers, so they may be needed even if you didn’t explicitly call them yourself.

In main.c, VSCode is complaining that it cannot open main.h. (Grrr! It’s right there in my workspace, under the inc folder, and I can open it – it’s fine!) The message is a little obscure, but it’s basically saying that it will interpret the file based on keywords and syntax, but can’t tell if things like function or variable names are correct.

Vscode include error.png

So, how do we fix this? If your cursor is on the error, you will see the lightbulb to the left. Click that, and then Update “includePath” setting. VSCode will create and open a file called “c_cpp_properties.json”, in your project under a “.vscode” folder. By default this will contain configurations for Mac, Linux, and Win32. Unless you are developing your project on multiple computers, you don’t need them. These include default includePaths suitable for desktop applications, but are not correct for ARM. I cut them down to a single one, called TM4C.

There are two sections with paths. The first, “includePath”, is where VSCode will look for headers for the purpose of checking your code. Unlike GCC, this is not recursive; you need to explicitly list each folder that contains headers that are referenced, directly or indirectly. While the default included “${workspaceRoot}”, it did not cover the inc folder – we will need to add that.

The second section with just “path” is used by IntelliSense to suggest things for you. If you are using massive libraries, you may not want tons of obscure things showing up. You can limit this list to the headers you actually use. This is recursive but you can make it non-recursive if you want. The default also included “${workspaceRoot}” so Intellesense is good for our own stuff.

We will also need to set a file for the symbol database.

This is the initial c_cpp_properties.json file:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/inc",
                "${ARMGCC_DIR}/arm-none-eabi/include",
                "/home/jshankar/ti/TivaWare_C_Series-2.1.4.178/"
            ],
            "defines": [
                "PART_TM4C123GH6PM"
            ],
            "compilerPath": "${ARMGCC_DIR}/bin/arm-none-eabi-gcc",
            "cStandard": "c99",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Next problem! The original error has changed, and it’s complaining about a dependency.

Vscode include dependency error.png

In main.h, there are now multiple errors showing.

Basically, this is more of the same. Most of these files are part of the STM32Cube library, that is outside of our project. I’ll add those folders to my paths as well.

But where is stdint.h? GCC has built-in include paths that are used even if my compiler flags don’t specify them. GCC will list the defaults by running “arm-none-eabi-gcc -xc -E -v -“, and add those paths as well. Be sure list all sub folders with headers for the includePath section.

Vscode include headers error.png

Once you add all the paths you need, all of the header inclusion errors will go away.