pico-sdk icon indicating copy to clipboard operation
pico-sdk copied to clipboard

Add support for SEGGER RTT STDIO

Open anaoum opened this issue 3 years ago • 4 comments

Fixes #774

This PR adds support for using SEGGER RTT as an STDIO driver.

The code for the stdio_rtt implementation is quite simple and copies the structure of the other STDIO drivers. RTT support can be enabled in the same way as the other STDIO drivers, simply add pico_enable_stdio_rtt(${TARGET_NAME} 1) to your CMakeLists.txt and call stdio_init_all() in your initialisation code.

The official SEGGER_RTT code is included in the lib directory (the latest version, V762c). I have copied all files exactly as-is, despite many of the files being unnecessary/code samples/etc. I did this to make updates to newer versions more simple (just overwrite the entire directory with the latest version). Unfortunately SEGGER does not distribute this code as a git repo which could have been included as a submodule.

Happy to make improvements/adjustments to this implementation based on feedback.

anaoum avatar Mar 30 '22 23:03 anaoum

Why don't you re-package the Segger code as a git repository yourself (or clone (and update?) https://github.com/PromyLOPh/rtt)?

Did you ask them to please publish their code to github?

smurfix avatar May 04 '22 09:05 smurfix

I find the problem with third parties hosting a clone of the official code is that they become out of date very quickly. To be fair, this problem would be the same by keeping the code copy in the pico-sdk, so I'm not sure what the best solution is...

The version you linked is 5 years old. I found another repo that seems to do a better job of keeping the code up to date: https://github.com/adfernandes/segger-rtt. I am happy to update my PR to use this third-party repo, but I would also like a maintainer of this project to chime in and advise what approach would most likely get merged.

I emailed SEGGER this morning to see if they would consider publicly hosting the code on a git repo.

anaoum avatar May 04 '22 21:05 anaoum

I was just searching for something else, but i think they already have the RTT source code on GitHub. Didn't checked if the version is the newest one (they always change the header on a release, but code often doesn't have any changes)

https://github.com/SEGGERMicro/RTT

Hope i could help a little bit

PhilippHaefele avatar Jun 24 '22 20:06 PhilippHaefele

FYSA I keep the unmodified RTT sources maintained and properly tagged here: https://github.com/adfernandes/segger-rtt (been doing it for a while)

I'm reasonably certain that Segger doesn't "maintain" any release of RTT outside of the JLink releases. Other projects that Segger does follow, like the Zephyr RTOS from the Linux Foundation, use relatively old libraries, too.

The attitude, much like the SEGGERMicro repository linked above, is to do a code dump "once in a while", ignoring bugfix and patches.

So about once a month (waves hands in the air) I download the latest Segger JLink software distribution and upload to my repository.

adfernandes avatar Jul 28 '22 01:07 adfernandes

This PR has been added to the 1.6.0 milestone. Anything speaking against merging this into develop in the not too far future?

rgrr avatar Mar 11 '23 10:03 rgrr

FWIW, I just pushed Version V7.86h (2023-04-12) to my unmodified, pristine mirror of Seggger's RTT distribution.

Segger's release notes are usually pretty complete, and there were some minor changes to to RTT backend in recent history.

@anaoum I would ask (please!) that the most recent-possible RTT sources, like mine from above, be merged into the Pico SDK since this can make a difference as the debuggers and protocol (slowly) evolve!

adfernandes avatar Apr 16 '23 17:04 adfernandes

This PR has been added to the 1.6.0 milestone. Anything speaking against merging this into develop in the not too far future?

I think we would want to avoid copying a bunch of Segger code into this repo... so would prefer to build with code from a submodule and have that submodule be optional

kilograham avatar May 26 '23 14:05 kilograham

@kilograham, I agree with your "use a submodule" sentiment 100%

The issue is that there is no official source, as far as I know, RTT repository - that's why I maintain this, which is very carefully exactly what Segger distributes.

@anaoum, if you agree, I'd be happy to rework your PR to use a submodule...

adfernandes avatar May 31 '23 03:05 adfernandes

@anaoum, if you agree, I'd be happy to rework your PR to use a submodule...

no objection from me. I would have done it myself but am quite time poor at the moment.

anaoum avatar May 31 '23 20:05 anaoum

(ping @kilograham and @anaoum)

Superseded by #1411

adfernandes avatar Jun 04 '23 05:06 adfernandes

@kilograham, I have vendored in RTT and removed the submodule.

However, no matter what I do, I cannot apply the compiler flags.

set_source_files_properties(SEGGER/RTT/SEGGER_RTT.c
    PROPERTIES COMPILE_OPTIONS "-Wno-cast-qual;-Wno-cast-align")

You'll see that I have

include(CMakePrintHelpers)

cmake_print_properties(
    SOURCES SEGGER/RTT/SEGGER_RTT.c
    PROPERTIES COMPILE_OPTIONS
)

and cmake does appear to apply those properties, but ... they're not in the actual compile commands, and the build fails.

Any idea what might be wrong?

adfernandes avatar Jun 07 '23 05:06 adfernandes

You'll have to specify the full path to the source file for set_source_files_properties to take effect.

peterharperuk avatar Jun 07 '23 07:06 peterharperuk

I pushed my suggested changes that seem to fix the issue - hope that was ok

peterharperuk avatar Jun 07 '23 08:06 peterharperuk

question: why don't you put the SysView files into the SEGGER subdirectory. Those are part of the more or less generic RTT support and would allow a user to easyly integrate SysView support.

rgrr avatar Jun 07 '23 19:06 rgrr

closed in favor of #1411

kilograham avatar Jun 07 '23 19:06 kilograham