3 ms·
The title is misleading, because defmt is not a debugger, but a logger (with a twist). A better title would be "Cheap Logging with Embedded Rust", or something
by dbrgn 5y ago
The title is misleading, because defmt is not a debugger, but a logger (with a twist). A better title would be "Cheap Logging with Embedded Rust", or something like that.
The cool thing about defmt is that it doesn't do string formatting in the program itself. The problem with logging is that many formatting operations - like formatting floats as strings - can be very expensive on small embedded microcontrollers, both the runtime cost as well as a big increase in binary size. Instead, defmt sends the memory representation of the logged values to the host (over an arbitrary transport like UART or RTT). The formatting / visualization of the logs is then handled on the host side.
This has the downside that you cannot simply connect a random serial console to your microcontroller for logging, because defmt uses its own non-plaintext format. But it has the huge advantage that you can do very efficient logging in the microcontroller firmware, and then visualize all those logs on your host with an appropriate client.
More details can be found in the article itself.
- rcxdude 5y agoI've built such systems in C++ before, and they really are extremely useful. You get much more efficient logging (in terms of CPU time, code size, and bandwidth on the wire), and it's automatically structured. printf style logging seems extremely primitive in comparison. It also pairs very well with asynchronous logging (just sticking the logged data into a ringbuffer to be transferred in bulk later), since then you can stick logs statements practically anywhere, often including interrupts and whatever mechanism you are using the transmit the logs.