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.
Differences:
- 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(){
âŚ
motor.useMonitoring(rtt);
âŚ
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 add_RTT_task.py file with the following content:
Import(âenvâ)
env.AddCustomTarget(
âRTT Startâ,
None,
â$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 = add_RTT_task.py
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