1

When I'm programming on my STM32 project, VSCode constantly underlines the code #include "main.h" with the reason belows:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit. cannot open source file "stm32f1xx.h" (dependency of "main.h")

However, I double-checked my c_cpp_properties.json, finding nothing wrong with it. Meanwhile, VSCode has given me the quick fix method, adding ${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32F1xx/Include to includePath parameter, which didn't work either.

Belows are my configurations.

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "USE_HAL_DRIVER",
                "STM32F103xE"
            ],
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compilerPath": "C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.07\\bin\\arm-none-eabi-gcc.exe",
            "intelliSenseMode": "gcc-arm"
        },
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "USE_HAL_DRIVER",
                "STM32F103xE"
            ],
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compilerPath": "/opt/ARM/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc",
            "intelliSenseMode": "gcc-arm"
        }
    ],
    "version": 4
}

And the required file /Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h does exist and the compilation with make can be done correctly too.

I've check the files multiple times but didn't find any problem, like belows:

enter image description here

5
  • under which configuration do you need that path, Win32 or Linux? /Drivers/...looks like Linux, Is that the full path Commented Nov 28, 2021 at 1:41
  • /Drivers/... means the Drivers folder under the folder of the project, e.g. STM32Project/Drivers/... Commented Nov 29, 2021 at 2:45
  • Hi, Futurime, at first do you see that file in file explorer? I mean main.h? Commented Nov 30, 2021 at 7:23
  • ..and same question for that Drivers folder :) I think you created project in Cube IDE or something and then didn't mark a check with copy neccessary files to folder so now you use them from another localization in disk. Commented Nov 30, 2021 at 7:25
  • I did mark the checkbox to copy files. I posted the screenshot of VSCode, in which the necessary files were. Commented Dec 1, 2021 at 13:56

1 Answer 1

0

You have to tell vscode where to find all the include files needed.
When you add an include folder to the includePath, the included headers inside the folder might include other header from elsewhere. This might explain why you still get the error after adding a single path to the includePath.

Project generated using CubeMX typically have multiple include folders.

Your configuration file should look something like that

"configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/Core/Inc/**",
                "${workspaceFolder}/Drivers/STM32F0xx_HAL_Driver/Inc/**",
                "${workspaceFolder}/Drivers/STM32F0xx_HAL_Driver/Inc/Legacy/**",
                "${workspaceFolder}/Drivers/CMSIS/Include/**",
                "${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32F0xx/Include/**"
            ],
            "defines": ["STM32F031x6","USE_HAL_DRIVER"],
            "compilerPath": "path_to_compiler",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],

To find the required folders, you have different to do it :

Using the Makefile

If you have a working Makefile, it probably contains a place where it defines the used header files, for example :

C_INCLUDES =  \
-IDrivers/STM32F0xx_HAL_Driver/Inc \
-IDrivers/STM32F0xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F0xx/Include \
-IDrivers/CMSIS/Include

Using Vscode intellisense

If there is a missing header, Vscode will show the following error

cannot open source file "HEADER2.h" (dependency of "HEADER1.h")

This means that HEADER2.h is included inside HEADER1.h but there is no HEADER2.h in the includePath.

So you should find the folder containing HEADER2.h and add it.
To do so, you can use find . -name "HEADER2.h" from the root of the project.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.