2023-07-07 02:45 AM
Hello, I have been working with the STM32CubeIDE for a while and I was thinking of maybe moving to VSCode as I am liking the VSCode interface a lot better than the Eclipse style of the CubeIDE.
I installed the STM32 Extension for VSCode and I installed all the necessary applications suggested by the Extension and added the PATH to the System Variables.
I imported an existing CubeIDE project to VSCode and VSCode automatically generated cmake files, CMakeLists.txt file and .json files like launch.json, tasks.json, settings.json etc. When I run CMake-> Build, it builds completely without errors and the output shows the .obj files generated. But when I go to main.c and press Debug C/C++ File, it runs into an error and it says that main.h: No such file or directory.
I haven't edited any auto-generated files by VSCode and I have attached the files for reference. Could anybody let me know what the problem could be? Thanks in advance.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${command:cmake.launchTargetPath}",
"MIMode": "gdb",
"miDebuggerPath": "${command:vscode-embedded.st.gdb}",
"miDebuggerServerAddress": "localhost:3333",
"debugServerPath": "${command:vscode-embedded.st.gdbserver}",
"debugServerArgs": "--stm32cubeprogrammer-path ${command:vscode-embedded.st.cubeprogrammer} --swd --port-number 3333",
"serverStarted": "Waiting for connection on port .*\\.\\.\\.",
"stopAtConnect": true,
"postRemoteConnectCommands": [
{
"text": "load build/debug/build/firmware-maincontroller.elf"
}
],
"logging": {
"engineLogging": true
},
"preLaunchTask": "Build",
"svdPath": "${command:vscode-embedded.st.svd}/STM32F429.svd"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "cmake",
"command": "build",
"problemMatcher": "$gcc",
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
settings.json
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureOnOpen": true,
"files.associations": {
"main.h": "c",
"config.h": "c",
"calibration.h": "c"
}
}
Error
* Executing task: C/C++: gcc.exe build active file
Starting build...
C:\MinGW\bin\gcc.exe -fdiagnostics-color=always -g C:\Users\user\Documents\Firmware_Development\CubeIDE\firmware-maincontroller\Core\Src\main.c -o C:\Users\user\Documents\Firmware_Development\CubeIDE\firmware-maincontroller\Core\Src\main.exe
C:\Users\user\Documents\Firmware_Development\CubeIDE\firmware-maincontroller\Core\Src\main.c:20:18: fatal error: main.h: No such file or directory
#include "main.h"
^
compilation terminated.
Build finished with error(s).
* The terminal process terminated with exit code: -1.
* Terminal will be reused by tasks, press any key to close it.
,
2023-07-07 02:55 AM
Maybe try dont use - in folder file names...
2023-07-07 03:08 AM
Which file names do you mean?
2023-07-07 03:11 AM
firmware-maincontroller
but i mean your config have more issues, use platformio is simpler...
2023-07-07 04:17 AM - edited 2023-07-10 04:11 PM
For a complete, well-tested and documented VS Code env setup you can check out my STM32F769I-DISCO demo at
https://github.com/tdjastrzebski/STM32F769I-DISCO-LVGL
2023-07-07 04:41 AM
Thank you so much for the suggestion. I am looking for more CMake based options.
2023-07-07 04:48 AM
Platformio is new to me. I was thinking about maybe using the new official STM32 VSCode Extension. Could you let me know what could be changed in the config to rectify this problem?
2023-07-07 05:12 AM - edited 2023-07-07 05:12 AM
The line
"preLaunchTask": "Build",
is wrong, because it triggers the Build task in settings.json which wants to compile a C/C++ single file and does not know about your project or CMake at all. Remove that line.
hth
KnarfB
2023-07-07 06:12 AM - edited 2023-07-07 06:17 AM
Thank you so much. It helped. But that line was auto-generated by the Extension.
Anyway, it went through and the auto-breakpoint was set on the Reset_Handler: function in the startup file. When I ran it, it ran till the first line of the main function and there was no response.
When I paused it, it said Exception has occured and Interrupt.
1. What could be causing this issue? - I think pausing it has caused the error. I am not sure if that is how it reacts when the debugger is paused.
2. If the above issue is solved, does ST-Link GDB server trace the printf statements or should it be configured as well somehow?
Thank you once again.
2023-07-10 12:55 AM
I see Platformio is more for Boards. I cannot find a project for an MCU. Is that true or haven't I found the right information?