Allow printing defmt output to the RTT console - #880
Conversation
xoviat
commented
May 17, 2023
Oh, and defmt-print must be installed for this to work. Maybe add a tooltip for that? |
xoviat
commented
May 25, 2023
@haneefdm Do you have questions about this? |
haneefdm
commented
Sep 1, 2023
Thank you for the PR and I agree it will be very useful for Rust developers Before I look at it, I have a request. I need an example project available on github for me to begin looking at it. It will be my test case as well. Your github example project should be ready to run with minimal effort on my part (preferably on a Mac). I cannot accept what I cannot test. I am not Rust-educated either. I you can also update the source code to add a reference to the example github then that would be nice. Sorry, it took me a long time to get to it. Personal health reasons. |
| super(tcpPort, channel); | ||
| this.cwd = wsPath; | ||
| this.executable = Path.relative(wsPath, executable); |
There was a problem hiding this comment.
@haneefdm I checked the source of defmt and probe-rs. This is because by default, defmt's message is compressed. The detailed info is stored in .elf file, that's why the executable is needed: without .elf, the message cannot be parsed.
See https://github.com/knurling-rs/defmt/blob/main/decoder/src/lib.rs#L157 . The Table is what's stored in .elf file
haneefdm
commented
Sep 1, 2023
I lied. I did a cursory review. I don't know what is going on with the And, then in the constructor of the Also, I think that the |
xoviat
commented
Sep 3, 2023
I'll get back to this in a few days. I need to refresh my memory after taking care of some other stuff. |
HaoboGu
commented
Jan 23, 2024
Any updates? I got the same problem, cortex-debug cannot print defmt's RTT log |
hazer-hazer
commented
Mar 5, 2024
Installed extension from this PR, everything works perfectly, except vscode does not hint to set |
haneefdm
commented
Jul 6, 2024
@xoviat I am still waiting for the PRs original author. |
romancardenas
commented
Oct 24, 2024
Any news here? Can I help with any blocker? |
wrs
commented
Dec 25, 2024
For those waiting on this, I wrote a comment on the old issue explaining how to get defmt working with the released cortex-debug. |
tpilt
commented
Feb 8, 2025
Looking very much forward to this!
This is now further simplified by 'tcp' parameter on defmt-print: |
newcomertv
commented
Feb 10, 2025
So the blocker is this? :
I think OP is gone. Not a TS dev though if this is the only thing I can maybe have a look and file a PR that can get merged. |
GreenCappuccino
commented
Apr 10, 2025
Hello all, Using the (newer?) "rttConfig": {
"enabled": true,
"address": "auto",
"decoders": [
{
"type": "advanced",
"decoder": "./rtt-defmt.js",
"config": {
"cwd": "${workspaceRoot}",
"executable": "./target/thumbv8m.main-none-eabihf/debug/interchange",
},
"label": "RTT",
"port": 0,
"ports": [0]
},
]
},Where I've written an implementation constChildProcess=require('child_process');constPath=require('path');constvscode=require('vscode');classDefmtDecoder{constructor(){this.config={};this.displayOutput=()=>{};this.graphData=()=>{};this.process=null;}init(config,displayOutput,graphData){this.config=config;this.displayOutput=displayOutput;this.graphData=graphData;this.cwd=config.config.cwd||process.cwd();if(!config.config.executable){thrownewError(JSON.stringify(config));}this.executable=Path.resolve(this.cwd,config.config.executable);this.process=ChildProcess.spawn('defmt-print',['-e',this.executable],{cwd: this.cwd});this.process.stdout.on('data',(data)=>{this.displayOutput(data.toString());});this.process.stderr.on('data',(data)=>{this.displayOutput(`stderr: ${data.toString()}`);});this.process.on('error',(error)=>{this.displayOutput(`Error: ${error.message}\n`);});}softwareEvent(_port,data){if(!this.process||!this.process.stdin){if(this.outputChannel){this.displayOutput('Error: defmt-print process is not running.\n');}return;}letbufferInput=Buffer.isBuffer(data) ? data : Buffer.from(data);this.process.stdin.write(bufferInput);}outputLabel(){returnthis.config.label;}typeName(){return'defmt-print';}}module.exports={default: DefmtDecoder};I have a solution that I prefer, where a new output channel (in this case named The implementation, when initialized, creates a new |
rhuys
commented
Jun 14, 2026
I have the same problem. |
haneefdm
commented
Jun 14, 2026
Built-in RTT with dfmt-print is coming. This extension is getting a rewrite. Don't want to disturb cortex-debug in a major way as it is used in production by many people. The new extension will be available soon for download here (alpha) and then Beta in the Marketplace. It will be bit of a journey. https://github.com/mcu-debug/mcu-debug For now, it is best to use the solution by @GreenCappuccino |
rhuys
commented
Jun 25, 2026
@GreenCappuccino thanks for your solution, it works, |
defmt is widely used as a logger in the rust embedded ecosystem. This allows seamlessly debugging a rust program while printing defmt output at the same time.