The MCU-Link is a small and inexpensive $10 CMSIS-DAP debug probe from NXP. It can work with OpenOCD, but has better target support using the NXP LinkServer which implements a gdb server. This makes it an ideal combination for scripting or automated testing.
Outline
The MCU-Link is a small and inexpensive CMSIS-DAP debug probe from NXP. In addition to the debug interface it includes a USB-CDC-2-UART bridge.
With VS Code, there are basically two different choices of debug extensions for the MCU-Link: cppdbg in the CppTools from Microsoft and Cortex-Debug from marus25. The Cortex-Debug extension implements debug support for different debug probes, including support for RTT. As the Cortex-Debug probe does not include a template for the MCU-Link, I worked on a launch.json for it. In side the NXP extension, the MCU-Link debug probe is supported through a cppdbg connection (which has been extended and is not standard). But it is possible to use the MCU-Link with a a standard cortex-debug extension, what the topic is of this article.
I have posted the example on GitHub.
LinkServer with Cortex-Debug
In Cortex-Debug, you can select from a range of different debug probes (pyOCD, J-Link, OpenOCD, …). The LinkServer is not part of that list (yet?), but it is easy to set it up as an ‘external’ debug probe. The downside is that for an external debug probe you have to launch the gdb server manually.
One way is to do this with a VS Code task, defining the following in .vscode/tasks.json:
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "start LinkServer",
"command": "${LINKSERVER_PATH}/LinkServer gdbserver --keep-alive LPC55S16:LPCXpresso55S16",
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": false
}
}
]
}
gdbserver
starts the gdb server, --keep-alive
keeps it running after a debug session has finised, and LPC55S16:LPCXpresso55S16
specifies the device and board. With the parameter --keep-alive
I only have to start the server once.
Another way is to launch the server on the console or terminal of VS Code:
.vscode/launch.json
To debug my target, I have the following launch.json
file in VS Code:
{
"name": "LPC55S16 Blinky LinkServer cortex-debug",
"type": "cortex-debug",
"request": "launch",
"servertype": "external",
"gdbTarget": "localhost:3333",
"cwd": "${workspaceFolder}",
"executable": "${command:cmake.launchTargetPath}",
"armToolchainPath": "${env:TOOLCHAIN_PATH}", // needed for the gdb
"postLaunchCommands": [
"monitor semihosting enable"
],
"runToEntryPoint": "main", // or "ResetISR"
"rtos": "FreeRTOS",
"svdFile": "./sdk/device/LPC55S16.svd",
},
- name: description of the launch configuration.
- type: using Cortex-Debug extension.
- request: launching, programming debugging the application.
- servertype: using external gdb server.
- gdbtarget: IP and port number of GDB server.
- cwd: current working directory.
- executable: the ELF/Dwarf file to launch. I’m using here the target file (.elf) as specified in the CMake file.
- armToolchainPath: Path where the arm-none-eabi-gdb executable is located.
- postLaunchCommands: debugger commands executed after launching the binary. Here I enable semihosting in LinkServer with a monitor command.
- runToEntryPoint: if I want to stop the target on a function.
- rtos: using FreeRTOS.
- svdFile: path to the CMSIS-SVD file with the register information.
Debugging
With this launch.json, I can debug my target with LinkServer and Cortex-Debug:
Semihosting
As seen above, I have enabled semihosting for LinkServer in the launch.json. The linkserver reports the port used as 4444:
INFO: Connected to core cm33 INFO: Disconnected from core cm33 Gdbserver on port 3333 has closed GDB server listening on port 3333 in debug mode (core cm33) Semihosting server listening on port 4444 (core cm33) INFO: Connected to core cm33
In VS Code, I can open a serial monitor to see the output or enter text:
Happy debugging 🙂
Links
- Example on GitHub: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/VisualStudioCode/LPC55S16-EVK/LPC55S16_Blinky
- New MCU-Link Debug Probe from NXP
- Laser-cut MCU-Link Pro Enclosure for the Masses
- VS Code: Debugging
- Using Legacy Devices with LinkServer
- LinkServer Scripting, and how to Recover MCUs with a Script
I heard Blackmagic probes are the best, they include built in gdb server, no need for openocd,
and they can be programmend onto cheap hw.
LikeLike
I own a BlackMagic probe, but was not able to get it up and running for most devices: https://mcuoneclipse.com/2019/06/23/black-magic-open-source-debug-probe-for-arm-with-eclipse-and-gdb/
I have not tried it any more since then. Not sure if the situation is better now.
LikeLike