Blog coding article

Knurling-rs changelog #8

Lotte
Article

Knurling-rs changelog #8

Published on 3 min read
Knurling icon
Knurling
A tool set to develop embedded applications faster.
❤️ Sponsor

    This is the eighth changelog for Knurling-rs, our push to sustainably build better tooling for developing and debugging Rust software for embedded systems. Knurling-rs includes a suite of tools that make it easier to develop, log, debug, and test your embedded Rust libraries and applications!

    Knurling-rs is supported by our sponsors on GitHub. If you're interested in seeing more projects like this, consider becoming a sponsor today!

    Highlights

    defmt::panic!, defmt::assert! and probe-run colorization

    With #266, defmt now has its own version of panic!-like and assert!-like macros which will log the panic message using defmt and then call core::panic! (by default).

    As of #110, the the output of defmt::assert_eq is also diff'ed and colorized based on the assertion result when using probe-run.

    `defmt::assert()` can be used and produces diff-like colorful output

    defmt::unwrap!

    defmt now has an unwrap! macro which can be called on Result and Option types. #273

    It behaves the same as the standard unwrap() but prints the result with defmt. You can also use it to emulate the behavior of expect().

    However, the invocation looks a bit different:

    let result = Ok::<(), ()>(());
    -let x = result.unwrap();
    +let x = defmt::unwrap!(result);
    
    let value = result;
    -let x = value.expect("text");
    +let x = defmt::unwrap!(value, "text");
    
    let arg = 42;
    -let x = value.expect(&format!("text {:?}", arg));
    // arg must implement `Format`
    +let x = defmt::unwrap!(value, "text {:?}", arg);
    

    Thanks to @Dirbaio for implementing this as well as reporting and fixing #257, #269 and #272!

    probe-run 0.1.7

    probe-run 0.1.7 (which uses probe-rs 0.10) has been published (see #108, #107).

    This fixes flashing issues #15 and #29.

    New knurling-sessions content

    In this week's knurling-sessions we're adding a piezo buzzer to get an acoustic warning if the CO2 levels in your room are critically high.

    Sponsors can check them out in the Red Alert! chapter of knurling-books (check the sponsors dashboard thread for credentials and discussions)

    Improvements

    defmt

    • #257 code size optimizations
    • #267, #280, #281 defmt now has Debug2Format and Display2Format adapters so that you can print values that only impl Debug or Display too. Note that this disables defmt's parameter compression and should only be used if using defmt::Format is not possible.
    • The defmt book is "rolling release", i.e. it contains all changes merged into the defmt repository. This means that it's already documenting features not yet in a crates.io release. We've started adding notes about feature availability (e.g. "defmt 0.1.2 and up") in #279.
    • #263, #276 it's now possible to add a custom Format Trait implementation, e.g. for a struct that you'd like to be displayed in a way that's more helpful to you

    probe-run

    Fixes

    defmt

    • #269 fixes compiler error that was thrown when using defmt::panic within e.g. a match expression
    • #272 braces in format args passed to the new defmt::panic! and defmt::assert! macros do not cause unexpected errors anymore
    • #261 update example output in README
    • #17 attributes in linker scripts do not cause parse errors anymore (they are ignored)

    Version Update Notification

    We've bumped the versions of our crates.io releases as a result of the changes listed above. They have changed as follows:

    • flip-link has been updated to v0.1.2
    • defmt has been updated to v0.1.2
    • probe-run has been updated to v0.1.7

    Internal Improvements

    • #278 the CI now has a backwards compatibility check against defmt-decoder v0.1.0 to catch regressions
    • #274 the CI now runs all tests on macOS. Previously, the defmt-decoder tests were unintentionally omitted.

    Sponsor this work

    Knurling is mainly funded through GitHub sponsors. Sponsors get early access to the tools we are building and help us to support and grow the knurling tools and courses. Thank you to all of the people already sponsoring our work through the Knurling project!