|
SDK for TESAIoT Dev Kit
API reference & tutorials (ModusToolbox)
|
The same six names exist on mtb-mpy, where they come from lfs_wifi_creds.c inside libbento_mpy.a — an archive, not shipped as source, whose file I/O runs by executing Python open() through the MicroPython VFS. That is why the mtb-mpy version needs a VM and cannot exist on this variant. The shipped C store reaches the same file through bento_storage instead, and is byte-compatible on purpose.
| mtb-mpy (archive, not readable here) | mtb-only (lfs_wifi_creds_c.c, shipped) | |
|---|---|---|
| File I/O | Python open() through the VFS bridge | bento_storage_read_file() / bento_storage_write_file() over plain lfs2 |
| Calling context | MicroPython task only, after the VFS mount | any task once bento_storage_init() has mounted |
| lfs_wifi_creds_init() | real bring-up; gc_collect() first (~16 KB GC heap) | no-op — bento_storage_init() owns bring-up |
| lfs_wifi_creds_deinit() | invalidates Python handles before soft reset | no-op |
| lfs_wifi_creds_ready() | store initialised and VFS mounted | forwards to bento_storage_ready() |
| lfs_wifi_creds_needs_resave() | true after a legacy XOR-32 file was read | always false — writes only the current format |
| Write path | whole write inside wifi_creds_lock(), deferred to a REPL-idle flusher | snapshot under the lock, write outside it, immediately in the WiFi worker |
Shared contract — the byte-compatible on-disk format (a board moved between variants keeps its saved networks):
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | magic 0x57494649 ("WIFI", QSPI_WIFI_CREDS_MAGIC) |
| 4 | 2 | version 1 (QSPI_WIFI_CREDS_VERSION) |
| 6 | 2 | count, 0 to 6 |
| 8 | 600 | entries, 6 × sizeof(qspi_wifi_entry_t) = 100 |
| 608 | 4 | CRC32 (poly 0xEDB88320) of bytes 0 to 607 |
Both readers accept the legacy XOR-32 checksum on read so a pre-migration file still boots with its networks; both writers emit CRC32 only. The shipped implementation, verbatim — it is short enough to be its own specification:
Locking. wifi_creds_lock() / wifi_creds_unlock() protect the shared g_boot_wifi_creds globals, not the file. wifi_init.c also read-modify-writes /.wifi_creds directly without touching the globals; the only lock over the file itself is the bento_storage layer's own.