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 · 28a

Parameter storage 1: one save, one power cycle

The first episode of the data & comms section: how a parameter the master changes survives a power cycle. It opens with the whole episode on one framework page: a value the master writes lives only in RAM (the app layer's kApp* tables; some setters also copy it into the control layer's kAxis), and nothing goes to flash until the host sends save. Then the 1 ms task packs every saved value into one 976-byte block (kFlashStorage) and FlashDB stores it under the key AllParam; at power-up the drive loads its defaults, reads the block back over them, and runs every setter again. The page: RAM on the left, the block in the middle, flash on the right; the save path along the top, power-up along the bottom. Running example: the master sets 0x6085, the quick-stop deceleration, to 6,000 rpm/s (13,107,200 counts/s² over CANopen, times 60/131072 in the CiA402 layer); written at 600 ms, saved at 700 ms, power off at 900 ms. The bench: episode 6's board build with the board's real drv_nor_flash.c, FlashDB 2.1.1 and FAL, on a model of the 8 MB NOR chip kept in a file; a power cycle is a second run on the same image (FLASH=1 sil-mac/ep06/build_boot.sh → boot_flash). Seven stops: the write (set_app_Quick_stop_deceleration checks 0 ≤ 6,000 ≤ 1,966,080 and stores it in kAppMotionParam; it counts at once, a quick stop in the same run disables at 1,315 ms); the save command (MAVLink SystemCmd 2 → set_app_Sys_cmd; refused while enabled, returning 3 with status −2; otherwise it only sets the Storage_cmd mailbox to 2); the 1 ms task (step 9 of UnrealTimeBase1ms, AppStoreUpdata1ms, opens the mailbox at 701 ms; the write guard passes → 28c; busy); packing the block (flash_param_update, 192 assignments, every value copied again whether changed or not; 6,000 lands at byte 316); into flash (bsp_flashdb_write → flashdb_write looks up the table registered at power-up: AllParam, &kFlashStorage, 976 bytes → fdb_kv_set_blob; the bench's log: a new copy at 0x320a48, the old one marked deleted, 8 writes, no erase; status 2, success, mailbox back to 0); power-up, defaults first (in HalInit, right after the system timer, AppParamInit: 0xFFFFFFFF × 60/131072 = 1,966,080); reading it back (AppStoreInit packs the defaults into the block first, which is the starting value on a new chip: 1,024 erases and 1,040 writes on the first power-up, none now; then it calls the store task itself to read: flashdb_read 976 bytes → flash_param_init → app_param_update runs every setter again; HalInit returns at 0 ms with 6,000, the bus settles at 507 ms). The proof: enabled at 1,000 ms, a move at 600 rpm, quick stop at 1,200 ms at 585 rpm, about 98 ms of ramp, disabled at 1,315.05 ms; the same write without a save disables at 1,231.05 ms. Not covered: which parameters are in the block and what the setters do at power-up → 28b; the write guard, error records and factory reset → 28c; only MAVLink can send save, so CANopen and EtherCAT can change 0x6085 but not keep it; how a CANopen write arrives → episode 30, MAVLink → episode 32; FlashDB stays a black box. Your turn: 0x6085 = 3,000 saved, power-cycled: disabled at 1,412.05 ms.

Up next28b · Parameter storage 2: what a save does not keep→