Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Quickly set up a probe-run + defmt + flip-link embedded project


$ cargo install flip-link

2. probe-run:

$ # make sure to install v0.2.0 or later
$ cargo install probe-run

3. cargo-generate:

$ cargo install cargo-generate

Note: You can also just clone this repository instead of using cargo-generate, but this involves additional manual adjustments.


1. Initialize the project template

$ cargo generate \
    --git \
    --branch main \
    --name my-app

If you look into your new my-app folder, you'll find that there are a few TODOs in the files marking the properties you need to set.

Let's walk through them together now.

2. Set probe-run chip

Pick a chip from probe-run --list-chips and enter it into .cargo/config.toml.

If, for example, you have a nRF52840 Development Kit from one of our workshops, replace {{chip}} with nRF52840_xxAA.

 # .cargo/config.toml
 [target.'cfg(all(target_arch = "arm", target_os = "none"))']
-runner = "probe-run --chip {{chip}}"
+runner = "probe-run --chip nRF52840_xxAA"

3. Adjust the compilation target

In .cargo/config.toml, pick the right compilation target for your board.

 # .cargo/config.toml
-target = "thumbv6m-none-eabi"    # Cortex-M0 and Cortex-M0+
-# target = "thumbv7m-none-eabi"    # Cortex-M3
-# target = "thumbv7em-none-eabi"   # Cortex-M4 and Cortex-M7 (no FPU)
-# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
+target = "thumbv7em-none-eabihf" # Cortex-M4F (with FPU)

Add the target with rustup.

$ rustup target add thumbv7em-none-eabihf

4. Add a HAL as a dependency

In Cargo.toml, list the Hardware Abstraction Layer (HAL) for your board as a dependency.

For the nRF52840 you'll want to use the nrf52840-hal.

 # Cargo.toml
-# some-hal = "1.2.3"
+nrf52840-hal = "0.14.0"

⚠️ Note for RP2040 users ⚠️

You will need to not just specify the rp-hal HAL, but a BSP (board support crate) which includes a second stage bootloader. Please find a list of available BSPs here.

5. Import your HAL

Now that you have selected a HAL, fix the HAL import in src/

 // my-app/src/
-// use some_hal as _; // memory layout
+use nrf52840_hal as _; // memory layout

(6. Get a linker script)

Some HAL crates require that you manually copy over a file called memory.x from the HAL to the root of your project. For nrf52840-hal, this is done automatically so no action is needed. For other HAL crates, you can get it from your local Cargo folder, the default location is under:


Not all HALs provide a memory.x file, you may need to write it yourself. Check the documentation for the HAL you are using.

7. Run!

You are now all set to cargo-run your first defmt-powered application! There are some examples in the src/bin directory.

Start by cargo run-ning my-app/src/bin/

$ # `rb` is an alias for `run --bin`
$ cargo rb hello
    Finished dev [optimized + debuginfo] target(s) in 0.03s
flashing program ..
resetting device
0.000000 INFO Hello, world!

$ echo $?

If you're running out of memory (flip-link bails with an overflow error), you can decrease the size of the device memory buffer by setting the DEFMT_RTT_BUFFER_SIZE environment variable. The default value is 1024 bytes, and powers of two should be used for optimal performance:

$ DEFMT_RTT_BUFFER_SIZE=64 cargo rb hello

(8. Set rust-analyzer.linkedProjects)

If you are using rust-analyzer with VS Code for IDE-like features you can add following configuration to your .vscode/settings.json to make it work transparently across workspaces. Find the details of this option in the RA docs.

    "rust-analyzer.linkedProjects": [

Running tests

The template comes configured for running unit tests and integration tests on the target.

Unit tests reside in the library crate and can test private API; the initial set of unit tests are in src/ cargo test --lib will run those unit tests.

$ cargo test --lib
(1/1) running `it_works`...
└─ app::unit_tests::__defmt_test_entry @ src/
all tests passed!
└─ app::unit_tests::__defmt_test_entry @ src/

Integration tests reside in the tests directory; the initial set of integration tests are in tests/ cargo test --test integration will run those integration tests. Note that the argument of the --test flag must match the name of the test file in the tests directory.

$ cargo test --test integration
(1/1) running `it_works`...
└─ integration::tests::__defmt_test_entry @ tests/
all tests passed!
└─ integration::tests::__defmt_test_entry @ tests/

Note that to add a new test file to the tests directory you also need to add a new [[test]] section to Cargo.toml.

Trying out the git version of defmt

This template is configured to use the latest release (the "stable" release) of the defmt framework. To use the git version (the "development" version) of defmt follow these steps:

  1. Install the git version of probe-run
$ cargo install --git --branch main
  1. Check which defmt version probe-run supports
$ probe-run --version
0.2.0 (aa585f2 2021-02-22)
supported defmt version: 60c6447f8ecbc4ff023378ba6905bcd0de1e679f

In the example output, the supported version is 60c6447f8ecbc4ff023378ba6905bcd0de1e679f

  1. Switch defmt dependencies to git: uncomment the last part of the root Cargo.toml and enter the hash reported by probe-run --version:
-# [patch.crates-io]
-# defmt = { git = "", rev = "use defmt version reported by `probe-run --version`" }
-# defmt-rtt = { git = "", rev = "use defmt version reported by `probe-run --version`" }
-# defmt-test = { git = "", rev = "use defmt version reported by `probe-run --version`" }
-# panic-probe = { git = "", rev = "use defmt version reported by `probe-run --version`" }
+defmt = { git = "", rev = "60c6447f8ecbc4ff023378ba6905bcd0de1e679f" }
+defmt-rtt = { git = "", rev = "60c6447f8ecbc4ff023378ba6905bcd0de1e679f" }
+defmt-test = { git = "", rev = "60c6447f8ecbc4ff023378ba6905bcd0de1e679f" }
+panic-probe = { git = "", rev = "60c6447f8ecbc4ff023378ba6905bcd0de1e679f" }

You are now using the git version of defmt!

NOTE there may have been breaking changes between the version and the git version; you'll need to fix those in the source code.


app-template is part of the Knurling project, Ferrous Systems' effort at improving tooling used to develop for embedded systems.

If you think that our work is useful, consider sponsoring it via GitHub Sponsors.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.


Quickly set up a `probe-run` + `defmt` + `flip-link` embedded project




Apache-2.0, MIT licenses found

Licenses found


Security policy





No releases published

Sponsor this project



No packages published