运行嵌入式程序就像运行本地程序一样
⚠️ As of 11.10.2023
probe-runis in maintainance mode. We recommend everyone to switch toprobe-rs. Read following article on the why and on how to migrate: https://ferrous-systems.com/blog/probe-run-deprecation/
probe-runRuns embedded programs just like native ones
probe-run is a custom Cargo runner that transparently runs Rust firmware on an embedded device.
probe-run is powered by probe-rs and thus supports all the devices and probes supported by
probe-rs.
cargo run.bkpt), Rust panics and unrecoverable hardware exceptions (e.g. HardFault).To install probe-run, use cargo install probe-run.
On Linux, you might have to install libudev and libusb from your package
manager before installing probe-run.
# ubuntu
$ sudo apt install -y libusb-1.0-0-dev libudev-dev
# fedora
$ sudo dnf install -y libusbx-devel systemd-devel
probe-rsprobe-run inherits device support from the probe-rs library.
If your target chip does not appear in the output of probe-run --list-chips it could be that:
probe-rs supports your chip but the latest version on crates.io does not.
You could try building probe-run against the latest probe-rs version; see instructions below.probe-rs does not yet support the device.
You'll need to request support in the probe-rs issue tracker.To build probe-run against the latest git version probe-rs and install it follow these steps:
$ # clone the latest version of probe-run; line below uses version v0.3.3
$ git clone --depth 1 --branch v0.3.3 https://github.com/knurling-rs/probe-run
$ cd probe-run
$ # modify Cargo.toml to use the git version of probe-rs
$ # append these lines to Cargo.toml; command below is UNIX-y
$ cat >> Cargo.toml ! {
rtt_init_print!(); // You may prefer to initialize another way
rprintln!("Hello, world!");
loop { asm::bkpt() }
}
would output
…
When the device raises a hard fault exception, indicating e.g. a panic or a stack overflow, probe-run will print a backtrace and exit with a non-zero exit code.
This backtrace follows the format of the std backtraces you get from std::panic! but includes
`` lines to indicate where an exception/interrupt occurred.
#![no_main]
#![no_std]
use cortex_m::asm;
#[entry]
fn main() -> ! {
// trigger a hard fault exception with the UDF instruction.
asm::udf()
}
…
If we look at the return code emitted by this cargo run, we'll see that it is non-0:
$ echo $?
134
⚠️ NOTE when you run your application with probe-run, the HardFault handler (default or user-defined) will NOT be executed.
The --backtrace flag is optional and can get passed the following values:
--backtrace=always - forced backtrace (if you'd like to see a backtrace at the end of successful program run)--backtrace=never - suppresed backtrace--backtrace=auto - default, shows a backtrace if the program panics or the stack overflowsRun it like this (example for a forced backtrace):
$ cargo run --bin hello --backtrace=always
The --backtrace-limit flag is optional and defaults to 50. It is possible to set any number.
--backtrace-limit=0 is accepted and means "no limit".
To show a shortened backtrace showing 5 frames, run:
$ cargo run --bin panic --backtrace-limit=5
Note: if --backtrace=never is set, setting --backtrace-limit has no effect.
First, check your hardware:
probe-run cannot be used with these boards.If this doesn't resolve the issue, try the following:
Check if your device shows up in lsusb:
$ lsusb
Bus 001 Device 008: ID 1366:1015 SEGGER J-Link
If your device shows up like in the example, skip to the next troubleshooting section
If it doesn't show up, you need to give your system permission to access the device as a non-root user so that probe-run can find your device.
In order to grant these permissions, you'll need to add a new set of udev rules.
To learn how to do this for the nRF52840 Development Kit, check out the installation instructions in our embedded training materials.
afterwards, your device should show up in probe-run --list-probes similar to this:
$ probe-run --list-probes
The following devices were found:
[0]: J-Link (J-Link) (VID: 1366, PID: 1015, Serial: , JLink)
To use probe-run you need a "probe" (also known as "debugger") that sits between your PC and the microcontroller.
Most development boards, especially the bigger ones, have a probe "on-board": If the product description of your board mentions something like a J-Link or ST-Link on-board debugger you're good to go. With these boards, all you need to do is connect your PC to the dev board using a USB cable you are all set to use probe-run!
If this is not the case for your board, check in the datasheet if it exposes exposes SWD or JTAG pins. If they are exposed, you can connect a "stand alone" probe device to the microcontroller and then connect the probe to your PC via USB. Some examples of stand alone probes are: the ST-Link and the J-Link.
Note that this may involve some soldering if your board does not come with a pre-attached header to plug your debugger into.
This may instead present as Error: RTT control block not found in target memory.
Your code, or a library you're using (e.g. RTIC) might be putting your CPU to sleep when idle. You can verify that this is the problem by busy looping instead of sleeping. When using RTIC, this can be achieved by adding an idle handler to your app:
#[idle]
fn idle(_ctx: idle::Context) -> ! {
loop {}
}
Assuming you'd like to still sleep in order to save power, you need to configure your microcontroller so that RTT can still be handled even when the CPU is sleeping. How to do this varies between microcontrollers.
On an STM32G0 running RTIC it can be done by amending your init function to set
the dmaen bit on RCC.ahbenr. e.g.:
#[init]
fn init(ctx: init::Context) -> init::LateResources {
ctx.device.RCC.ahbenr.write(|w| w.dmaen().set_bit());
...
}
Follow the instructions in the error message to resolve the mismatch.
If you are hacking around with probe-run, you can disable the version check by setting the PROBE_RUN_IGNORE_VERSION environment variable to true or 1 at runtime.
probe-runFor easier copy-paste-ability, here's an example how to try out your local probe_run modifications.
$ cd probe-run/
$ PROBE_RUN_IGNORE_VERSION=1 cargo run -- --chip nRF52840_xxAA --backtrace-limit=10 hello
ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ ˆˆˆˆˆ
environment variables extra flags binary to be
(optional) (optional) flashed & run
To check whether your change has altered probe-run in unexpected ways, please run the snapshot tests in tests before opening a PR if at all possible.
You can do so by connecting a nrf52840 Development Kit and running
$ cargo test -- --ignored
probe-run 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
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.
暂无开放 Issues,或尚未同步最近议题。