Expand description
Panic capture and last-panic persistence.
Flow on a panic (or an Xtensa exception, which esp-hal turns into a
panic!):
- 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. - 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).
- The boot-loop counter increments; after
MAX_PANICSpanics without a 30 s stable run (seemark_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
RtcSnapshota'staticinterior-mutable cell (avoidsstatic 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_markertask inmain). - panic_
handler π - The
#[panic_handler]of this firmware (esp-backtraceβs built-in handler is disabled inCargo.tomlso the report can be captured here). - report_
last_ panic - Replay the persisted last-panic report into the log ring.