MelexisIO SCPI Commands
Loading...
Searching...
No Matches
EEPROM SCPI Command Reference

Compact reference for the EEPROM emulation interface. The module stores a JSON document in RAM (eeprom_buffer) and persists versioned snapshots as binary records in a dedicated Flash sector.

‍On system startup / reset the firmware loads the last valid persisted record (latest intact) into the RAM buffer automatically.


1. Binary Record Layout

Each persisted record (little endian):

uint32 magic = 0x1504
uint32 json_len = N (bytes, excluding terminating NUL)
uint32 crc32 = zlib_crc32(JSON, start=ZLIB_CRC32_START)
uint8 json[N] // UTF-8 JSON payload
uint8 0x00 // terminating NUL
padding 0..3 bytes (0x00) to 4-byte alignment

Records are appended sequentially until no space remains or corruption is detected. An erased word reads 0xFFFFFFFF.


2. Command Summary

Command Parameters Action
:EeProm:INIT *(none or index)* Load latest record (no param / -1) or 0-based record index.
:EeProm:ERASE - Clear RAM buffer only (Flash untouched).
:EeProm:DUMP - Pretty-print current RAM JSON.
:EeProm:SAVE optional 0/1 Persist RAM JSON (append 0/None or 1 to force erase all).
:EeProm:RECords? - List all valid / first corrupt Flash records.
:EeProm:Object? key[.prop] Pretty-print object at top-level key.
:EeProm:String key[.prop],value Set string.
:EeProm:Integer key[.prop],value Set integer.
:EeProm:Float key[.prop],value Set float.
:EeProm:Boolean key[.prop],value Set boolean (0/1/true/false/on/off/yes/no).
:EeProm:String? key[.prop] Get string.
:EeProm:Integer? key[.prop] Get integer.
:EeProm:Float? key[.prop] Get float.
:EeProm:Boolean? key[.prop] Get boolean.
:EeProm:DELete key[.prop] Delete key or property.

Notes:

  • Keys are case-sensitive; command mnemonics are case-insensitive.
  • Nested access uses . (e.g. net.port). Missing objects are auto-created on set.

3. INIT Behavior

:EeProm:INIT scans the sector, validating consecutive records:

  1. Stop at first 0xFFFFFFFF (free space) or structural/CRC error.
  2. Latest fully valid record is chosen by default (this same logic is run automatically at startup).
  3. :EeProm:INIT,<n> loads record index n (0-based) if valid; aborts if out of range.
  4. If the newest record is corrupt, the last prior valid record is loaded.

Return messages (examples):

EEPROM loaded latest record len=400 crc=0x99887766
EEPROM loaded record 2 len=128 crc=0x1A2B3C4D
EEPROM loaded previous valid record len=256 crc=0x55AA9911 (newest corrupted)
EEPROM record 5 not found
EEPROM empty (no records)
EEPROM corrupted -> cleared

4. SAVE Behavior

Syntax: :EeProm:SAVE or :EeProm:SAVE,«erase» where «erase» is 0 or 1.

Flow:

  1. If RAM buffer is empty (""), it is converted to {} before saving.
  2. If «erase» = 1: erase sector, write record at offset 0 (no duplicate check).
  3. Else: scan for first free slot; validate chain.
  4. If last record matches (same length, CRC, and bytes) → skip (no Flash write).
  5. If insufficient space → erase sector then write at offset 0.
  6. On corruption during scan → erase sector then write at offset 0.

Messages:

EEPROM unchanged (skip save) len=400 crc=0x99887766
EEPROM saved: json=420 bytes crc=0xDEADBEEF total=436 bytes @offset=0x0000 (forced erase)
EEPROM saved: json=128 bytes crc=0x12345678 total=140 bytes @offset=0x01B4 (sector erased)

Empty JSON example:

:EeProm:ERASE
:EeProm:SAVE
--> EEPROM saved: json=2 bytes ...

5. RECords? Output

:EeProm:RECords? prints table until free space or first corruption:

Idx Offs Len CRC Status
0 0x000 256 0x1234ABCD OK
1 0x110 300 0x89EF0123 OK
2 0x23C ---- -------- CORRUPT (bad magic 0xFFFF0000)
Summary: valid=2 total_scanned=3 (stopped on corruption)

Status meanings:

  • OK - Structure + CRC valid.
  • BADCRC - CRC mismatch (scan stops).
  • CORRUPT - Structural issue (magic, length, terminator, overflow).

6. GET / SET Formats

Outputs:

  • String: key="value"
  • Integer: key=123
  • Float: key=1.23
  • Boolean: key=0|1 On success for set/delete: OK.

Error samples:

ERR: get 'wifi.ssid' not found
ERR: set 'val' buffer too small
ERR: invalid integer
ERR: delete 'wifi.mode' not found

7. Deletion

:EeProm:DELete key removes whole key. :EeProm:DELete parent.child removes only child from object parent. Nonexistent targets report an error.


8. Edge Cases & Limits

Case Handling
Empty buffer save Auto-converted to {}.
Duplicate save Skipped if identical (wear reduction).
Full sector Auto-erase (unless skip) then write at offset 0.
Corruption mid-chain Stop scan; latest prior valid used; next save may erase.
Oversized JSON Rejected with error before Flash write.

Maximum JSON length per record: EE_SECTOR_SIZE - 12 - 1 - padding.


9. Typical Session

:EeProm:INIT
:EeProm:String device.name,NodeA
:EeProm:Integer net.port,502
:EeProm:SAVE
:EeProm:String device.name,NodeA (unchanged)
:EeProm:SAVE --> skip
:EeProm:RECords?
:EeProm:INIT,0 (load oldest)
:EeProm:SAVE,1 (force new baseline)

10. Return Codes (Internal)

  • Success operations return HAL_OK (0) to caller layer.
  • Flash / validation failures return HAL_ERROR (non-zero) and print an error if verbose.

11. Verbosity

Internal helper APIs may suppress printing when verbose == 0. SCPI command layer typically prints always.


End of EEPROM SCPI reference.