2024-09-18 03:29 AM
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
why? why cannot import the project?
thanks.
Solved! Go to Solution.
2024-09-18 12:11 PM
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:
2024-09-18 03:41 AM
when I open the folder and try to build, the result is as below
what is the problem? 1 day before it was ok, but now cannot build.
Thanks
2024-09-18 12:11 PM
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:
2024-09-18 05:35 PM
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.
2024-09-18 05:43 PM
I re-generated the project with STM32CubeMX, below is my setting.
you can see I used CMake.
and I re-import, it is still the problem. no solve. do you have any other advice?
thanks.
2024-09-20 10:14 AM
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?
2024-09-25 01:51 AM
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.
2024-09-25 08:22 AM
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.
2024-09-25 05:58 PM
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
2024-09-26 09:32 AM
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.