Hands-onESP32-C3MRRC Modern2026-11-22
An ESP32-C3 Terminal
That Keeps Talking on a Train
A FoloToy AI Passport turned into a handheld terminal for MRRC Modern: 240×320 panel, four-position knob, one TLS socket carrying control, PCM16 audio both ways and the spectrum. This is what it took to stop the stutter — five independent causes, each one found by measurement rather than by intuition — and the numbers that proved each of them.
What the thing is
The Passport is a wearable with an ESP32-C3, 8 MB of flash and no PSRAM. Everything shares one 400 KB pool of SRAM and one 160 MHz core: Wi-Fi, TLS, a 240×40 waterfall, a spectrum trace, the audio path and the UI renderer. It talks to the same MRRC Modern server a PC does, so the interesting part is not the feature list but making a $3 microcontroller keep a real-time audio stream alive on that budget.
The stutter was five problems, not one
The symptom was identical every time — chopped audio — and the first three fixes made it worse because each was aimed at the wrong layer. What finally worked was refusing to touch anything until a measurement said which layer was short.
- Receive queueing, not bandwidth. The device received 25.6–28.6 KB/s of a 31.3 KB/s stream while a reference client on the same Wi-Fi received all of it. Raising the TCP window twice changed nothing, because the window was never full: the per-connection receive mailbox held 6 pbufs, the out-of-order queue 4, and the A-MPDU receive block-ack window 6. With those at 8/8/16 the device receives the whole 49 KB/s stream.
- Playback started from an empty ring. The server does not send a smooth 50 frames/s: measured arrival gaps were p95 67–74 ms and p99 230–299 ms. With no cushion, every gap starved the I2S DMA and the codec filled it with silence — 3–5 ring-empty wakeups per second. A 160 ms pre-buffer, and re-buffering after 200 ms dry, took that to zero.
-
The server was blocked on us. Its own counter,
max pump stall, read 5791 ms — it had been waiting nearly six seconds for this client to read. After the queueing fix: 3 ms. -
The uplink ran under Nagle. Neither
tcp_transportnoresp_websocket_clientever callssetsockopt, so 641-byte PCM writes waited for the previous segment to be acknowledged. 100 of 323 sends blocked longer than 30 ms, the worst 89 ms. SettingTCP_NODELAYand doubling the send buffer: 0–3 slow sends, worst 9–17 ms, and the server reportsqueue_drops=0on every transmission. - A microphone gain that only clipped. Transmit audio peaked at 100% with 5% of samples clipped. Two gains were stacked: the codec's analog PGA at +30 dB and the server's software gain at +12 dB. Lowering the server to +3 dB did not help (5.0% → 5.8%), which is what proved the peaks were already at the ADC. At 0 dB the peak is 40% and a full transmission adds zero clipped samples.
Then the UI turned out to be the CPU
With the audio clean, taskLVGL was still eating 56–61% of
the core with only 7–14% idle. Rather than guess which widget was
expensive, two counters went in: bytes flushed to the panel, and the same
pixels bucketed into 32-row bands. A full screen is 153,600 bytes, so the
first number converts directly into “screens per second”.
With the UI timer stopped the flush counter read 0 B/s:
nothing was repainting for its own sake. The band histogram then named the
culprits — the frequency and the info row were 40% of every repaint,
because the code rewrote those labels whenever the state sequence moved,
and lv_label_set_text() invalidates even when the string is
identical.
Fixing that took the flush volume from 526 KB/s (3.5 screens/s) to 344
KB/s and taskLVGL from 56–61% to 42%. Control experiments
then split what was left: freezing the waterfall gave 36–39%, freezing the
spectrum trace gave 15–17%. The trace cost 25 CPU points
while covering only a quarter of the flushed area — LVGL pays per
anti-aliased segment, not per pixel, and a 240-vertex polyline has 239 of
them. One vertex every 2 columns instead of every column: same line
weight, same flushed area, taskLVGL 28–30%.
Memory: the waterfall as palette indices
The largest single .bss block was the waterfall, 19,200 bytes
of RGB565. Stored as one byte per pixel into a 256-entry palette it costs
10,624 bytes including the palette LVGL insists on keeping in front of the
pixels. Steady-state free went 48 → 57–59 KB and the largest contiguous
block 27–42 → 38–48 KB, for 1–2 CPU points of palette lookup while
blending. On this chip the contiguous block is what the TLS handshake
needs, so that trade is worth making.
Setup with no network of any kind
The case carries an NTAG213. It is a passive tag: a phone can read it, the MCU cannot see it, and there is no reader on the board. So a phone cannot hand this device anything unless the device becomes the access point — which is what it does when it has no credentials, or after two failed connection attempts 30 seconds apart. SoftAP, DHCP on 192.168.4.1, one page with five fields, then a reboot into station mode.
The settings live in NVS and override the compile-time defaults, so a provisioned unit never needs a rebuild. And because the Wi-Fi driver writes an NVS entry per boot, the 24 KB partition eventually fills: the save path logs the NVS statistics and, on failure, erases and retries once. Setup is the one moment where wiping is safe.
What the knob actually controls
Six positions cycle on an OK double-tap — frequency, channel, step, filter, volume, microphone gain — while the arrow keys only change the value of whichever one is current. They briefly shared the job: arrows cycled the radio group on a double-tap, which sounds reasonable until you remember that sweeping the band is rapid tapping on the same key. Measured press-to-press intervals for a double-tap were 250–420 ms, the same range as two tuning taps, so the two could not be told apart reliably. Mode changes went back to OK.
The filter knob had a subtler problem: it did nothing. The server's settable
field is filter_width, an index on the radio's per-mode ladder;
filter_hz is derived from it and read-only, so sending a
frequency was silently ignored. The ladder also differs by mode group —
voice (SSB/AM/FM) and narrow (CW/RTTY/DATA) share no indices — so the
firmware picks the table that matches the current mode. Verified at the
protocol level: filter_width=13 → filter_hz=2400,
17 → 2700, 20 → 3000.
Two networks were not enough
A terminal that lives in a bag needs more than one network. It now holds three and picks between them at boot by scanning — preferring the one that last obtained an IP, because signal strength is a poor proxy for quality: at one point it chose the louder AP (−25 dBm over −27) and landed on the network that was delivering 10% loss.
Which leads to the useful part: esp_wifi never reports a
disconnect while a hotspot delivers that kind of loss. So the audio
counters vote too. Two consecutive minutes over 2% frame drops or 50
underruns per second trigger a rescan and a switch to another visible
candidate — measured on a train, moving from a congested hotspot to a
phone gave drops +200/min → 0 and frames written 1.9–26 →
44–47 per second.
What is left is physics
On a moving cellular link the same test shows 6.5–12% packet loss with RTT peaks of 6–10 seconds. No ring buffer covers a ten-second hole: that is 320 KB of audio against 400 KB of SRAM. So the goal stopped being continuity and became graceful degradation — a stall of more than a second discards the queued audio rather than replaying it stale, and once the ring passes 75% the oldest frames are dropped instead of the newest, so a recovery burst leaves fresh audio behind. The failure is now quiet instead of violent.
Design record
The design record is not a wiki: it is 13 chapters in this site, backed by a rule registry that runs in CI. Chapter 00 states how every claim in it must be written (measurement point, date, scenario), chapter 05 holds the numbers, chapter 08 the decisions with their rejected alternatives, chapter 14 the incident ledger including what was not fixed. For the bench there is a one-page field card.
Firmware image
Ready to flash: mrrc-terminal-full-v1.3.0-9-g503e4fc-noconfig.bin
(1 717 968 B, SHA-256 42ae8e74bdb3d393…). Write it at offset 0x0 —
it is the merged bootloader + partition table + application for the ESP32-C3
board. It contains no credentials: on first boot the terminal
raises its own access point so a phone can hand it the network and server
(the same SoftAP flow described above). Source for this build is
v1.3.0 plus the 24 November audio and UI fixes; the exact
revision is in the image (mrrc-terminal
v1.3.0-9-g503e4fc).
The source
Everything is in
cheenle/mrrc-passport:
the firmware, the measurement notes behind each fix
(docs/transport-tuning.md, docs/optimization-notes.md)
and the provisioning page. Releases are source-only — a CI image cannot
carry this terminal's credentials, so the build is yours to make.
中文版:一块 ESP32-C3 手持终端如何在高铁路线上保持通话
Flashing one from a box’s web page, firmware and network config in one click: Plug it in.