Skip to main content
Visitor II
August 11, 2023
Question

STM32Cube MX, VScode setup

  • August 11, 2023
  • 2 replies
  • 4850 views

Hello.
I'm having issues with STM32CubeMX and VScode setup. I have the STM32 VScode extension installed and all the extras that were required as per this page ( https://marketplace.visualstudio.com/items?itemName=bmd.stm32-for-vscode ). I generate a make file for the blue pill based on the STM32F103C8T6 IC. When I open the code in VScode I immediately see errors starting with (main.h: No such file or directory 20 | #include "main.h")
There are other errors starting with unknown type name 'RCC_OscInitTypeDef' | RCC_OscInitTypeDef RCC_OscInitStruct = {0};
'RCC_CLOCKTYPE_HCLK' undeclared (first use in this function) | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK


Any suggestions on how to set this up so these errors are permanently resolved?

    This topic has been closed for replies.

    2 replies

    Graduate II
    August 12, 2023

    I found these videos:

    https://www.youtube.com/watch?v=PxQw5_7yI8Q

    https://www.youtube.com/watch?v=xaC5oWwzOt0

    https://www.youtube.com/watch?v=7stymN3eYw0

    Note: I've already used vscode a few times, but I think it's better to use the STM32CubeIDE with the STM32 MCUs, ST is already making an effort to keep it updated and fix the bugs, and the people here on the forum have more knowledge in this STM32CubeIDE. It may take a while to get used to the STM32CubeIDE if the programmer is not familiar with the Eclipse IDE, but I think it's worth it. In the end the generated code should be similar too.

    Super User
    August 12, 2023

    It's a matter of taste. I prefer vscode with https://marketplace.visualstudio.com/items?itemName=bmd.stm32-for-vscode plugin (which came before the ST own plugin). Projects are Makefile based and there is much less magic behind the curtain compared to STM32CubeIDE/Eclipse.

    Are those error just squiggles in the editor? It may take a while until IntelliSense has picked up all neccessary include files.

    Edit: this process is done by the Makefile tools https://marketplace.visualstudio.com/items?itemName=ms-vscode.makefile-tools which should be installed too.

    hth

    KnarfB

    Graduate II
    July 11, 2025

    I also wanted to use VS Code for editing and STM32CubeIDE for configuration of the controller. It turns out all it might be required (at least as of July 2025) is that your project root directory needs to have a `.vscode/c_cpp_properties.json`:

    {
     "configurations": [
     {
     "name": "STM32",
     "includePath": [
     "${workspaceFolder}/**",
     "${workspaceFolder}/Core/Inc",
     "${workspaceFolder}/Drivers/STM32L4xx_HAL_Driver/Inc",
     "${workspaceFolder}/Drivers/STM32L4xx_HAL_Driver/Inc/Legacy",
     "${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32L4xx/Include",
     "${workspaceFolder}/Drivers/CMSIS/Include"
     ],
     "defines": [
     "USE_HAL_DRIVER",
     "STM32L452xx"
     ],
     "compilerPath": "/usr/bin/arm-none-eabi-gcc",
     "cStandard": "c11",
     "cppStandard": "c++17",
     "intelliSenseMode": "gcc-arm"
     }
     ],
     "version": 4
    }

     

    The `includePath` was rather easy to find, but still I got those errors that Intellisense could not find much of the defines. I got the rest from ChatGPT's help and since then the errors have gone away.