F0076 pin-1¶
Rule: Pin drivers live as long as the pin is used.
| Code | F0076 (stable, never reused) |
| Id | pin-1 |
| Category | pin |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | off | |
| medium | off | |
| big | off | |
| ai | off | |
| embedded | deny |
bedrock error: Pin driver dropped (let _ = Output::new(..), a temporary, end of main's scope): embassy disconnects the pin on drop |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Why¶
Embassy's GPIO wrappers (Output, Input, Flex) disconnect the pin's function on Drop: let _ = Output::new(..) binds to the wildcard pattern, which drops the value at the end of the statement, and the pin goes back to its reset state (usually a floating input) right after it was configured. The firmware looks like it drove the pin, because the register write happened, but the driver object that was supposed to hold that configuration for the firmware's life never lived past the line that created it.
Example¶
Donguru_template's firmware/src/main.rs shows the pattern to follow instead: let _pa4 = Output::new(p.PA4, Level::High, Speed::Low) binds the driver to a named (if underscore-prefixed) local that lives for the rest of main, so the pin stays driven. The generic Notion firmware checklist item on "destructors" is the same lesson in HAL-agnostic form: anything whose Drop undoes a hardware configuration needs an owner that outlives the configuration's intended lifetime.
How to fix¶
Bind every pin driver that must hold its configuration to a named variable (or a field of a struct kept in a task or a static) that lives as long as the configuration must, never to _. Where a pin genuinely is meant to be released, that release should be an explicit, visible call, not an implicit one from a temporary falling out of scope.
How it is checked¶
Check: src easy — let _ = <ctor>(..) (or an unnamed temporary passed by value and never bound) around a HAL GPIO constructor is a syntactic pattern syn can flag without needing the firmware model.
Source¶
Ported from embedded_bedrock's firmware check catalogue, PIN-1 (book/checks.md, detail in book/checks/pin.md). Found on: donguru_template main.rs; notion "destructors".
Configure¶
Allow one finding in the code with // spirit-level: allow(pin-1) <reason> (waivers); the code works there too, as in [lints.F0076].