Skip to main content
NewEpisode 3a is out: Carry the conversation onWatch →

This part is for members

Membership opens soon. Leave your email and we'll tell you the day it does. Founding members get the launch price.

Keep watching the free parts
Data & comms · 28c

Parameter storage 3: the lock that protects the flash

The last part on parameter storage: who else writes flash, and the lock that protects it. It opens with the whole episode on one framework page: every flash write (a host save, system command 2; the friction table, 4 / 253; clearing the error records, 254; factory reset, 255; and the error record each new fault queues by itself) goes through one mailbox, Storage_cmd, and the store task in step 9 of the 1 ms task, AppStoreUpdata1ms, whose first call is the guard IsFlashWriteGuard: at most 20 writes in a 60 s window. The page: the writers on the left; the mailbox and the 1 ms task in the middle (the guard: count, window, lock; then a switch with nine cases); flash's three keys on the right (AllParam 976 bytes, ErrorRecord 64, TqFcTable 1,444); the real run beside. Running example: a host tuning tool that saves every 100 ms from 600 ms, 20 times, with the drive disabled. Five stops: who writes flash (every case of set_app_Sys_cmd is refused while enabled and otherwise puts one number in the mailbox; a new fault queues its own record in the slow status scan); the guard (three statics: write count, window timer, lock flag; a write or erase adds one, the first starts the window, the timer adds 1 ms per call while the count is above zero, back to zero at 60,000 ms, lock at 20; it returns the flag); saves 1–19 (seven or eight writes each, no erase, status 2); save 20 (2,500 ms: the count goes to 20 before the check, so the same call locks and refuses it and only 19 get through; status −3, ERROR_FLASH_STORE at 2,501 ms, bsp error code 32, app error 1024 at 2,501.05, the drive disabled); locked for good (the last line returns the flag whatever the command, so every millisecond sets the error again; factory reset at 2,700 refused; a clear at 3,000 is undone at 3,001; disable at 3,100 and enable at 3,200 do nothing; a clear at 62.5 s the same; the flag lives in RAM, so only a power cycle helps). Then error records (enabled in a PP move, nFault at 1,200 ms, error word 8192; the 16-entry list shifts down one, and at 1,201 ms 64 bytes go to ErrorRecord, eight writes, counted by the same guard; the lock's own error is never recorded); factory reset (interrupts off, defaults, pack, delete the friction table, write, reset: nine writes, reset at 601 ms, and 0x6085 is back at 1,966,080 after the reboot; refused under the lock); the fix (fork branch fix/flash-guard-lockout, one function: check before counting, guard only writes; PATCHED run: all 20 saves succeed, the 21st is refused and sets the error once, and after clear → disable → enable the PWM is on at 3,200.05 ms). Not covered: the friction table → episode 20; fault handling and clearing errors → episode 21; MAVLink system commands → episode 32; FlashDB stays a black box. Your turn: 25 saves on the patched firmware → 21–25 refused, clear at 3,200, PWM on at 3,400.05 ms.

Up next29a · Product contract 1: one entry, eleven files→