Debug from VS Code to a remotely located J-Link - Page 1
Forum section: electronics / general

author: longh
author_rank: Contributor
timestamp: March 28, 2024, 05:57:55 pm
content: Hey All,I've been debugging a Cortex M4 micrcocontroller using a J-Link probe connected over USB and the cortex debug plugin for VS Code. I like it a lot, but the launch.json file still confuses me. As does the interaction between all the J-Link command line utilities and VS Code.For the J-Link connected locally over USB, I can use this in my launch.json{"name" : "JLink: debug over usb","cwd" : "${workspaceFolder}","request" : "launch","type" : "cortex-debug","servertype" : "jlink","executable" : "${workspaceFolder}/build/app.elf","interface" : "swd","device" : "Cortex-M4","runToEntryPoint" : "main","svdFile" : "scripts/my.svd",},And it looks like this is causing the commandJLinkGDBServer -singlerun -nogui -if swd -port 50000 -swoport 50001 -telnetport 50002 -device Cortex-M4 to be run behind the scenes, and I guess VS Code connects to this GDB server?It would be great if I could debug something in my home network, while out and about. Looks like it is possible:https://wiki.segger.com/J-Link_Remote_ServerI've started by connecting the J-Link over USB to a Raspberry pi, then making a tunnel withJLinkRemoteServerCLExe -UseTunnel -TunnelByName <name_of_tunnel> -TunnelPW <password>And I can even connect to it with the JLinkGDBServer command line on my laptopJLinkGDBServer -singlerun -nogui -if swd -port 50000 -swoport 50001 -telnetport 50002 -device Cortex-M4 -select "ip=tunnel:<name_of_tunnel>:<password>"But the launch.json I've tried doesn't work, it says failed to launch GDB server: Timeout. But it seems close to working!{"name" : "REMOTE: JLink","cwd" : "${workspaceFolder}","request" : "launch","type" : "cortex-debug","servertype" : "jlink","executable" : "${workspaceFolder}/build/app.elf","device" : "Cortex-M4","runToEntryPoint" : "main","ipAddress" : "tunnel:<name_of_tunnel>:<password>","svdFile" : "scripts/my.svd",},Kind of a weird obscure question, but maybe someone understands how J-Link software works better than I do.Thanks!-Hunter

author: longh
author_rank: Contributor
timestamp: March 28, 2024, 06:18:57 pm
content: I think I got it working! For posterity's sake I'll post what I did here:First on the Pi where the J-Link is connected over USB I run:$ JLinkRemoteServerCLExe -UseTunnel -TunnelByName <tunnel_name> -TunnelPW <tunnel_password>Then on my laptop at a coffee shop I run the command:$ JLinkGDBServer -singlerun -nogui -if swd -port 50000 -swoport 50001 -telnetport 50002 -device Cortex-M4 -select "ip=tunnel:<tunnel_name>:<tunnel_password>"Then I add this to my vs code launch.json:{"name": "tunnel to j-link","type": "cortex-debug","request": "launch","executable": "${workspaceFolder}/build/app.elf","cwd": "${workspaceFolder}","servertype": "external","interface": "swd","gdbTarget": "localhost:50000","showDevDebugOutput": "raw","runToEntryPoint" : "main",},And then when I click debug, it works! Like magic.I still don't understand why I have to start GDB from the command line first, I think it is because it takes longer and VS Code times out or something.-Hunter

author: longh
author_rank: Contributor
timestamp: March 28, 2024, 06:33:40 pm
content: Maybe I spoke too soon, this doesn't seem to work reliably.

author: __george__
author_rank: Contributor
timestamp: April 01, 2024, 08:30:44 pm
content: The J-Link server has a no-timeout option:https://wiki.segger.com/J-Link_GDB_Server#-notimeoutIt seems that by default it timeouts after 5 seconds so what you see probably makes sense.