cancel
Showing results for 
Search instead for 
Did you mean: 

Debug fails from imported STM32CubeIDE project to VSCode

kkar
Associate II

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.

 

,

9 REPLIES 9
MM..1
Chief II

Maybe try dont use - in folder file names...

kkar
Associate II

Which file names do you mean?

firmware-maincontroller

but i mean your config have more issues, use platformio is simpler...

TDJ
Senior III

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

kkar
Associate II

Thank you so much for the suggestion. I am looking for more CMake based options.

kkar
Associate II

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?

 

KnarfB
Principal III

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

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.

kkar_0-1688735430136.png

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.

kkar
Associate II

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?