Skip to main content
Associate II
Solved

How to select a specific STLInk for debugging in VSCode

I have multiple STLinks on multiple Nucleo boards.  I can debug only if I connect one at a time, but it is tedious to connect and reconnect to switch boards. When I plug in multiple devices I see them listed (bottom left) but I can’t work out how to select a specific STLink to use.  If I try to debug it fails with a “bound doStepConnectToTarget Failed: could not connect: Operation timed out.” and suggests I open launch.json.

Disconnecting the cables is additionally tedious because I’m using the VCP on each, and disconnecting breaks the connection to the terminals, which then all need to be reconnected.

I know that with the stand-alone STM32CubeIDE it possible to have separate configurations for each STLink (defined by Serial ID) and then I select the one to use as needed, without having to disconnect any hardware (and the VCPs for the devices I’m not debugging stay connected).

Is there a way to specify the STLink serial ID to use in the launch.json file?  In VSCode I notice there is a button to copy the Serial ID to the clipboard - but how do I use that?

There’s a Knowledge base article here  by ​@Nawres GHARBI  but there is no mention of the STLink Serial ID. Maybe there is another way to do this?

I’m using this launch configuration that was auto generated:

    "configurations": [
{
"type": "stlinkgdbtarget",
"request": "launch",
"name": "STM32Cube: Launch ST-Link GDB Server",
"origin": "snippet",
"cwd": "${workspaceFolder}",
"preBuild": "${command:st-stm32-ide-debug-launch.build}",
"runEntry": "main",
"imagesAndSymbols": [
{
"imageFileName": "${command:st-stm32-ide-debug-launch.get-projects-binary-from-context1}"
}
]
}
]


I’m on macOS, and using two NUCLEO-F303K boards and two NUCLEO-H7S3L8 boards. VSCode 1.123.1 and STM32CubeIDE for VSCode v3.9.0

Nawres GHARBI
Nawres GHARBIBest answer
ST Technical Moderator

Hi ​@SJB 

The only way is to use the Serial ID. 

As you said before, copy it using the copy ID button then add this parameter in the launch file 
"serverSerialNumber": "Copied_Serial_ID_from_button",              

4 replies

Andrew Neil
Super User

with the stand-alone STM32CubeIDE it possible to have separate configurations for each STLink (defined by Serial ID) 

 

Indeed it is - and that is an invaluable feature!

I don’t use VSCode yet, but not being able to do this would be a major blocking issue for me!

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Nawres GHARBI
Nawres GHARBIBest answer
ST Technical Moderator

Hi ​@SJB 

The only way is to use the Serial ID. 

As you said before, copy it using the copy ID button then add this parameter in the launch file 
"serverSerialNumber": "Copied_Serial_ID_from_button",              

SJBAuthor
Associate II

​@Nawres GHARBI  Thank you. That now works for me. I now have two separate configuration in launch.json that I can select from the drop-down box in the Debug tab.

BTW, I would never have guessed that that setting name. I did try ‘serialID’ as that's what it’s called when it’s copied.  Also tried targetID and serialNumber based on some googling.   Maybe it's obvious when you know.

Could I suggest an update of your useful Knowledge base article, as I’m sure its not an unusual to have multiple ST-Links connected.

Nawres GHARBI
ST Technical Moderator

STM32CubeIDE for VS Code debug configuration (launch.json) | Community

 

but I didn’t describe all the parameters. You can type in the launch.json “server” and in the help popup will show you all the parameters related to your debugger with a little description