Import
Overview
RTT (Real-Time Transfer) is a technology from SEGGER that allows high-speed bidirectional communication between a host and an embedded target through the debug probe. It’s significantly faster than traditional UART and doesn’t require dedicated pins. Key Benefits:- Very high transfer speeds (up to several MB/s)
- No additional hardware pins required
- Works during debugging sessions
- Minimal target overhead
RTT Class
RTT(attach=False)
Create an RTT connection instance.
| Parameter | Type | Description |
|---|---|---|
attach | bool | Reserved for future use (default: False) |
Methods
Reading Data
read_until(expected, timeout=None)
Read data until an expected byte sequence is found.
| Parameter | Type | Description |
|---|---|---|
expected | bytes | Byte sequence to wait for |
timeout | float | Timeout in seconds (None = no timeout) |
bytes - Data read including the expected sequence
read_line(ending=b'\n', timeout=None)
Read a single line of text.
| Parameter | Type | Description |
|---|---|---|
ending | bytes | Line ending to wait for (default: b'\n') |
timeout | float | Timeout in seconds |
bytes - Line including the ending character
read_all()
Read all available data until EOF.
bytes - All available data
read_some()
Read at least one byte of data (blocking).
bytes - Available data (at least 1 byte)
read_eager()
Read immediately available data (non-blocking, may return empty).
bytes - Available data (may be empty)
read_very_eager()
Read all immediately available data (non-blocking).
bytes - All immediately available data
read_lazy()
Read data without blocking.
bytes - Available data without blocking
read_very_lazy()
Read all immediately available data without blocking (similar to read_very_eager()).
bytes - All immediately available data
Writing Data
write(data)
Write data to the RTT channel.
| Parameter | Type | Description |
|---|---|---|
data | bytes | Data to send |
Pattern Matching
expect(patterns, timeout=None)
Wait for one of several patterns to appear.
| Parameter | Type | Description |
|---|---|---|
patterns | list | List of byte patterns (or regex) to match |
timeout | float | Timeout in seconds |
tuple - (index, match_object, text) where index is -1 on timeout
Examples
Basic RTT Communication
Interactive RTT Console
Command/Response Protocol
Log Capture
Production Test with RTT
RTT Auto-Detection
When connecting with J-Link, the system automatically searches RAM for the RTT control block. This is necessary because:- J-Link only searches at 4KB-aligned addresses by default
- Many firmwares place RTT at non-aligned addresses
- Without auto-detection, RTT may fail even with RTT-enabled firmware
Prerequisites
| Requirement | Description |
|---|---|
| Debug Connection | Active J-Link debug connection |
| RTT Firmware | Target firmware must include RTT library |
| J-Link Software | JLinkGDBServer must be running |
Firmware Setup
To use RTT, your embedded firmware must include the SEGGER RTT library:Notes
- RTT communicates over the debug probe (J-Link), not a separate connection
- Default RTT channel is 0 (most firmware uses channel 0 for terminal)
- RTT buffer sizes are configured in firmware (typically 1KB-4KB)
- The
RTTclass uses telnet to port 9090 (J-Link RTT server) - Context manager (
withstatement) ensures proper cleanup - For very high-speed logging, consider using binary format instead of text

