trice

module
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2026 License: MIT

README

Trice - Trace IDs for Embedded C/C++

🅃🅁ace 🄸d's for 🄲 🄴mbedded

View GitHub Pages

TriceGirlS.png Hi, I am Trice.


Trice is an ultra-low-overhead logging framework for embedded C/C++. It provides printf-like usability with only ~6–100 CPU cycles per log call, making logging practical even when used from interrupt handlers in real-time firmware systems.

License GitHub release (latest by date) GitHub commits since latest release Downloads GitHub issues PRs Welcome Go Version Go Report Card Coverage TRICE Library CI (Nightly Full)

Log in a trice — with Trice, even from ↯ interrupt handlers in less than 1 µs ❗

Trice User Manual: GitHubGH PagesPDF

Overview (click to expand)

What is Trice?

Trice is designed for systems where traditional logging is too slow, too large, or not safe to use in interrupt or real-time contexts.

Trice replaces printf-style logging in embedded C/C++ systems with a much faster and more efficient approach.

Instead of formatting and storing strings on the target, Trice encodes log messages as compact IDs and keeps the actual strings on the host. This reduces runtime overhead, memory usage, and data transfer size.

Key Benefits
  • 🚀 Speed – ~6–100 CPU cycles per log call. This makes logging practical even when used from interrupt handlers in real-time firmware systems.
  • 📦 Small Size – no format strings stored in target FLASH
  • 🧱 Version Stability – decode logs from older firmware without requiring matching tool versions
  • 🛠 Easy Migration – reuse existing printf-style code with minimal changes via the -alias option
  • ➕ More Features – flexible logging, transport options, and tooling
How it works
  1. Use Trice macros instead of printf in your firmware (or use the trice i -alias option).
  2. At build time, Trice assigns each log message a compact ID while the user source code stays unchanged.
  3. The target device sends only IDs and data.
  4. The host reconstructs the original messages using the Trice ID list.
- printf("Temperature: %d°C", t);
+ trice("Temperature: %d°C", t);   // fast, compact, ID-based
Result
  • Faster execution
  • Smaller binaries
  • Reliable logging in time-critical code paths
Two Parts of Trice
  1. C code macros - Provide a familiar printf-like interface at the application level, but internally send just ID and values instead of full format strings. The Trice tool maps these IDs back to readable text.
  2. Trice tool - Manages and displays the logs
    • Written in Go - works on all platforms that Go supports
    • You can also build your own tool to receive Trice packages, replace IDs with text, and display the output

Ready to use: Start with Trice

Trice log icon

Install the trice tool. Use a latest release binary and put it into your PATH.

For a first setup, SEGGER RTT is usually fastest: it needs no MCU-specific UART driver and works via J-Link. Install the SEGGER J-Link software package so JLinkRTTLogger is in PATH.

  1. Add the complete src folder to your target project unchanged and add ./src to the compiler include path.
  2. Create a project-specific triceConfig.h file with this minimal direct RTT configuration:
#define TRICE_DIRECT_OUTPUT 1
#define TRICE_BUFFER TRICE_STACK_BUFFER
#define TRICE_DIRECT_SEGGER_RTT_32BIT_WRITE 1
  1. Add Trice to your code, for example in main.c:
#include "trice.h"

int main(void) {
    TriceInit(); // RTT-specific
    // ... system init
    trice("Hello world!\n");
    // ...
}
  1. Create empty til.json and li.json files in your project root and run trice insert -src ./ before compiling. This assigns IDs to your trice(...) calls and fills both JSON files.
  2. Build and flash your target.
  3. Start logging with your device name (add -v for details)
trice log -p JLINK -args "-Device STM32G0B1RE -if SWD -Speed 4000 -RTTChannel 0" -pf none -prefix off -hs off -d16 -i ./til.json -li ./li.json

Or use the file-based RTT logger workflow manually:

Terminal 1 (remove any old log file and create the file):

rm -f ./temp/trice.bin
touch ./temp/trice.bin
JLinkRTTLogger -Device STM32G0B1RE -If SWD -Speed 4000 -RTTChannel 0 ./temp/trice.bin

Terminal 2:

trice log -p FILE -args ./temp/trice.bin -pf none -prefix off -hs off -d16 -ts ms -i ./til.json -li ./li.json

For more setup details, see Start with Trice, Configuration file triceConfig.h, and Trice over RTT.

When to Use Trice

Logging and Debugging

You can use Trice for printf debugging and as a logging system. The advantage is very short messages (no strings) for data transfer. Keep your project-specific til.json file available to decode field logs later. The repository example file is demoTIL.json.

  • Optional: Add your project-specific til.json as a compressed resource to your target image. You can use SRecord or provide a download link.
Data Compression

Replacing format strings with IDs at compile time acts like strong data compression for FLASH and transferred log data, while making target-side logging orders of magnitude faster at runtime.

FLASH Memory Storage

Store Trice messages in FLASH memory for later analysis. A typical trice uses only 4 bytes, no matter how long the format string is.

Encryption

You can encrypt Trice transfer packets for security.

  • Deliver firmware images with encrypted Trice output that only works with the right key and the matching til.json
  • XTEA encryption is available
Translation

Translate the til.json file into different languages. Change the language by changing the til.json file without changing the target binary.

Timing Analysis

Trice makes timing analysis easy on distributed embedded systems. It supports both host and target timestamps.

How Trice Works (UART Example)

This simplified diagram shows how Trice works. Read the detailed explanation here.

trice

Data Transfer Options

Implemented Transfer Methods
Other Transfer Options

Display Server

  • Start trice ds in a console on your local PC or a remote PC. Then connect several trice tool instances using commands like trice log -p COM15 -ds
  • This allows you to see the Trice logs of several devices line-by-line intermixed in one terminal.

Documentation

The Trice User Manual includes all information from the Memfault Interrupt Blog which is slightly outdated.

Debugging with VS Code and Clang

Debug a Trice project in Direct-Out Mode over SEGGER-RTT. (See Development Environment Setup for details.)

Trice Cache

(click to expand)

You can use the -cache CLI switch with trice insert and trice clean commands. This only works when you create the .trice/cache folder in your home directory. (Trice Cache Details)

When to Use Cache

Use cache when you:

  • Use trice i ... before compiling
  • Use trice c ... after compiling
  • Want to keep IDs out of your source code when working
  • Want faster compilation
How Cache Works

The Trice cache saves copies of all files after processing them with trice i or trice c. This avoids inserting and removing IDs repeatedly. The copies are used to get the same results for files that have not been edited. Edited files are processed normally and the cache updates afterwards. File modification times do not change, so the build system does not reprocess unchanged files even when IDs are temporarily removed.

Important Note
-> Be careful when your build system also modifies source files!

For example, run an auto-formatter before the trice insert command.


Which Mode Should You Use?

  • For development: Direct mode with SEGGER_RTT is recommended
  • For most use cases: Deferred mode with TRICE_BUFFER == TRICE_RING_BUFFER (uses less RAM) in TRICE_MULTI_PACK_MODE (transfers less data)

Project Status

Trice is fully usable.

+ Use the latest release or main branch to build from source.
- Do not use the "dev" branch. It may not work properly.

Future Plans

  • The documentation could better explain advanced use cases, such as deferred remote procedure calls.
  • A separate tlog tool written in C or Python would allow logging on any platform, not just platforms supported by Go.
  • A draft specification for structured logging in Trice is available, based on feedback from #531.
  • Proposals and feedback on these topics are welcome.

Support the Project

  • Trice takes a lot of my free time. I want to keep it MIT licensed in the future.
  • If you make profit using Trice in your products, donations help convince my family to continue improving Trice.
  • ⭐ Star this project! ☺
  • Support options:

Similar Projects

(click to expand)

Additional comparison material:

(back to top)

Directories

Path Synopsis
_test
alias_dblB_de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
aliasassert_dblB_de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
be_dblB_de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
be_staticB_di_xtea_cobs_rtt32
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_multi_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_multi_nopf_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_multi_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_multi_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_multi_xtea_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_protect_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_single_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_single_nopf_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_single_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_single_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_de_single_xtea_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_cobs_rtt32__de_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt32__de_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt32__de_multi_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt32__de_multi_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt32__de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt32__de_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt8__de_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt8__de_multi_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt8__de_multi_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
dblB_di_nopf_rtt8__de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
modify_for_debug
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_multi_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_multi_nopf_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_multi_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_multi_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_multi_xtea_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_protect_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_single_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_single_nopf_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_single_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_single_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_de_single_xtea_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_cobs_rtt32__de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_cobs_rtt32__de_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_cobs_rtt8__de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_nopf_rtt32__de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_nopf_rtt32__de_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_nopf_rtt8__de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_tcobs_rtt32__de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_xtea_cobs_rtt32__de_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_xtea_cobs_rtt32__de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
ringB_di_xtea_cobs_rtt32__de_xtea_cobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
stackB_di_nopf_aux32
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
stackB_di_nopf_aux32_specific
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
stackB_di_nopf_aux8
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
stackB_di_nopf_rtt32
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
stackB_di_nopf_rtt8
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
stackB_di_xtea_cobs_rtt8
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
staticB_di_nopf_aux32
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
staticB_di_nopf_aux8
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
staticB_di_nopf_rtt32
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
staticB_di_nopf_rtt8
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
staticB_di_tcobs_rtt32
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
staticB_di_tcobs_rtt8
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
staticB_di_xtea_cobs_rtt32
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
userprint_dblB_de_tcobs_ua
Package cgot is a helper for testing the target C-code.
Package cgot is a helper for testing the target C-code.
cmd
_cui command
_stim command
clang-filter command
tlog command
trice command
internal
args
Package args defines the Trice command-line interface.
Package args defines the Trice command-line interface.
charDecoder
Package charDecoder provides a pass-through decoder for character streams.
Package charDecoder provides a pass-through decoder for character streams.
com
Package com provides serial COM-port helpers for opening, reading, and writing.
Package com provides serial COM-port helpers for opening, reading, and writing.
decoder
Package decoder provides several decoders for differently encoded trice streams.
Package decoder provides several decoders for differently encoded trice streams.
do
Package do wires parsed command arguments into cooperating runtime packages.
Package do wires parsed command arguments into cooperating runtime packages.
dumpDecoder
Package dumpDecoder provides a decoder that hex-dumps an encoded trice stream.
Package dumpDecoder provides a decoder that hex-dumps an encoded trice stream.
emitter
Package emitter formats decoded trice text lines and writes them either to a local display or to a remote RPC display server.
Package emitter formats decoded trice text lines and writes them either to a local display or to a remote RPC display server.
fmtspec
Package fmtspec provides a tiny shared parser for the subset of C printf format specifiers that Trice needs during source analysis and host-side decoding.
Package fmtspec provides a tiny shared parser for the subset of C printf format specifiers that Trice needs during source analysis and host-side decoding.
id
Package id List is responsible for id List managing
Package id List is responsible for id List managing
keybcmd
Package keybcmd is responsible for interpreting user commandline and executing commands
Package keybcmd is responsible for interpreting user commandline and executing commands
link
Package link reads from SeggerRTT with the SEGGER app JLinkRTTLogger or with the open source app stRttLogger.exe.
Package link reads from SeggerRTT with the SEGGER app JLinkRTTLogger or with the open source app stRttLogger.exe.
trexDecoder
Package trexDecoder decodes framed TREX trice byte streams.
Package trexDecoder decodes framed TREX trice byte streams.
pkg
ant
Package ant walks source trees and applies an action function to matching files.
Package ant walks source trees and applies an action function to matching files.
cipher
Package cipher provides XTEA-based helper functions for encrypting and decrypting Trice binary payload blocks.
Package cipher provides XTEA-based helper functions for encrypting and decrypting Trice binary payload blocks.
msg
Package msg contains small logging and diagnostic helpers used across Trice.
Package msg contains small logging and diagnostic helpers used across Trice.
tst
Package tst provides helper utilities used by tests in this repository.
Package tst provides helper utilities used by tests in this repository.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL