NXP MCU-Link for Rust with probe-rs

The Rust programming language is making its way into the embedded world, and getting more and more popular and not only at the Lucerne University. With Rust, the probe-rs is one of the popular debug choices, as it nicely comes with cargo. On the hardware side, the NXP MCU-Link is $15 debug probe hardware I use for many targets. Why not using the MCU-Link with probe-rs and Rust?

MCU-Link Board Top Side
MCU-Link Board Top Side

Outline

With Visual Studio Code and Rust for embedded, probe-rs is probably the most popular choice. While it works well with cortex-debug too, I really like the probe-rs features and cli support to flash the target, or that it supports SEGGER RTT.

MCU-Link Debug probe with custom enclosure (see Different Laser-Cut Enclosures for the MCU-Link)

Installation

probe-rs installation is very simple and easy, just run

cargo install probe-rs --features cli

For the MCU-Link debug probe, install the latest LinkServer software and have the probe firmware updated as CMSIS-DAP debug probe. See LinkServer for Microcontrollers and New MCU-Link Debug Probe from NXP about updating the firmware. I’m using in this article MCU-LINK_CMSIS-DAP_V3_133.s19.

Usage with probe-rs

With

probe-rs list

it should list the NXP MCU-Link debug probe:

[0]: MCU-LINK (r0FF) CMSIS-DAP V3.133 (VID: 1fc9, PID: 0143, Serial: GNENQG0AQTDWK, CmsisDap)
list probes

Using cargo

To flash the application using cargo, use probe-rs in .cargo/config.toml, for example with:

runner = "probe-rs run --chip RP2040 --protocol swd"
cargo runner

With this I can use:

cargo run

to flash and run the application:

Running probe-rs run --chip RP2040 --protocol swd target\thumbv6m-none-eabi\debug\rp2040-project-template
Erasing ✔ [00:00:00] [#####################################################################] 12.00 KiB/12.00 KiB @ 75.96 KiB/s (eta 0s ) Programming ✔ [00:00:00] [#####################################################################] 12.00 KiB/12.00 KiB @ 58.35 KiB/s (eta 0s ) Finished in 0.384s

INFO Program start
└─ rp2040_project_template::__cortex_m_rt_main @ src\main.rs:27
INFO on!
└─ rp2040_project_template::__cortex_m_rt_main @ src\main.rs:67
INFO off!

Debugging with VS Code

Below is an example launch configuration, both for probe-rs and cortex-debug:

// The format of this file is specified in https://probe.rs/docs/tools/vscode/#start-a-debug-session-with-minimum-configuration
{
"version": "0.2.0",
"configurations": [
{
"preLaunchTask": "rust: cargo build",
"type": "probe-rs-debug MCU-Link",
"request": "launch",
"name": "myProject",
"cwd": "${workspaceFolder}",
"chip": "rp2040",
"connectUnderReset": false,
"speed": 4000,
"runtimeExecutable": "probe-rs",
"runtimeArgs": [
"dap-server"
],
"flashingConfig": {
"flashingEnabled": true,
"resetAfterFlashing": true,
"haltAfterReset": true,
},
"coreConfigs": [
{
"coreIndex": 0,
"programBinary": "target/thumbv6m-none-eabi/debug/rp2040-project-template",
"chip": "RP2040",
"rttEnabled": true,
"options": {
"env": {
"DEFMT_LOG": "debug"
}
},
}
],
"consoleLogLevel": "Info", //Error, Warn, Info, Debug, Trace
"wireProtocol": "Swd"
},
{
"name": "MCU-Link cortex-debug",
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"serverpath": "${env:OPENOCD_PATH}/openocd",
"serverArgs": [
"-c adapter speed 5000",
"-c set USE_CORE 0",
],
"cwd": "${workspaceRoot}",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/project",
"armToolchainPath": "${env:PICO_TOOLCHAIN_PATH}",
"device": "RP2040",
"configFiles": [
"interface/cmsis-dap.cfg",
"target/rp2040.cfg"
],
"runToEntryPoint": "main",
"postLaunchCommands": [
"monitor arm semihosting enable",
],
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
"rttConfig": {
"enabled": false,
"address": "auto",
"decoders": [
{
"label": "",
"port": 0,
"type": "console"
}
]
},
"showDevDebugOutput": "none",
}
]
}

With this, I can debug Rust applications with the NXP MCU-Link and probe-rs in VS Code:

Trouble Shooting

If you get something like this:

ERROR nusb::platform::windows_winusb::enumeration: Failed to get DeviceInterfaceGUIDs from registry: The system cannot find the file specified. (os error 2)    
Error: Failed to open the debug probe.

Check the USB driver/devices e.g. with the USB Driver Tool. It should look like this:

NXP MCU-Link USB Devices

Otherwise, re-installing the driver with the above tool usually solves the problem.

Summary

The NXP MCU-Link debug probe not only works for C/C++ applications, but can be easily used for Rust based applications. For C/C++ applications I’m mostly using the cortex-debug VS Code extension. Probe-rs nicely works with a Rust environment, and with the NXP MCU-Link I have a universal, fast and inexpensive debug probe, working with extensions like cppdbg, cortex-debug and now probe-rs.

Happy rusting 🙂

Links

6 thoughts on “NXP MCU-Link for Rust with probe-rs

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.