cancel
Showing results for 
Search instead for 
Did you mean: 

Run without debugging on VSCode

DamianoF
Associate III

I have setup STM32 VSCode extension on my PC and it is amazing. The only problem that I have encountered is that it is not possible to run the code without debugging. I removed the "runToEntryPoint": "main" line in launch.json. But every time I launch the code it attaches a debugger. How can I simply run the code without debugging?

 

Thank you,

Damiano

14 REPLIES 14
istery
Associate II

我发现了可以创建一个task.json文件,加入以下内容

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": ":down_arrow: Flash",
            "type": "shell",
            "command": "STM32_Programmer_CLI.exe",
            "args": [
                "-c",
                "port=SWD",
                "-w",
                "${workspaceFolder}/build/Debug/TEST.bin",
                "0x08000000",
                "-v",
                "-rst"
            ],
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "problemMatcher": []
        }
    ]
}
这样就可以在终端中运行这个任务,只下载而不进入调试。配合Task插件可以将这个任务直接一键运行,和IDE内的操作一致
DavidEGrayson
Associate II

I prefer to do common operations like this with a keyboard, and I couldn't get most of Sarra.S's suggestions to work.  Also, the "Build + Flash" task is the one to use, since it also builds.  Here's what works for me:

Option 1: Do this every time you want to run without debugging: Ctrl+Shift+P, type "Tasks: Run Task" (or enough of it so it's at the top of the autocomplete list that pops up), Enter, use up and down arrow keys to select "Build + Flash" (which is defined in your project's autogenerated .vscode/tasks.json), Enter.

Option 2: Add a hotkey by doing Ctrl+Shift+P, and selecting "Preferences: Open Keyboard Shortcuts (JSON)".  Set the file contents to this, overwriting what was there (or merge it if there's something important there).  After you save the file, you can press Ctrl+F5 to run the command.  Unfortunately, this applies to all your VSCode projects.

[
    {
        "key": "ctrl+f5",
        "command": "workbench.action.tasks.runTask",
        "args": "Build + Flash"
    }
]



I have improved your task by adding a configuration to Build the code and Flash

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Flash STM32 (CubeProg)",
            "type": "shell",
            "command": "C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin\\STM32_Programmer_CLI.exe",
            "args": [
                "-c",
                "port=swd",
                "-d",
                "${command:cmake.launchTargetPath}", // Takes the path of the compiled binary
                "-v", // Verify after programming
                "-rst" // Reset the board to start the code
            ],
            "dependsOn": "CMake: build", // <--- This forces COMPILATION before flashing
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
}

Hi, I found this thread trying to answer the question "how do I flash my code to my MCU without needing to go through the debugger" when using vscode. I see there's mention of ST-specific "tasks", but (using the most recent VScode extension bundle) there is no "tasks.json" in my .vscode directory. 

Is it possible to get updated instructions on how to do this? Seems like kind of a mishmash of advice here, and not an obvious way to do any of these in the most recent build of the VSCode tooling. 

the "task" is a Vscode features in all latest versions, I am using the last update as well

this is what I am using 

https://code.visualstudio.com/docs/debugtest/tasks

the tasks.json file in .vscode folder