Actions

EmSys

Difference between revisions of "Using Visual Studio Code for ARM Development – Include Paths"

From EdWiki

m (Using Visual Studio Code for ARM Development – Include Paths)
m (Using Visual Studio Code for ARM Development – Include Paths)
Line 24: Line 24:
 
     "configurations": [
 
     "configurations": [
 
         {
 
         {
             "name": "Linux",
+
             "name": "ARM",
 
             "includePath": [
 
             "includePath": [
 
                 "${workspaceFolder}/**",
 
                 "${workspaceFolder}/**",
                 "${workspaceFolder}/inc",
+
                 "E:\\ti\\TivaWare_C_Series-2.2.0.295"
                "${ARMGCC_DIR}/arm-none-eabi/include",
+
                "/home/jshankar/ti/TivaWare_C_Series-2.1.4.178/"
+
 
             ],
 
             ],
 
             "defines": [
 
             "defines": [
 +
                "_DEBUG",
 
                 "PART_TM4C123GH6PM"
 
                 "PART_TM4C123GH6PM"
 
             ],
 
             ],
             "compilerPath": "${ARMGCC_DIR}/bin/arm-none-eabi-gcc",
+
             "compilerPath": "C:\\ProgramData\\chocolatey\\bin\\arm-none-eabi-gcc",
 
             "cStandard": "c99",
 
             "cStandard": "c99",
             "cppStandard": "c++17",
+
             "cppStandard": "gnu++17",
             "intelliSenseMode": "clang-x64"
+
             "intelliSenseMode": "gcc-arm",
 +
            "configurationProvider": "ms-vscode.cmake-tools"
 
         }
 
         }
 
     ],
 
     ],

Revision as of 06:47, 22 March 2022

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. 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. These include default includePaths suitable for desktop applications, but are not correct for ARM.

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.

The second section with just “path” is used by IntelliSense to suggest things for you.

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

This is the initial c_cpp_properties.json file:

{
    "configurations": [
        {
            "name": "ARM",
            "includePath": [
                "${workspaceFolder}/**",
                "E:\\ti\\TivaWare_C_Series-2.2.0.295"
            ],
            "defines": [
                "_DEBUG",
                "PART_TM4C123GH6PM"
            ],
            "compilerPath": "C:\\ProgramData\\chocolatey\\bin\\arm-none-eabi-gcc",
            "cStandard": "c99",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "gcc-arm",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}


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


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.


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