Skip to content

Allow defmt-print to connect to a TCP port.#757

Merged
Urhengulas merged 14 commits intoknurling-rs:mainfrom
hydra:defmt-print-tcp
Jun 12, 2023
Merged

Allow defmt-print to connect to a TCP port.#757
Urhengulas merged 14 commits intoknurling-rs:mainfrom
hydra:defmt-print-tcp

Conversation

@hydra
Copy link
Copy Markdown
Contributor

@hydra hydra commented May 30, 2023

Why: The Segger J-Link debugger sessions listen on TCP port 19021 by default and it dumps RTT output to any client that connects to the port.

This allows defmt-print to log data so you can see it in real-time while you are debugging in your IDE.

example:

$ defmt-print tcp --host=127.0.0.1 --port=19021

Output from --help is now:

Prints defmt-encoded logs to stdout

Usage: defmt-print.exe [OPTIONS] -e <ELF> [COMMAND]

Commands:
  stdin
  tcp
  help   Print this message or the help of the given subcommand(s)

Options:
  -e <ELF>
      --json
      --show-skipped-frames
  -v, --verbose
  -V, --version
  -h, --help                 Print help

Default subcommand is std-in for backwards compatibility.

The host and port can read from your environment variables RTT_HOST and RTT_PORT respectively.

$ defmt-print tcp --help
Usage: defmt-print.exe -e <ELF> tcp --host <HOST> --port <PORT>

Options:
  -h, --host <HOST>  [env: RTT_HOST=]
  -p, --port <PORT>  [env: RTT_PORT=]
  -h, --help         Print help
C:\> set RTT_HOST=127.0.0.1
C:\> set RTT_PORT=19021

or

$ export RTT_HOST=127.0.0.1
$ export RTT_PORT=19021

Once environment variables are set they are shown and used appropriately.

$ defmt-print tcp --help
Usage: defmt-print.exe -e <ELF> tcp --host <HOST> --port <PORT>

Options:
  -h, --host <HOST>  [env: RTT_HOST=127.0.0.1]
  -p, --port <PORT>  [env: RTT_PORT=19021]
  -h, --help         Print help
$ defmt-print -e <elf> tcp
...

J-Link console:
image

CLion debug session of the target:
image

defmt-print output:
image

This is a replacement PR for #676
EDIT: I updated the examples to show the 0.3.7 output, the original comment previously had the 0.3.2 output

@hydra
Copy link
Copy Markdown
Contributor Author

hydra commented May 30, 2023

This also works with OpenOCD

example GDB commands:

monitor rtt setup 0x24008000 8192 "SEGGER RTT"
monitor rtt polling_interval 5
monitor rtt start
monitor rtt server start 8765 0
defmt-print -e <elf> tcp --host localhost --port 8765

Segger J-Link debugger sessions listen on TCP port 19021 by default and dump RTT output to any client that connects to the port.

This allows defmt-print to log data WHILE you are debugging in your IDE.

example:
```
defmt-print tcp --host=127.0.0.1 --port=19021
```

The host and port can read from your environment variables `RTT_HOST` and `RTT_PORT` respectively.
@hydra hydra force-pushed the defmt-print-tcp branch from fb8b7e8 to 13487e2 Compare May 30, 2023 08:23
@hydra
Copy link
Copy Markdown
Contributor Author

hydra commented May 30, 2023

Changelog updated and cargo fmt suggestions applied.

@Urhengulas
Copy link
Copy Markdown
Member

@hydra I added a few changes. Let me know what you think.

And can you please test it as well? I don't have the J-Link debugger set up.

@hydra
Copy link
Copy Markdown
Contributor Author

hydra commented Jun 5, 2023

@Urhengulas will test hopefully later today and get back to you.

@hydra
Copy link
Copy Markdown
Contributor Author

hydra commented Jun 5, 2023

Ok @Urhengulas so I did a review of your comments and everything 'looks' ok, but didn't work with my saved 'external tools' configuration in IntelliJ that I've been using since I did the original PR.

The issue is with commit 8b60a4c -> "Switch from String to IpAddr"

Where things go wrong is like this:

$ defmt-print.exe -e target/thumbv7em-none-eabihf/release/nucleoh743zi2 tcp --host localhost --port 8765
error: invalid value 'localhost' for '--host <HOST>': invalid IP address syntax

I have been supplying hostnames, not just IP address, on the command line. Usually you want it to work for both, especially for the use-case of an internet-connected J-Link or OpenOCD connected debugger that uses a DDNS hostname. You can also see this in one of my comments on this PR, here: #757 (comment)

Additional, commit a5348ec -> "Add default values" should probably be using 'localhost' instead of an IP address.

The actual functionality of reading frames over TCP works for me still when an IP address is used, e.g.

$ defmt-print.exe -e target/thumbv7em-none-eabihf/release/nucleoh743zi2 tcp --host 127.0.0.1 --port 8765
0 INFO  Reset
└─ startup::isr::reset_handler @ logging\src\tracing.rs:82

Not sure what to suggest at this point. Options:

  1. Merge original PR as-is. Add another PR for cleanups that still allow hostnames to be used later.
  2. Update this PR with additional commits that allow hostnames to be used again.
  3. Merge this PR as-is. Add another PR that allow hostnames to be used again.

I'm keen to get the basic functionality of reading defmt frames over TCP to be merged in, so perhaps 1 or 3 might be better depending on your availability/schedule?

@Urhengulas
Copy link
Copy Markdown
Member

Hostnames should work now. Can you please test again. If it does work we can merge it.

@hydra
Copy link
Copy Markdown
Contributor Author

hydra commented Jun 8, 2023

Hostnames should work now. Can you please test again. If it does work we can merge it.

Hi, I just grabbed the PR change, simpler than I thought it was going to be, nice!

It seems to work fine, no error message when using hostname on the command line now.

$ defmt-print.exe -e target/thumbv7em-none-eabihf/debug/config tcp --host localhost --port 8765
0 TRACE Config
└─ config::main @ src\bin\config.rs:39

LGTM!

@Urhengulas Urhengulas added this pull request to the merge queue Jun 12, 2023
Merged via the queue into knurling-rs:main with commit 8a45724 Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants