[T][R]ace [I]d's [C] [E]mbedded
Log in (a) trice (S>G)
even inside | interrupts in less than 1 us
What is Trice?
Trice replaces printf or log in C code and gives you three main benefits:
- Speed - Fast enough to use inside interrupts
- Small Size - Uses less FLASH memory
- More Features - Extra options that help developers
Main Idea
Instead of storing log strings on your embedded device, Trice keeps them on your PC. This makes logging faster and uses less memory on your device.
+ The Trice ID List stores all log strings, so the
+ newest version can read logs from all older versions
Two Parts of Trice
- C code macros - Works like
printfbut creates very fast trace and log code for your embedded device - 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
- Read the Trice User Manual
- Current Status: Trice is ready to use!
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. Remember that the file til.json is needed to read all output from devices in the field for 10+ years.
- Optional: Add til.json as a compressed resource to your target image. You can use SRecord or provide a download link.
Data Compression
Trice looks like data compression (IDs instead of strings), which is useful for IoT devices, especially NB-IoT with very low data rates.
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 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.
Data Transfer Options
Implemented Transfer Methods
- UART - Can connect to virtual UART over USB
- RTT - Works with J-Link and ST-Link
- TCP4 (TCP4 input and TCP4 output)
- UDP4 (UDP4 input)
Other Transfer Options
- Use a small separate microcontroller as a bridge from GPIO, I2C, SPI, CAN, LIN to UART
- Use FTDI chips like Adafruit FT232H Breakout for easy GPIO, I2C, and SPI access
Display Server
- Start
trice dsin a console on your local PC or a remote PC. Then connect several trice tool instances using commands liketrice log -p COM15 -ds - This allows to see the Trice logs of several devices line-by-line intermixed in one terminal.
Documentation
- https://interrupt.memfault.com/blog/trice (slightly outdated)
- Trice User Manual (includes updated information from the interrupt blog)
- Check issues and discussions, including closed items
- Read the target source code, especially triceDefaultConfig.h
- View CLI options by running
trice help -allin a terminal or reading tricehelpall_test.go - Look at and modify ./internal/emitter/lineTransformerANSI.go if needed (requires running
go install ./cmd/trice/...afterwards)
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
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. There are no known bugs (see issues).
- Do not use the "dev" branch right now (December 2025) - it may not work properly.
Future Plans
The documentation could be improved. We could add features like remote procedure calls. Or create a separate tlog tool written in C or Python (with AI help). This would allow logging on any platform, not just platforms supported by Go.
Structured Logging
Trice will soon support structured logging. Based on feedback from #531, there is now a specification draft. Please provide feedback before implementation starts.
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!
Become a Sponsor with your Github Account
OR
OR
Clone the Repository
Similar Projects
- ARM ITM/SWO (hardware-native)
- ARM Keil Event Recorder (hardware-native)
- baical.net (C)
- call stack logger function instrumentation (trace program execution flow)
- Debugging with Dynamic Printf Breakpoints (Eclipse IDE option)
- defmt (Rust)
- Diagnostic Log and Trace (AUTOSAR)
- Embedded Logger (elog) (Embedded logger with minimal footprint and memory usage)
- Logging with symbols - The Embedonomicon
- McuLog (McuOnEclipse)
- MCUViewer
- Memfault Compact Log Library (part of firmware SDK)
- Minimal Structured Logging for Autonomous Vehicles (C++, closed source talk)
- NanoLog (C++11) (Linux C++)
- Percepio Tracealyzer (with TraceRecorder) (Visual Trace Diagnostics)
- Pigweed Trace Tokenized
- Postform (Postponed formatting experiments with string interning in C++, inspired by the defmt Rust crate)
- qpspy (C/C++)
- Real-time binary data logging/tracing toolkit
- SEGGER System View
- Serial-Studio (Data visualisation)
- Tonbandgerat (Small embedded systems tracer with support for bare-metal and FreeRTOS-based targets)
- Traces (API tracing framework for Linux C/C++ applications)
- uLog (RD Poor)
- Zephyr Dictionary Based Logging
Trice Compare (generated 2025-05-26)
Logging & Tracing Solutions for Embedded Systems (generated 2026-02-16)
(back to top)