Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

west: Add west rtt command #75508

Merged
merged 3 commits into from
Sep 10, 2024
Merged

west: Add west rtt command #75508

merged 3 commits into from
Sep 10, 2024

Conversation

topisani
Copy link
Contributor

@topisani topisani commented Jul 5, 2024

Implemented in the pyocd and openocd runners while awaiting some feedback.

This command runs separately from a debug session. We should probably also support attaching a rtt client to a running debugserver. However, this might work differently for each runner. pyocd is easy, as it supports a separate RTT command, while openocd and jlink will always need a running server.

See the FIXME's for other points i would like input on.

@MarkoSagadin
Copy link
Contributor

This would be really awesome to have. For our internal processes I created a wrapper around JLinkExeRTTViewer so we could have a single command that does that.

How would enabling a running server be implemented in the case of JLink? As a separate command or an additional flag to the west flash command?

@topisani
Copy link
Contributor Author

topisani commented Jul 5, 2024

How would enabling a running server be implemented in the case of JLink? As a separate command or an additional flag to the west flash command?

I think the two possible approaches, of which we should maybe do both as separate commands, are:

  1. west rtt -r openocd will run the openocd server just like west debugserver does, and attach an rtt client to it.
  2. west rtt -r openocd requires you to run west debugserver in another terminal and connects to that.

The first approach is easy, when all you want is to see the log, but the second is more flexible and compatible with the other debug/debugserver/attach commands.

@MarkoSagadin
Copy link
Contributor

I think that second approach makes sense, like you said, it is compatible with other commands.

Two things:

  1. Is explicit -r openocd flag needed always? Or just in this PR? I would expect that I can just run west rtt regardless of the runner, if the default one support this, of course.
  2. What about if the west rtt command checks if there is a running server (by checking known ports maybe?) and creates a new one (like suggested in your first case) if none is found? This would then support the easy use case that you describe. So something like:
    west build -b <some_board> && west flash && west rtt
    

@topisani
Copy link
Contributor Author

topisani commented Jul 5, 2024

1. Is explicit `-r openocd` flag needed always? Or just in this PR? I would expect that I can just run `west rtt` regardless of the runner, if the default one support this, of course.

No, i just always use it, because the default runner is usually not what i want

2. What about if the `west rtt` command checks if there is a running server (by checking known ports maybe?) and creates a new one (like suggested in your first case) if none is found? This would then support the easy use case that you describe.  So something like:

I consideren this option, but i think its nicer to have it either as a separate command, or as an argument. Connecting to arbitrary ports when not asked to is probably a no go. Besides, consistent behavior seems preferable

scripts/west_commands/runners/openocd.py Outdated Show resolved Hide resolved
scripts/west_commands/runners/openocd.py Outdated Show resolved Hide resolved
scripts/west_commands/runners/openocd.py Outdated Show resolved Hide resolved
scripts/west_commands/runners/pyocd.py Outdated Show resolved Hide resolved
scripts/west_commands/runners/openocd.py Outdated Show resolved Hide resolved
@pdgendt
Copy link
Collaborator

pdgendt commented Aug 22, 2024

Looks very neat BTW

pdgendt
pdgendt previously approved these changes Sep 10, 2024
@topisani
Copy link
Contributor Author

LMK if i should have pushed this latest commit to a different PR, now that this had been partially approved. I just thought id better get this jlink support in along with the rest.

jlink support is implemented in much the same way as openocd, except it can better automatically locate the rtt block, so it relies on that.

Copy link
Member

@fabiobaltieri fabiobaltieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, second commit message is stale I guess, feel free to update it.

@topisani
Copy link
Contributor Author

Cool, second commit message is stale I guess, feel free to update it.

Any objections to me just squashing all three commits?

@fabiobaltieri
Copy link
Member

Any objections to me just squashing all three commits?

Yes, don't. :-) Just reword the second commit message, the rest is fine as it is.

This command runs separately from a debug server, instead of attaching
to a running server. This is both the easiest out of the box experience,
and also should be possible to implement consistently for most runners.

This commit includes an initial implementation for pyocd.

Signed-off-by: Tobias Pisani <[email protected]>
This was non-trivial, as openocd is a bit weird to work with. Using only
commands passed with '-c' arguments, I couldn't get it to reliably resume
(or just not halt) the target when started. I tried using the 'sleep'
command, and various 'configure -event XX { resume }' events, but nothing
panned out, as it seems to always halt after all `-c` commands have been
run.

To avoid that, this waits for the TCL RPC port to be up, and sends a
resume command there. This works reliably.

Signed-off-by: Tobias Pisani <[email protected]>
Moves the telnet client into runners/core.py as well, as this is now shared
between openocd and jlink.

Signed-off-by: Tobias Pisani <[email protected]>
@topisani
Copy link
Contributor Author

alright, reworded and reordered, apparently i had swapped the first two commits somewhere along the way

@nashif nashif merged commit 73c8235 into zephyrproject-rtos:main Sep 10, 2024
32 checks passed
@pdgendt
Copy link
Collaborator

pdgendt commented Sep 10, 2024

A follow-up PR to add this to the documentation would be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: West West utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants