Super-fast, tiny C/C++ tracing with printf look-and-feel, even in interrupts ⚡, plus real-time PC logging
Super-fast, tiny C/C++ tracing with printf look-and-feel, even in interrupts ⚡, plus real-time PC logging
The name combines TRace IDs, C/C++, and Embedded systems.
Hi, I am Trice.
Trice is a compact ID-based logging framework for embedded C/C++.
Firmware code uses printf-like calls, but the target sends only small binary records: an ID plus optional runtime values.
The PC-side trice tool reconstructs the readable text using the project-specific til.json which is intentionally cumulative: old IDs and format strings remain available so logs from older firmware can still be decoded.
Use Trice when normal printf logging is too slow, too large, too intrusive in interrupt contexts, or too inefficient for field diagnostics.
User Manual: GitHub - GitHub Pages - PDF - Project page
Log in a trice — even from ↯ interrupt handlers in a few CPU cycles in optimized configurations❗
Small demo animation
Choose one first path:
| Situation | Start here |
|---|---|
| You already have a non-blocking byte writer, DMA TX queue, USB CDC writer, socket writer, pipe, or file writer | Existing non-blocking byte writer |
| You have a SEGGER J-Link and want the quickest lab setup | SEGGER RTT direct mode |
| You want UART or USB-VCOM output | UART / USB-VCOM deferred output |
| You want complete STM32 examples | Example projects |
For most existing projects, the non-blocking byte writer path is the least disruptive first integration.
trice bindtrice bind is the successor to the legacy trice insert / trice clean workflow. It keeps numeric IDs out of bind-managed Trice calls by generating sidecar headers as temporary build artefacts. Existing insert / clean projects remain fully supported and continue to work unchanged. This technique does not patch the user sources anymore during the build process. See Trice Bind in User Manual for details.
trice bind is currently experimental and is not yet included in an official release. To try it before the next release, build the trice tool from this repository and ensure the resulting executable is in your PATH:
./scripts/buildTriceTool.shTry the minimal demo. It uses only the installed trice binary and the target sources in src from this repository.
Minimal source example
Trice gives embedded firmware a fast logging path with a familiar source-code style:
trice("boot\n");
trice("adc=%d mV\n", adc_mV);Instead of formatting strings on the target, Trice stores the human-readable text on the host and transfers compact binary records from the target. This reduces target FLASH usage, transfer bandwidth, log files and log-call execution time.
How ID-based decoding works
The recommended workflow uses trice bind as described above. The following steps describe the legacy source-modifying workflow, which remains supported:
trice(...) calls in firmware code.trice insert before compilation.til.json.A typical source-level idea is:
- printf("Temperature: %d °C\n", t);
+ trice("Temperature: %d °C\n", t);Legacy source-code ID workflow (still supported)
The legacy workflow assigns IDs by processing source files with trice insert. This workflow remains supported for existing and new projects.
A call such as this:
trice("boot\n");becomes similar to this before compilation:
trice(iD(12345), "boot\n");This is intentional: the target binary contains the ID, while the host keeps the text in til.json.
You can choose how visible those IDs are in your workflow:
trice clean after the build,For team projects, define this policy early and treat til.json like any other build artifact needed for field diagnostics.
See Trice ID management.
Key benefits
printf-style code with minimal changes via the -alias optiontil.json is preserved.til.json, not in the target image.Which mode should you start with?
| Mode / path | Use when |
|---|---|
| Deferred auxiliary 8-bit | You already have a non-blocking byte writer. This is usually the most universal first integration. |
| Direct SEGGER RTT | You have J-Link/RTT and want a fast interactive lab setup. |
| Deferred UART / USB-VCOM | Your board exposes a serial path and you want a conventional PC input stream. |
| Deferred ring buffer | You want a balanced default for RAM usage and runtime behavior. |
| Deferred double buffer | You want the shortest target-side log-call path and can spend more RAM. |
Direct mode writes each record immediately to the selected backend.
Deferred mode writes first into a target buffer; TriceTransfer() sends later.
Two parts of Trice
Trice has two cooperating parts:
printf-like interface but emit IDs and values instead of full format strings.trice tool manages IDs, receives binary data, and reconstructs readable log output.The host tool is written in Go and runs on common desktop platforms. You can also build your own receiver that reads Trice packages, maps IDs to format strings, and displays or stores the decoded output.
Files: til.json, li.json, and binary logs
| File | Purpose | Keep? |
|---|---|---|
til.json |
Maps IDs to format strings | Yes; required for decoding |
li.json |
Maps IDs to source locations | Useful for diagnostics |
| Binary log file | Raw target output | Useful for offline or field decoding |
Keep the one accumulated til.json to decode all previously released firmware versions.
The repository example file is demoTIL.json.
Each li.json entry stores a normalized File path relative to the location-file
directory by default. Use -liRoot to select a different project root when
creating location data. Log output shows only the file name by default; use
-liMaxDirs to include trailing parent directories.
Legacy insert/clean ID workflows (still supported)
These three source-modifying workflows remain fully supported:
Keep IDs in source - good for small projects and maximum robustness.
trice insert -src ./ -i ./til.json -li ./li.json
# build normallyInsert before build, clean after build - good when the repository should stay visually free of IDs.
trice insert -src ./ -i ./til.json -li ./li.json
# build
trice clean -src ./ -i ./til.json -li ./li.jsonUse the Trice cache - good when repeated insert/clean would otherwise cause unnecessary recompilation.
mkdir -p ~/.trice/cache
trice insert -cache -src ./ -i ./til.json -li ./li.json
# build
trice clean -cache -src ./ -i ./til.json -li ./li.jsonPick one workflow and document it in the project build instructions.
If other tools also rewrite source files, such as formatters or code generators, run them before trice insert.
Legacy insert/clean cache (still supported)
The Trice cache avoids unnecessary rebuilds when using trice insert and trice clean around the build.
It keeps cached inserted and cleaned copies of unchanged files.
Typical use:
mkdir -p ~/.trice/cache
trice insert -cache -src ./ -i ./til.json -li ./li.json
# build
trice clean -cache -src ./ -i ./til.json -li ./li.jsonUse cache when you want to keep IDs out of your source code while avoiding repeated recompilation of unchanged files.
Be careful when your build system also modifies source files; for example, run auto-formatters before trice insert.
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.
See Trice Cache for Compilation Speed.
Legacy insert workflow (still supported)
src/ to your firmware project.triceConfig.h.trice insert before compiling. This assigns stable IDs and updates til.json and li.json.trice log on the PC to decode the binary stream.Minimal firmware shape:
#include "trice.h"
int main(void) {
BoardInit();
TriceInit();
trice("boot\n");
trice("adc=%d mV\n", adc_mV);
for (;;) {
AppRun();
TriceTransfer(); // needed for deferred outputs
}
}Create the ID files once, then insert IDs:
touch til.json li.json
trice insert -src ./ -i ./til.json -li ./li.jsonStart logging from a serial or USB-VCOM port:
trice log -p COM15 -baud 921600 -i ./til.json -li ./li.json
# or, on Linux/macOS:
trice log -p /dev/ttyACM0 -baud 921600 -i ./til.json -li ./li.jsonLegacy code integration
Existing projects do not have to migrate all logs at once. Best strategy:
Use Trice aliases so project-specific log macros are processed by
trice insertwithout renaming every call site.
See Legacy User Code Option Trice Aliases Adaptation.
Alternatively:
printf output and send Trice on a separate physical channel.printf calls with Trice calls where speed, bandwidth, or FLASH matters.For a first integration, prefer a small vertical slice:
No open issues yet, or sync has not completed.