Skip to main content

Crate unprobe

Crate unprobe 

Source
Expand description

Probe-less development for RP2040/RP2350 with Embassy.

No debug probe? With unprobe, a debug build gets:

  • Logging over USB serial with the usual info!, warn!, error!, debug!, trace!.
  • Panic capture: the message survives a reset and is printed on the next boot. The firmware then halts there instead of running again, like stopping at a breakpoint.
  • HardFault and stack overflow capture: reported the same way, with the source line (the CLI looks it up). On the RP2350 the stack limit register turns a stack overflow into a fault instead of silent memory corruption, like flip-link.
  • Stack usage: stack_usage tells how deep the stack has been so far.
  • Flashing without the BOOTSEL button: the unprobe CLI opens the port at 1200 baud and the board reboots into BOOTSEL by itself.

In a release build all of this disappears: no USB stack, no logger, no format strings, no fault handler. The binary is the same as one built without unprobe (the panic handler behaves exactly like panic-halt).

§Usage

ⓘ
use unprobe::info;

#[embassy_executor::main]
async fn main(spawner: Spawner) {
    let p = embassy_rp::init(Default::default());
    unprobe::init!(spawner, p.USB);
    info!("hello from {}", "unprobe");
}

Use the unprobe CLI as the cargo runner (cargo install unprobe-cli), in .cargo/config.toml:

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "unprobe run"

cargo run then flashes the board and streams the log into the terminal.

init! needs an async context: if the previous boot panicked or faulted, it prints the report and never returns, so the application does not run again until you reflash or replug.

§Device identity, log level and format

ⓘ
unprobe::init!(spawner, p.USB, unprobe::Config {
    product: "My Board",
    level: log::LevelFilter::Info,
    format: unprobe::Format::Detailed, // or Format::Custom(your_fn)
    ..unprobe::Config::new()
});

The log buffer is 2048 bytes; set UNPROBE_BUFFER_SIZE in the [env] section of your .cargo/config.toml to change it.

If you change the VID/PID, pass them to the CLI too: unprobe run --vid 1234 --pid 5678.

§Sharing USB with your own device

If the firmware already uses USB (HID, MIDI, …), add the log port to your own builder instead. The device then appears as a composite device. Driver, interrupt, VID/PID and UsbDevice::run stay yours; only Config::level is used. In release, nothing is added.

ⓘ
let mut builder = embassy_usb::Builder::new(driver, config, ...);
unprobe::attach!(spawner, &mut builder); // first, before your own classes
// ... add your own classes ...
spawner.spawn(usb_task(builder.build())).unwrap();
unprobe::halt_if_panicked!();

§Cargo features

All are on by default. With default-features = false, only the logger is left.

  • panic-handler: provides the #[panic_handler]. Turn it off to use your own (for example panic-halt or panic-probe).
  • hardfault-handler: provides the HardFault handler and, on the RP2350, the stack limit. Turn it off to use your own #[exception] fn HardFault.
  • bootsel-touch: opening the port at 1200 baud reboots the board into BOOTSEL. Without it, you have to press the button for every flash.

§Notes

  • Use the macros from this crate (unprobe::info!). Calling log::info! directly also works in debug builds, but in release it leaves the call in the binary unless your app enables the log feature release_max_level_off.
  • unprobe installs itself as the log logger. If another logger is already installed, it doesn’t panic: it prints a notice over USB, and log output goes to that logger.
  • Debug and release are told apart by debug_assertions (cargo build vs cargo build --release).
  • The chip feature of embassy-rp (rp235xa, rp2040, …) is chosen by your application.

Macros§

attach
Adds the log port to your own USB device (composite device).
debug
Logs a message at the debug level.
error
Logs a message at the error level.
halt_if_panicked
For attach! users: call right after spawning your USB device task, in an async function.
info
Logs a message at the info level.
init
Starts unprobe on the USB peripheral (the firmware uses USB for nothing else).
trace
Logs a message at the trace level.
warn
Logs a message at the warn level.

Structs§

Config
USB device identity and log level. Only used in debug builds.
StackUsage
How much of the stack was used so far (the deepest point), see stack_usage.
Uptime
Time since boot in microseconds. Displayed as seconds: 12.345678.

Enums§

Format
How a log line looks. Only used in debug builds.

Functions§

reboot_to_bootsel
Reboots the chip into BOOTSEL (USB mass storage) mode, as if the button was held.
stack_usage
The deepest the stack has been since boot: info!("stack: {}", unprobe::stack_usage().unwrap()).
uptime
Time since boot from the hardware timer. Zero before embassy_rp::init (the timer is still held in reset then).

Type Aliases§

FormatFn
Formats one log line (without the line ending). See Format::Custom.