Skip to main content
Explorer II
August 2, 2024
Question

Any hints on using SWO output from STM32 within VSCode via STLink V3?

  • August 2, 2024
  • 4 replies
  • 4531 views

I'm reading various posts about the cortex debug extension supporting SWO output, but maybe not on STLinks, and various ways to enable it for other types of ARMs. Are there any guides to how to set it up for STM32 within VSCode?

    This topic has been closed for replies.

    4 replies

    Graduate II
    August 2, 2024

    It doesn't work on CM0(+) cores

    You'd need to get with VSCode devs to understand exactly what they'd implemented and support in current iterations.

    If it works on Segger J-Link's then you might look at the ST-LINK/V2 to J-Link OB firmware conversion. Or look at CMSIS-DAP support

    Explorer II
    August 2, 2024

    Right - thus my message here. Hopefully some of the ST Devs can weight in and suggest an existing set of instructions or some guidance on how best to set this up with what's in the current version of the extension.

    Graduate II
    August 2, 2024

    I think VSCode has it's own forums and developer feeds

    Perhaps @Nawres GHARBI knows?

    ST Employee
    August 5, 2024

    Hi All,

     

    This post has been escalated to the ST Online Support Team for additional assistance. We'll contact you directly.

     

    Regards,
    Jake

    ST Support

    Graduate II
    August 6, 2024

    It works with OpenOCD. This is the stanza I use in my launch.json file:

     

     

     {
     "name": "Build & Debug Microcontroller - OpenOCD",
     "cwd": "${workspaceFolder}",
     "type": "cortex-debug",
     "executable": "${command:cmake.launchTargetPath}",
     // Let CMake extension decide executable: "${command:cmake.launchTargetPath}"
     // Or fixed file path: "${workspaceFolder}/path/to/filename.elf"
     "request": "launch",
     "servertype": "openocd",
     "configFiles": [
     "${workspaceFolder}/stlink.cfg"
     ],
     "device": "STM32L4P5RETx", //MCU used
     "interface": "swd",
     "serialNumber": "", //Set ST-Link ID if you use multiple at the same time
     "runToEntryPoint": "main",
     "svdFile": "${config:STM32VSCodeExtension.cubeCLT.path}/STMicroelectronics_CMSIS_SVD/STM32L4P5.svd",
     "v1": false, //Change it depending on ST Link version
     "serverpath": "/usr/bin/openocd",
     "stm32cubeprogrammer":"${config:STM32VSCodeExtension.cubeCLT.path}/STM32CubeProgrammer/bin",
     "stlinkPath": "${config:STM32VSCodeExtension.cubeCLT.path}/STLink-gdb-server/bin/ST-LINK_gdbserver", 
     "armToolchainPath": "${config:STM32VSCodeExtension.cubeCLT.path}/GNU-tools-for-STM32/bin",
     "gdbPath":"${config:STM32VSCodeExtension.cubeCLT.path}/GNU-tools-for-STM32/bin/arm-none-eabi-gdb", 
     "swoConfig": {
     "enabled": true,
     "cpuFrequency": 16000000,
     "swoFrequency": 2000000,
     "source": "probe",
     "decoders": [
     { 
     "type": "console",
     "label": "ITM",
     "showOnStartup": true,
     "port": 0,
     "encoding": "ascii"
     }
     ]
     },
     "preLaunchTask": "Build project"
     /* If you use external loader, add additional arguments */
     //"serverArgs": ["--extload", "path/to/ext/loader.stldr"],
     },

     

    You will need to amend the device, configFiles, and frequency. This will create a SWO terminal with SWO output. You may need to change the path to the OpenOCD binary. You can add multiple decoders, but I have only used it for ASCII output.
    Explorer
    June 13, 2025

    Thanks a lot!
    I can confirm the works with STM extension 2.1.1. on Mac.
    And its crucial to set the right cpu frequency. Otherwise the SWO console records nothing.