KoaOS Architecture: WASM on Microcontrollers with Web Serial Flashing
October 2026 - min read
Try it in your browser (Chrome/Edge, USB cable, Heltec WiFi LoRa 32 V4)
What It Is
KoaOS is a tiny Unix-style operating system for the Heltec WiFi LoRa 32 V4 (ESP32-S3, 16 MB flash, 8 MB PSRAM, SX1262 LoRa, GPS, 0.96” OLED). It boots from a browser-based flasher using the Web Serial API, then runs a persistent shell with a WASM sandbox for user applications.
Key Features
| Feature | Details |
|---|---|
| Flash from browser | Web Serial API - no drivers, no esptool install, works on Chrome/Edge |
| Persistent shell & FS | Login, background jobs, nano-style editor, files survive reflashes |
| WASM sandbox (wasm3) | Apps are .esp packages (max 256 KB); crash won’t kill the OS |
| Hardware mediation | OS arbitrates Wi-Fi, GPS, LoRa, GPIO so apps don’t conflict |
| Built-ins | GPS manager, HTTP(S), Open-Meteo weather, LoRa APRS (aprs, aprsd), edit, neofetch, pins |
| Experimental 0.14 | VGA/desktop (vga, gui), RCA composite (rca), BLE keyboard (ble), I2C/OLED support for apps |
| SDK | C -> WASM with 48-56 function ABI (console, files, Wi-Fi, GPS, LoRa, UART, I2C, SPI, RNG, crypto, IPC) |
Architecture Overview
Boot Flow
Browser (Web Serial) -> ESP32-S3 ROM bootloader -> KoaOS bootloader -> KoaOS kernel -> init -> shell
The browser flasher sends the bootloader + kernel + rootfs in one stream. On first boot, KoaOS formats the data partition, creates the default user, and drops to a login prompt. Subsequent boots are ~2 seconds to shell.
Memory Map (16 MB Flash + 8 MB PSRAM)
| Region | Size | Purpose |
|---|---|---|
| Bootloader | 64 KB | Web Serial receive, verify, jump to kernel |
| Kernel | ~512 KB | Scheduler, VFS, drivers, hardware mediation |
| Rootfs (read-only) | ~2 MB | Built-in apps, libraries, config |
| Data partition | ~13 MB | User files, installed .esp apps, logs |
| PSRAM | 8 MB | WASM heap, framebuffers (VGA/composite), network buffers |
Hardware Mediation Layer
Instead of giving apps raw peripheral access, KoaOS exposes capability-based syscalls:
wifi_connect(ssid, pass)- OS manages connection, reconnection, power savelora_send(payload, freq, sf)- OS handles CAD, duty cycle, SX1262 register dancegps_read()- OS parses NMEA, publishes structured fixgpio_claim(pin, mode)- OS tracks ownership, prevents conflicts
Apps request capabilities at install; user grants/denies. A buggy app can’t brick the radio stack.
WASM Sandbox (wasm3)
- Interpreter (not JIT) - deterministic, small code size (~60 KB)
- Linear memory capped at 256 KB per app
- Syscall ABI: 48-56 functions, each validates capability token
- Crash -> trap -> OS kills app, restarts shell, logs fault
Building an App (C -> .esp)
// hello.c
#include <koaos.h>
int main() {
console_puts("Hello from WASM!");
wifi_connect("SSID", "pass");
http_get("https://api.example.com/data", buf, sizeof(buf));
console_puts(buf);
return 0;
}
// Compile:
clang --target=wasm32 -O2 -nostdlib -Wl,--export=main -Wl,--no-entry -o hello.wasm hello.c
// Package:
koaos-pack hello.wasm hello.esp --name "Hello" --cap wifi,http
Drag hello.esp onto the browser flasher -> installs to data partition -> appears in shell as hello command.
Experimental: VGA + Composite + BLE
Version 0.14 adds:
- VGA (640x480 @ 60 Hz) via resistor DAC on GPIO - framebuffer in PSRAM, double-buffered
- RCA composite (NTSC/PAL) - same DAC, different timing generator
- Desktop GUI (
guicommand) - window manager, mouse via BLE keyboard/trackpad - BLE HID - pairs with keyboards/mice, presents as standard HID to apps
Known issues: VGA + Wi-Fi + LoRa simultaneous = PSRAM pressure. MeshCore direct messages crash the system (WIP).
Why This Matters for Embedded Work
KoaOS demonstrates the full stack I bring to client projects:
- Bootloader + Web Serial - production-grade flashing UX, no host tools
- Custom kernel + VFS - persistent storage, background tasks, resource limits
- Hardware abstraction - mediation layer prevents peripheral conflicts
- WASM sandbox - safe third-party code execution on microcontrollers
- Radio protocols - LoRa (SX1262), APRS, mesh networking (MeshCore fork)
- Video output - VGA/composite from GPIO, framebuffer management
Links
- Live demo: flash.koakno.com
- Source: github.com/Koakno/KoaOS-for-the-Heltec-V4
- MeshCore fork: github.com/Koakno/MeshCore
KoaOS is experimental. Wi-Fi and Bluetooth share one radio - concurrent use degrades both. Flash at your own risk; recovery requires the browser flasher or esptool. Default login: root / 1234.