Skip to main content
Explorer
September 9, 2023
Question

VSCode extension build and only flash program

  • September 9, 2023
  • 4 replies
  • 10897 views

I started using stm32 MCU's on my university. There we used the CubeIDE. Now I have a board at home for own projects. I wanted to use VSCode with the new extension, because i prefer it over Eclipse / CubeIDE. Now I have two questions. I can debug my program via vscode, but I found no option to just flash it onto the board without debugging. (Where) can I do that?

Another questions that came into my mind related to that is, if I could just build my project without flashing it like you can do it on CubeIDE. When I press CTRL + P in vscode and press run build task i get an error:

 

FAILED: LED_TEST.elf 
cmd.exe /C "cd . && C:\ST\STM32CubeIDE_1.13.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.0.202305231506\tools\bin\arm-none-eabi-gcc.exe -fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -T C:/Users/Matth/Desktop/LED_TEST/STM32G431KBTX_FLASH.ld CMakeFiles/LED_TEST.dir/Core/Src/main.c.obj CMakeFiles/LED_TEST.dir/Core/Src/stm32g4xx_hal_msp.c.obj CMakeFiles/LED_TEST.dir/Core/Src/stm32g4xx_it.c.obj CMakeFiles/LED_TEST.dir/Core/Src/syscalls.c.obj CMakeFiles/LED_TEST.dir/Core/Src/sysmem.c.obj CMakeFiles/LED_TEST.dir/Core/Src/system_stm32g4xx.c.obj CMakeFiles/LED_TEST.dir/Core/Startup/startup_stm32g431kbtx.s.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cortex.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma_ex.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_exti.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ex.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ramfunc.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_gpio.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr_ex.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart_ex.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart.c.obj CMakeFiles/LED_TEST.dir/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c.obj -o LED_TEST.elf && cmd.exe /C "cd /D C:\Users\Matth\Desktop\LED_TEST\build\debug\build && C:\ST\STM32CubeIDE_1.13.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.0.202305231506\tools\bin\arm-none-eabi-size.exe C:/Users/Matth/Desktop/LED_TEST/build/debug/build/LED_TEST.elf && cd /D C:\Users\Matth\Desktop\LED_TEST\build\debug\build && C:\ST\STM32CubeIDE_1.13.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.0.202305231506\tools\bin\arm-none-eabi-objcopy.exe -O ihex C:/Users/Matth/Desktop/LED_TEST/build/debug/build/LED_TEST.elf LED_TEST.hex && cd /D C:\Users\Matth\Desktop\LED_TEST\build\debug\build && C:\ST\STM32CubeIDE_1.13.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.0.202305231506\tools\bin\arm-none-eabi-objcopy.exe -O binary C:/Users/Matth/Desktop/LED_TEST/build/debug/build/LED_TEST.elf LED_TEST.bin""
Der Befehl "cmd.exe" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
ninja: build stopped: subcommand failed.
build finished with error(s).

It sais that the command "cmd.exe" is misspelled  or could not be found.

 

    This topic has been closed for replies.

    4 replies

    Super User
    September 9, 2023

    Hi,

    A short answer: the VS Code extension looks nice and promising - but it is not quite mature yet. The debugger is the most crucial and valuable part of the developer environment. So, if you know Eclipse at all and can use it, please do yourself a favor and do so. Be productive and (almost) happy. Use the VS Code stuff when it is ready for  prime time (or when you feel like improving it and contribute to the community ;)

    maze2goAuthor
    Explorer
    September 9, 2023

    Thank you for your reply. I already noticed that the extension is not very mature. But is there a way to do my above mentioned things?

    Super User
    September 9, 2023

    Of course, many users do this many times every day. Just create a "Run" configuration in CubeIDE, it is similar to "Debug" but stops after loading the program. Another way: use the CubeProgrammer, ether GUI or command line variant. It is a special tool for putting the program on the MCU.

    Visitor II
    February 16, 2024

    This is the structure of the launch configuration for VSCode, where it needs to be changed to perform flash only

    {
     "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/Button.elf"
     }
     ],
     "logging": {
     "engineLogging": true
     },
     "preLaunchTask": "Build",
     "svdPath": "${command:vscode-embedded.st.svd}/STM32F103.svd"
     }
     ]
    }
    Visitor II
    February 20, 2024

    After some working, i finalized a launch.json tha actually flash the microcontroller and then disconnects, but due to early exit of the script VSCode warns about "GDB exited unexpectedly". It works but this script ends with this warning.

     {
     "name": "Program target board",
     "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": false,
     "postRemoteConnectCommands": [
     {"text": "load build/debug/build/Button.elf" }, 
     { "text": "detach"},
     { "text": "disconnect", "ignoreFailures": true},
     ],
     "logging": {
     "engineLogging": true,
     
     },
     "preLaunchTask": "Build",
     "svdPath": "${command:vscode-embedded.st.svd}/STM32F103.svd"
     },

     

    Super User
    February 21, 2024

    "GDB exited unexpectedly"

    The type should be something else, not "cppdbg"?

    Visitor II
    March 15, 2024

    "cppdbg" is the default tool provided with the official VSCode STM32 Extension so this is a minimum intrusive change to make the whole thing works as spected.

    Super User
    March 15, 2024

    Try a different port number, not 3333 ?