SEGGER RTT STDIO Driver for Pico-SDK

This add-on module for the Raspberry Pi Pico SDK adds support for using SEGGER RTT as an STDIO driver.

The main advantages of RTT over semihosting are the speed of data transfer and not halting execution. RTT is widely implemented in many debuggers, including OpenOCR. Read more about SEGGER RTT here.

Usage

The code for the stdio_rtt implementation is quite simple and copies the structure of the other STDIO drivers. Until this PR is merged, you need to add this repo into your project directory to use the RTT driver:

$ git clone git@github.com:anaoum/pico-stdio-rtt.git lib/pico-stdio-rtt

Alternatively, you can add this repo as a submodule:

$ git submodule add git@github.com:anaoum/pico-stdio-rtt.git lib/pico-stdio-rtt

Then, in your CMakeLists.txt file, add the subdirectory and link the library to your target:

add_subdirectory("lib/pico-stdio-rtt")

target_link_libraries(${target}
    ...
    pico_stdio_rtt
)

In your initialisation code, you will need to call stdio_rtt_init:

#include "pico/stdio_rtt.h"

int main()
{
    stdio_rtt_init();
    ...

Then, throughout your code you can simply make calls to the standard input/output functions such as printf or puts:

    printf("Hello, World!\n");

Example

To build the included example, run:

$ cmake -B example/build -S example
$ make -C example/build

This will generate binary files:

  • example/build/hello_world.elf
  • example/build/hello_world.bin
  • example/build/hello_world.hex
  • example/build/hello_world.uf2

Flash one of these to your pico using your preferred method. Then connect your J-Link probe to the pico and run JLinkRTTViewer: JLinkRTTViewer output from example code