C++ implementation of the SEGGER Real Time Transfer (RTT) protocol. RTT is a protocol to transfer data beetween a microcontroller and a host computer with the use of a debugger.
The implemation is fully configurable at compile time and there is no runtime overhead1 for the initialisation of the control blocks.
For the most basic usage see examples/static_buffers.cpp.
#include "rtt/rtt.hpp"
#include <string_view>
// basic configuration with 1 up buffer in skip mode with 512 bytes size.
using RttConfig = rtt::SingleModeUpOnlyEmptyNameConfig<rtt::BufferMode::skip, 512>;
using RttType = rtt::ControlBlock<RttConfig>;
static inline constinit typename RttType::Storage_t storage{};
static inline constinit RttType rttControlBlock{storage};
int main() {
static constexpr std::string_view msg{"test\n"};
rttControlBlock.write<0>(msg);
}There are more advanced usecases and configurations in the examples folder.
For receiving the data on the host see segger website or openocd website.
To use this project in a cmake project, just add the rtt folder via add_subdirectory and
link against it using target_link_libraries.
example:
add_subdirectory(rtt)
target_link_libraries(${target_name} rtt::rtt)You can also use rtt as single header. Just copy rtt.hpp wherever you need it.
To prevent zero initializing of the storage you can place it into a ram section which does not get initialized.
example:
// .noInit.inline, not .noInit: gcc refuses a TU where this inline (COMDAT) member and a plain variable
// share one named section; a linker rule *(.noInit*) collects both.
[[gnu::section(".noInit.inline"), gnu::used]] static inline constinit typename RttType::Storage_t rttStorage;tests/ is a CMake project of its own, run by CI on every push:
cmake -S tests -B build && cmake --build build && ctest --test-dir build- the ring against a model, its edges, block mode against a reader thread, and host offsets
past the buffer (the target must never copy outside it), built
-m32since rtt needs 4-byte pointers (-DUSE_SANITIZER=addressfor ASan/UBSan) - the examples: all compiled, the ones that end run
- with
arm-none-eabi-gccinstalled: an example cross-compiled with gcc and clang for Cortex-M0+ to M55 and A7/R5, warnings as errors, and admbchecked in the assembly exactly where the core needs one
Feel free to report bugs or submit pull requests.
-
On systems with cache, the user needs to ensure that the storage and control blocks are aligned to cache lines.
-
Only ranges with contigues memory are supported. There is no reason, other then performace, to not support non contigues ranges. When there is a need for that, feel free to suggest an option how to configure it.
-
A
dmbis placed between the data and the offset that publishes it on ARMv7E-M (Cortex-M4/M7), ARMv8-M baseline/mainline (Cortex-M23/M33), ARMv8.1-M and ARMv7-A/R (Cortex-A/R), asSEGGER_RTT.hdoes. Cortex-M0/M0+/M3 get only a compiler barrier; SEGGER adds nodmbthere either.
Footnotes
-
The control blocks will be inizialised in startup code while copying the data segment. There will be
24 + <number of buffers> * 24bytes copied. ↩