Files
frame/poc/apps/m1_hardware
Lainandlain e8ac2c1c5d docs(evidence): complete M1-008 artifacts and draft owner pass record (#9)
## Summary

Completes the remaining M1-008 evidence gaps and drafts the owner pass
record (requirement **M1-008**; heap/stack instrumentation also closes
the M1-006 soak heap-integrity note "internal_free not evaluable").

### Firmware: `metrics` console command (console_service.{cc,hh})
- Machine-parseable `heap internal|psram free=<u> largest=<u>
min_ever=<u>` (heap_caps 8-bit pools) and `task <name>
stack_hwm_bytes=<u>` per FreeRTOS task via `uxTaskGetSystemState` (all
tasks: frame-sd/board/display/prov-mon/console_repl/IDLE/ipc/Tmr
Svc/esp_timer/wifi/tcpip/sys_evt).
- ESP-IDF Xtensa reports the high-water mark directly in bytes
(`StackType_t` = uint8_t), so the unit is documented in the field name
itself.
- Companion one-line sdkconfig change:
`CONFIG_FREERTOS_USE_TRACE_FACILITY=y` (required for
`uxTaskGetSystemState`; necessary build-config companion to the mandated
API).
- No JSONL/display/snapshot changes; no new files; partitions untouched;
clang-format 18.1.8 clean; build 0 warnings.

### Evidence (poc/evidence/m1-20260831/)
- `build/m1_frame_m1_hardware.map` — linker map of the instrumented
build (binary sha256 a0e937ba… pinned in the manifest note).
- `build/m1_size_components.txt` — `idf.py size` summary + `idf.py
size-components` breakdown.
- `build/m1_metrics_samples.txt` — three on-device samples (t≈14 s
boot-ish / post-selftest / post-60 s-idle) + selftest + status --json.
Highlights: internal heap min_ever 123295 B (largest block 53248 B),
PSRAM min_ever 8362016 B, smallest task stack HWM ipc0 552 B,
console_repl 2652 B free of 6144 B, idle drift ~36 B/min.
- `M1-PASS-RECORD.md` — completeness table for every M1-008 artifact
(path+sha256), M1-001..007 one-line acceptance summary, known
limitations; **ships PENDING owner confirmation, does not record Pass**.
- manifest.json: 3 artifact entries (+notes); .gitignore: re-include
`poc/evidence/**/build/` (map/size/metrics), same mechanism as the
existing `!poc/evidence/**/*.log`.

## Requirement refs
- M1-008 (pass-record artifacts: linker map, size-components, heap/stack
metrics, owner record draft)
- M1-006 (heap-integrity: heap free/largest/min-ever + per-task stack
HWM now instrumented)

## Gates
Build 0 warnings (clean rebuild, evidence-logged); ruff format/check,
pyright (0 errors), pytest 31 passed 1 skipped, frame-evidence validated
(1 manifest, 47 artifacts).

Co-authored-by: ania-lain <[email protected]>
2026-08-31 18:10:32 +08:00
..

Frame M1 Hardware Firmware

This isolated ESP-IDF application implements the 0.1.0-dev.1 hardware-status vertical slice for the Waveshare ESP32-S3-RLCD-4.2 N16R8 board. It does not load dynamic plugins.

It checks the ESP32-S3 target, 16 MiB flash, 8 MiB PSRAM, ST7305 display, shared I2C RTC/SHTC3, active-low KEY, SDMMC TF card transitions, Wi-Fi STA configuration with softAP web provisioning, native landscape 400x300 display output, and USB Serial/JTAG console output.

Wi-Fi provisioning persists the last credentials as plaintext JSON at /system/wifi.json on the internal system_fs partition. This is a user-approved development-board exception (SEC-010, recorded in _doc/requirements-v4.2.md under M1-007): ESP-IDF v6.0.2 requires Flash Encryption or an HMAC eFuse key to protect NVS encryption keys, and both provisioning steps are irreversible on the single development board. Production boards must switch to NVS-encrypted credential storage before shipping. The password never appears in UART output, logs, or status.

On boot the device auto-connects with the saved credentials. When no valid configuration exists, or after 5 disconnects without an IP address or 60 seconds without obtaining one, it starts an open setup hotspot Frame-Setup-XXXX at 192.168.4.1. The portal's network list is populated from a live scan; hidden networks cannot be typed into the browser form — configure those through the console with wifi set <ssid> hidden. Holding KEY for 3 seconds or longer also requests the setup hotspot; such a hold is a portal command and does not count as a button press.

Buttons

The board's three buttons are all observable:

  • KEY (GPIO18, active-low): a release under 1 second counts as a short press, 1-3 seconds as a long press, and 3 seconds or more requests the setup hotspot (a portal command, not a press). Both counters appear on the display and in status as KEY: short/long.
  • BOOT (GPIO0, active-low with the internal pull-up): the same release bands, under 1 second short and 1 second or more long, counted as BOOT: short/long. It is a strapping pin, so the firmware only reads it at runtime and never drives it, and it has no portal binding.
  • RST: hardwired to the chip reset line, so it cannot be sampled as a GPIO. Instead the firmware increments a persistent boot counter once per boot (NVS namespace frame, key rst_cnt) and reports it as RST: count / reset_count; pressing RST reboots the board and increments the counter.

Timezone

Internal time handling is strictly UTC: the RTC chip, JSONL telemetry, and the machine utc fields all carry UTC with a Z suffix. Only human-facing surfaces convert to local time — China Standard Time (UTC+8, no daylight-saving transitions): the display RTC line, the text status output, and rtc status render local time labeled UTC+8, and rtc set interprets its argument as UTC+8 local time (the firmware converts it to UTC before writing the chip).

Real-Time Clock

The PCF85063 RTC shares the I2C bus with the SHTC3. Nothing writes the chip from the factory, so after a power loss its oscillator-stopped (OS) flag is set and the time reads invalid on the display (-) and in JSONL ("utc":""). The firmware now provides two time sources:

  • SNTP: once the station has an IP address, the firmware starts SNTP against ntp.aliyun.com and pool.ntp.org, and on the first successful sync writes the UTC time to the RTC (log line rtc synced from sntp). SNTP keeps running; periodic re-syncs update the system clock.
  • Console: rtc set writes the chip manually (the argument is UTC+8 local time; see Timezone).

A CR1220 coin cell on the board keeps the RTC running across power-off. Without a battery (or with an empty one) every boot loses the time and the OS flag returns — install a fresh cell for persistence across power loss.

Build with the exact IDF tag:

. "$IDF_PATH/export.sh"
cmake --preset default --fresh
cmake --build --preset default

The console is available through USB Serial/JTAG at 115200 baud. Useful commands:

status [--json]
rtc status
rtc raw
rtc set YYYY-MM-DD HH:MM:SS
wifi set <ssid> [hidden]
wifi clear
wifi reconnect
wifi status
prov status
prov start
prov scan
storage probe
storage status
selftest
metrics

rtc status reports validity, unix time, formatted UTC, formatted UTC+8 local time, and the OS-bit state; rtc raw dumps PCF85063 registers 0x00-0x0A with a decode; rtc set parses YYYY-MM-DD HH:MM:SS as UTC+8 local time, validates the ranges (calendar round-trip), converts to UTC, writes the chip, and re-reads it to confirm.

metrics prints machine-parseable memory lines: heap internal free=<u> largest=<u> min_ever=<u> and heap psram ... (8-bit-capable pools, min_ever from the boot-time watermark), then one task <name> stack_hwm_bytes=<u> line per FreeRTOS task, where the high-water mark is the minimum-ever free stack in bytes (on this ESP-IDF Xtensa port StackType_t is one byte, so the kernel reports the mark directly in bytes).

Do not place real credentials in command transcripts or committed evidence. wifi set asks for the password after parsing the command so it is not stored in command history; terminal software must also keep local echo disabled. The password is persisted only inside /system/wifi.json under the SEC-010 development-board exception and is never echoed back.