Electronics > Microcontrollers
Debug from VS Code to a remotely located J-Link
(1/1)
longh:
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 command
JLinkGDBServer -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_Server
I've started by connecting the J-Link over USB to a Raspberry pi, then making a tunnel with
JLinkRemoteServerCLExe -UseTunnel -TunnelByName <name_of_tunnel> -TunnelPW <password>
And I can even connect to it with the JLinkGDBServer command line on my laptop
JLinkGDBServer -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
longh:
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
longh:
Maybe I spoke too soon, this doesn't seem to work reliably.
__george__:
The J-Link server has a no-timeout option:
https://wiki.segger.com/J-Link_GDB_Server#-notimeout
It seems that by default it timeouts after 5 seconds so what you see probably makes sense.
Navigation
[0] Message Index
Go to full version