F0108 flt-11¶
Rule: The panic and HardFault handlers put the board into its safe state before anything else.
| Code | F0108 (stable, never reused) |
| Id | flt-11 |
| Category | flt |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | off | |
| medium | off | |
| big | off | |
| ai | off | |
| embedded | warn |
a panic in control code turns the outputs off before it records and resets; warn while no board generates safe_state() yet, then deny |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
calls |
list of strings | ["safe_state"] |
functions that put the outputs into the board's safe state, by last path segment |
before |
list of strings | ["exc_return", "disable"] |
calls and macros that may come first: reading EXC_RETURN, disabling interrupts |
Why¶
A panic in a control module means the code that drives a power stage or a switch is wrong. The only safe action is to turn the outputs off first and ask questions later. The panic handler and the HardFault handler call the board's safe_state() before anything else: the crash capture writes a record and formats a message, and a gate driver does not wait for that.
The handler's order:
exc_return!()(HardFault only) and disabling interrupts;safe_state(): raw register writes that turn the outputs off, no HAL calls, no formatting;- capture the crash (
bedrock_crash); - log over defmt when a debugger is attached;
- reset.
The handler is the second line of defence: the timer break input, the gate driver's enable pull-down and the watchdog cut the outputs without software.
Example¶
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
board::safe_state();
bedrock_crash::capture_panic(info, uptime_ms());
bedrock_crash::panic_reset()
}
How to fix¶
Call the safe-state function first (the parameter calls names it; before lists what may come before it). A board with no output whose state matters turns the lint off in its spirit_level.toml, with that reason.
How it is checked¶
src: the first call or macro in the #[panic_handler] function and in HardFault that is not in before.
Configure¶
[lints.flt-11]
level = "deny"
calls = ["safe_state"]
before = ["exc_return", "disable"]
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(flt-11) <reason> (waivers); the code works there too, as in [lints.F0108].