Skip to main content

Module panic_report

Module panic_report 

Source
Expand description

Panic capture and last-panic persistence.

Flow on a panic (or an Xtensa exception, which esp-hal turns into a panic!):

  1. The banner (message, location, backtrace) and the most recent log lines are moved out of the ring into .rtc_slow.persistent β€” RTC slow memory, which esp-hal only zeroes on power-on and preserves across software resets.
  2. The same bytes are written to NVS (best effort, skipped when the flash is busy or storage is down β€” the RTC copy is the fallback).
  3. The boot-loop counter increments; after MAX_PANICS panics without a 30 s stable run (see mark_stable) the firmware halts instead of resetting. Otherwise it reboots.

On the next boot report_last_panic replays the stored bytes into the log ring, so inv monitor shows the previous crash as soon as a host connects. Live output during the panic itself is impossible: the USB transfer pipeline is owned by the embassy executor, which a panic handler cannot drive.

The report stays in NVS/RTC until the next panic overwrites it β€” the web UI can later expose it as an endpoint.

StructsΒ§

RtcCell πŸ”’
Wrapper making RtcSnapshot a 'static interior-mutable cell (avoids static mut, which edition 2024 rejects references to).
RtcSnapshot πŸ”’
Snapshot layout in .rtc_slow.persistent.

ConstantsΒ§

MAX_PANICS πŸ”’
Consecutive panics without a stable run after which the firmware halts instead of resetting (boot-loop protection).
RTC_MAGIC πŸ”’
Magic marking a valid RTC snapshot.
SNAPSHOT_LEN πŸ”’
Panic payload staged in RTC slow memory (12-byte header + data; RTC slow has 8 KiB in total).

StaticsΒ§

IN_PANIC πŸ”’
Guards against a panic while panicking (would otherwise recurse).
RTC πŸ”’
The persistent snapshot. esp-hal zeroes this section on power-on only, so the contents survive the software reset issued below.

FunctionsΒ§

halt πŸ”’
Spin forever with interrupts masked.
mark_stable
Clear the boot-loop counter; called once the firmware ran stably for 30 s (see the stable_marker task in main).
panic_handler πŸ”’
The #[panic_handler] of this firmware (esp-backtrace’s built-in handler is disabled in Cargo.toml so the report can be captured here).
report_last_panic
Replay the persisted last-panic report into the log ring.