cancel
Showing results for 
Search instead for 
Did you mean: 

VSCode with STM32 extension V2.1.0 errors

dqsh06
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

 

View solution in original post

10 REPLIES 10
dqsh06
Associate III

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

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.

 

@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.

 

@Rob.Riggs 

I re-generated the project with  STM32CubeMX, below is my setting. 

dqsh06_0-1726706537523.png

you can see I used CMake.

and I re-import, it is still the problem. no solve. do you have any other advice?

thanks.

Rob.Riggs
Senior III

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?

@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.

 

Rob.Riggs
Senior III

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.

@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

Rob.Riggs
Senior III

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.