Repository navigation
fix(firmware): stop settings writes from wearing out the flag page - #16
Merged
Merged
Conversation
Every saved command erased the settings page right away, with no limit, so a program changing the colour with 24 30 could wear the page out in minutes. The same page holds the bootloader flag that every recovery path writes. Settings now reach flash once nothing has changed for 1 s. Up to 16 writes can follow each other, then one more per minute; later changes wait in memory. 24 00 still writes at once. The timing lives in shifter.c (sh_saves_*) so the host tests can drive it with a fake clock. If the flag write fails twice, the unit now leaves USB and blinks red instead of resetting into the application or looping through a fault. A failed settings write is retried once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every saved command (
24 21to24 23,24 30to24 35, the mode button, the H/SEQ switch) erased the settings page at0x0800F000right away, with no limit. A program that keeps changing a saved setting, for example a rev-light script using24 30, got 25 to 40 erases a second. At the STM32F103's rating of 10,000 erases, the page would be worn out in under ten minutes.The same page holds the bootloader flag. Every way into update mode writes it (
24 00, both buttons, fault, stall, USB recovery), and write errors were ignored. A worn page could leave a unit that can't be put into update mode over USB.Approach
sh_saves_*inshifter.c, used bymain.c): a change is written once nothing has changed for 1 s. Up to 16 writes can follow each other, then one more per minute. Later changes wait in memory and are still in use (LEDs, reports). Only writes that erased the page count against the limit.24 00writes a waiting change at once, ignoring the wait and the limit.enter_bootloader()retries once. If that also fails, the unit detaches from USB and blinks all LEDs red, instead of resetting into the application or looping through fault, erase, reset.test_shifter.pydrives it with a fake clock, including the clock wrapping after 49 days.docs/protocol.mdsays saved commands write flash and that continuous colour changes must use24 20.Cost: 320 bytes of code, 12 bytes of RAM.
Automated validation
make -C firmwarebuilds without warningsmake -C firmware testpasses: 81 tests, differential tests ran (stock image, SHA-25696da5e6b…), nothing skippedNew tests:
test_shifter.SettingsWrites(6): quiet time, urgent write, the 16-write burst, refill once a minute, no stored-up time, clock wrap.test_emulated.OpenShifter:24 00writes a waiting change before the resetflash_worn) gives two flag attempts, a USB detach, and red/off LED frames with no resetAgainst the current firmware (0.5.0), three of the four new emulator tests fail as expected. The
24 00one passes there too, since 0.5.0 wrote everything at once.Existing emulator tests now wait 1.1 s before they read the settings page or power-cycle. That includes the differential ones, for both images.
Hardware testing
0.5.0+pr16(SHA-2565ac9798b…):openshifter_flash.py. The unit restarted asOpenShifter 0.5.0+pr16.24 30colour changes in 0.6 s, then 16 changes 1.15 s apart, then a replug. The unit came back with change 15 of the second set, so the 40 cost one write and the 16th waited.24 00: a second install from0.5.0+pr16entered update mode and finished.Limitations and follow-up