Boot counter that survives re-flashing
Store and File side by side — a typed counter in settings, a human-readable boot log, and the guarantee that ties them together.
Click through the files — it's the whole project
Boot counter that survives re-flashing — Visual Studio Code
Select a file from the explorer
Store + File Store · File · settings
What's going on
- The counter lives in a
Store— typed key/value settings, one namespace. The read takes a required default, so first boot is explicit:getInt('boots', 1)returns exactly 1 when the key doesn't exist. - The
Fileholds a note a person could read — a boot log line. Note there is no append:write()rewrites the whole file, so a log that grows isn't what File is for. The latest line is. - The guarantee both rest on: values live in the board's storage partition, not the application image, so re-flashing the app leaves them alone. Erasing the whole flash wipes them — that's the boundary.
Prove it
terminal
npx @typecad/hal build --compile --upload --port COM4Flash it, watch the counter, flash it again:
serial monitor
boot #1 — re-flash the app, the number keeps counting
boot #2 — re-flash the app, the number keeps counting
boot #3 — re-flash the app, the number keeps countingWhere to go next
- Storage & Persistent Data — both classes, the defaults rule, and the storage guarantee
- Boards — where the storage partition comes from