Use of SEGGER RTT for Monitoring

I saw there is some interest about SEGGER RTT so I thought I can summarize what I tried here.

SEGGER RTT or Real Time Transfer reads and writes data from memory instead of using Serial communication. This means you can use your Jlink or Stlink for monitoring/sending commands as well.

It should work with any ARM Cortex powered chip.
It initially required a Jlink debug probe but now works with stlink as well via openocd or some webusb implementations like jstlink.


  • You cannot flash and debug at the same time, you need to disconnect RTT
  • As your RTT viewer is polling the data, the data stays in the buffer until you pull it, but can be overwritten by the library if the buffer is full depending on how it’s set up

It’s really easy to use SEGGER RTT thanks to this library.
In my case I added this line to lib_deps in my platformio.ini file:

koendv/RTT Stream@^1.3.0

How to adapt your sketch:
You need to declare a RTT Stream and replace Serial by RTT in your code.

#include <RTTStream.h>
RTTStream rtt;
Commander command = Commander(rtt);
void setup(){


rtt.println(“Setup done!”);

Use with WebUSB
I successfully used this webapp for monitoring and sending commands to a b-g431b-esc1, I just needed to set commander with a different end of line character by initializing it this way:

Commander command = Commander(rtt,‘\r’);

Here is a video how it works.

Use with OpenOCD in Platformio
I created a file with the following content:

“RTT Start”,
“$PROJECT_PACKAGES_DIR/tool-openocd/bin/openocd” +
" -f interface/stlink.cfg" +
" -c "transport select hla_swd"" +
" -f target/stm32g4x.cfg" +
" -c init" +
" -c "rtt setup 0x20000000 10000 \"SEGGER RTT\""" +
" -c "rtt start"" +
" -c "rtt server start 9090 0""

This uses OpenOCD (see section 15.6) to:

  • Locate memory allocated to SEGGER RTT by searching for “SEGGER RTT” in RAM ( 10000 first bytes starting from address 0x20000000 )
  • Start a RTT server on port 9090

I added this to the platformio.ini file for setting up the Platformio terminal to read from this server, and handle commands properly:

extra_scripts =
monitor_port = socket://localhost:9090
monitor_filters = send_on_enter
monitor_eol = LF
monitor_echo = yes

Here is a video how it works.

Jlink tools
You can use the Jlink tools if you have one of the Jlink debug probes, but some of the original Stlink can also be converted with a specific firmware


This is very helpful. Any idea how the speed compares to serial? I mean not the comm speed itself but the blocking / read time?

In other words, if I put serial and RTT in a loop, which one could execute more reads in a second?


It’s hard to tell.
On their website they say it’s faster but they compare it to SWO or Semihosting.
In reality on your device RTT writes to a buffer in RAM, that’s really fast because it’s a memcopy. But the data seats there until you pull it.

The main advantage for me using this in the past was that I could save pins for monitoring.