Storage & Persistent Data

Two ways to keep data on the board, and one guarantee that covers both: values live in the board's storage partition, not the application image, so they survive re-flashing the app. (Erasing the whole flash wipes them.)

  • Store — typed key/value settings for device state: counters, calibration, flags. One namespace per store.
  • File — whole-file text I/O for things a person might read or edit: notes, exported JSON, a boot log.

There is no session on either one — nothing to set up first. Everything is ready the moment your program runs.

class

Store

Typed key/value settings. Construct a store with a namespace; every read and write rides that namespace, so several stores can coexist without colliding.

Example first

store.ts
import { Store, UART0 } from '@typecad/hal';

const settings = new Store('app');

const boots = settings.getInt('boots', 1);   // first boot reads the default: 1
if (boots === 1) {
  UART0.writeLine('first run');
}
settings.setInt('boots', boots + 1);

settings.setString('ssid', 'MyNet');
settings.setFloat('offset', -1.25);
settings.setBool('calibrated', true);

UART0.writeLine(settings.getString('ssid', '(none)'));

remove / clear remove(key): void

cleanup.ts
settings.remove('ssid');   // delete one key
settings.clear();          // delete every tc/app/* key this program wrote

All methods

MemberDescription
new Store(namespace)One namespace per store — 'app' becomes the tc/app/ settings subtree
getInt / getFloat / getString / getBool(key, default)Typed read; the default is required — unset keys read back exactly what you chose
setInt / setFloat / setString / setBool(key, value)Typed write, committed per key
remove(key)Delete one key
clear()Delete every key this program wrote in its namespace
class

File

Whole-file text I/O. Construct with the path; write, read, exists, and remove are all there is.

Example first

file.ts
import { File } from '@typecad/hal';

const log = new File('/log.txt');

log.write('boot\n');              // overwrite (creates the file when absent)
if (log.exists()) {
  UART0.writeLine(log.read());        // 'boot\n'
  log.remove();
}

A boot counter that survives re-flashing is two lines:

boot-counter.ts
const boot = new File('/boot-count.txt');
boot.write(String(Number(boot.read() || '0') + 1));

All methods

MemberDescription
new File(path)Whole-file text I/O — no open()/close()
write(text)Overwrite (creates the file when absent); there is no append
read()The whole file — '' for a missing file and an empty file alike
exists()Distinguish missing from empty
remove()Delete the file

Which one to use

StoreFile
ShapeMany typed keys under a namespaceOne whole text document per path
Best atCounters, calibration, flagsNotes, exported JSON, logs a person reads
WritesPer-key commitsWhole-file rewrites
TypesTyped pairs, required defaultsNone — it's text
© 2026 typeCAD — code-defined electronics github