3 releases (breaking)
0.3.0 | Aug 16, 2024 |
---|---|
0.2.0 | Jun 15, 2024 |
0.1.0 | Apr 13, 2024 |
#2202 in Parser implementations
25 downloads per month
Used in cdefmt-decoder
27KB
490 lines
cdefmt
cdefmt
("c de format", short for "c deferred formatting") is a highly efficient logging framework that targets resource-constrained devices, like microcontrollers.
Inspired by https://github.com/knurling-rs/defmt/
Setup
c
- Add cdefmt modifications to the linkerscript:
- Update/add
.note.gnu.build-id
section to define the necessary memory locations:.note.gnu.build-id : { PROVIDE(__cdefmt_build_id = .); *(.note.gnu.build-id) }
- Add the cdefmt metadata section to the end of the linker script (or right before
/DISCARD/
if it exists):/* CDEFMT: log metadata section */ .cdefmt 0 (INFO) : { KEEP(*(.cdefmt.init .cdefmt.init.*)) . = . + 8; KEEP(*(.cdefmt .cdefmt.*)) }
- Update/add
- Make sure that you compile with the following flags:
-g
- need debugging information in order to parse log arguments.-Wl,--build-id
- link build-id into the binary to verify elf compatibility on init.
- Add the header
cdefmt.h
to your project. - Include the header wherever you want to use it.
- Implement
cdefmt_log
in your project. - Call
CDEFMT_GENERATE_INIT()
somewhere in your main file. - Call
cdefmt_init()
after your logging backend is initialized andcdefmt_log
can be safely called. - Enjoy.
Rust
TBD
Usage
Basically cdefmt_log
should store/write log
into the log sink, then these bytes should be
provided to the parser as-is, accompanied with the elf binary.
See:
The easiest way to run the example would be to build the project using cmake:
cmake -S . -B build
cmake --build build/
Then run the stdout example and pipe it's stdout into the stdin example:
build/examples/stdout/example-stdout | build/stdin --elf build/examples/stdout/example-stdout
License
- MIT license (LICENSE or http://opensource.org/licenses/MIT)
Dependencies
~8.5MB
~161K SLoC