knurling-rs / defmt

Efficient, deferred formatting for logging on embedded systems
https://defmt.ferrous-systems.com/
Apache License 2.0
855 stars 79 forks source link

Request: panic-probe reset device on panic #868

Open Gibbz opened 1 month ago

Gibbz commented 1 month ago

I'm using panic probe with embassy rust. It's supposed to reset the device when there is a panic. The logging part is working fine, however the device stays stuck after the log. There is no reset.

Is there some extra setting required to cause it to reset after the log?

Edit: make this a feature request or it can be closed.

Urhengulas commented 1 month ago

It's supposed to reset the device when there is a panic.

Is this documented behavior of panic-probe? I don't recall that it is supposed to do that.

But I think it would be possible to add a cargo feature which does configure it to do a reset.

Gibbz commented 1 month ago

Ah! Okay maybe it's not. I was trying to use a crate to do this and it was giving me a warning saying panic probe does this.

I've done it manually for now. But I'll leave this open as a feature request then.

Urhengulas commented 1 month ago

Is it possible you could share your workaround? As a reference for others and maybe an implementation

Gibbz commented 1 month ago

I used the following

use core::panic::PanicInfo;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    cortex_m::interrupt::disable();
    defmt::error!("Panicked: {}", defmt::Display2Format(info));
    //panic_persist::report_panic_info(info);
    for _ in 0..2_000_000 { // delay before reset
        nop()
    }
    cortex_m::peripheral::SCB::sys_reset();
}