Skip to main content
Graduate
September 18, 2024
Solved

VSCode with STM32 extension V2.1.0 errors

  • September 18, 2024
  • 5 replies
  • 5609 views

hello, 

Now I am using VSCode with STM32 extension V2.1.0, at beginning is used well. but 1 days later, when I opened the VScode and try to build my code. it shows 

"Unhandled exception: Unhandled Promise rejection: build Error: Build failed: Unable to configure the project {}"

then I want to close the folder, it cannot be closed. 

so I copy it to a backup folder and delete the project. and copy back and use [Import CMake project], the VSCode just always importing. you can see as below

dqsh06_0-1726655290534.png

why? why cannot import the project?

thanks.

    This topic has been closed for replies.
    Best answer by Rob.Riggs

    I see you are in an STM32CubeIDE workspace. Are you sure that the code was generated as a CMake project in this location?

    If this really is a VS Code workspace, here are some things to try:

    1. Use source control to revert your workspace to a known good state.
    2. If that does not work or is not possible, regenerate the project using STM32CubeMX, then re-import the project.
    3. If there is still a problem, try removing the .vscode/settings.json file and re-import the project.

     

    5 replies

    dqsh06Author
    Graduate
    September 18, 2024

    when I open the folder and try to build, the result is as below

    dqsh06_0-1726656071238.png

    what is the problem?  1 day before it was ok, but now cannot build.

    Thanks

    Rob.RiggsAnswer
    Graduate II
    September 18, 2024

    I see you are in an STM32CubeIDE workspace. Are you sure that the code was generated as a CMake project in this location?

    If this really is a VS Code workspace, here are some things to try:

    1. Use source control to revert your workspace to a known good state.
    2. If that does not work or is not possible, regenerate the project using STM32CubeMX, then re-import the project.
    3. If there is still a problem, try removing the .vscode/settings.json file and re-import the project.

     

    dqsh06Author
    Graduate
    September 19, 2024

    @Rob.Riggs 

    yes, my workspace is in an STM32CubeIDE, because before use VSCode, I used STM32CubeIDE, so I put the all files generated by STM32CubeMX at an STM32CubeIDE workspace, but I think it is a directory, you can name the directory any name, for example, VSCode, I think it is not the root cause for this issue. I generated the project with CMake, otherwise, it cannot be imported at first, and cannot see the cmake folder and CMakeLists.txt file. these are generated by STM32CubeMX.

    I have regenerated the project, but it seems no solve this issue.

    I will try to removing the .vscode/settings.json.

    Thanks.

     

    Graduate II
    September 20, 2024

    Create a new CMake project in STM32CubeMX and then trying to import that into VS Code. That will tell you if the problem is with your specific project (if it can be imported), or with VS Code (if it cannot be imported).

    Did you upgrade VS Code or install or uninstall any extensions between the time it worked and when it did not?

    Is the CMake extension installed? If not, does installing this extension change anything?

    Did you make any changes to the generated CMake files? If so, does reverting these changes allow the project to be imported?

    dqsh06Author
    Graduate
    September 25, 2024

    @Rob.Riggs 

    hello, I have uninstalled the vscode and deleted the .vscode under my  c:\users\username folder. and re-install vscode again and reinstall all necessary extension, now it seems ok, I can import MX generated project now.

     

    but, I have another question. now the vscode can only build files generated by STM32CubeMX, if you write my own files, for example, BSP_USB.h BSP_BUS.c, I put the 2 files in folder BSP, which is in Drivers. so the directory is like

    .\Drivers\BSP\BSP_USB.c 

    .\Drivers\BSP\BSP_USB.h

     

    how can I get the including path for the 2 files? (when i build, the cmake cannot find the 2 files)

    Thanks.

     

    Graduate II
    September 25, 2024

    You will need to edit the cmake/stm32cubemx/CMakeLists.txt file that lists all of the source files to be compiled. Add the source file there. But this is not really the place for a CMake tutorial.

    dqsh06Author
    Graduate
    September 26, 2024

    @Rob.Riggs 

    thanks for reply!

    This is what i have done now, but I think it is not a final solution, because every time when I use STM32CubeMX to regenerate the codes again, the files I written still can not be found by CMake. that means I should add the source file to  cmake/stm32cubemx/CMakeLists.txt again. it takes time and sometimes it is forgotten  

    so I think it is not a final solution. does ST have a final solution for this issue?

    Thanks

    Graduate II
    September 26, 2024

    That is true. The proper way to handle this is to create another folder with a separate CMakeLists.txt file with your code built as a library and modify the top-level CMakeLists.txt file to build both modules and link in your library.

     

    # Add linked libraries
    target_link_libraries(${CMAKE_PROJECT_NAME}
    stm32cubemx
    # Add user defined libraries
    mylibrary
    )

     

    The top-level CMakeLists.txt is created only once and is never overwritten.

    dqsh06Author
    Graduate
    September 27, 2024

    @Rob.Riggs 

    I have tried that, but not succeeded. 

    could you give a clear demonstration?

    thank.

    Visitor II
    November 4, 2024

    Have you tried running Visual Studio Code as administrator?