F0109 flt-12¶
Rule: The boot counter is read before the first output is enabled.
| Code | F0109 (stable, never reused) |
| Id | flt-12 |
| 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 crash loop must not re-enable the outputs on every boot; an estimate by statement order, and no firmware reads boots_since at boot yet |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
reads |
list of strings | ["boots_since", "boots_since_crash"] |
names whose use reads the crash record's boot counter |
Why¶
embassy has no per-task restart: after a panic the whole chip resets. If the panic comes back every boot, the firmware enables its outputs, crashes, resets and enables them again, many times a second. The crash record counts the boots since the last crash (boots_since); reading it before the first output is enabled lets the firmware stay in safe mode after repeated crashes: outputs off, host link up, crash record served.
Example¶
let crash = last_reset::boot();
if crash.map_or(false, |c| c.boots_since < 3) {
return safe_mode(spawner).await;
}
let gate_en = Output::new(p.PA8, Level::Low, Speed::Low);
How to fix¶
Read boots_since at boot, before any Output::new or a function that builds one; after three crashes in ten seconds stay in safe mode.
How it is checked¶
src, an estimate: in the entry point, the statement that first reads a name of reads (directly or through a function of the source) must come before the first statement that builds an output driver, as pin-2 finds them.
Configure¶
[lints.flt-12]
level = "deny"
reads = ["boots_since", "boots_since_crash"]
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(flt-12) <reason> (waivers); the code works there too, as in [lints.F0109].