FRANK OS Architecture

Overview

FreeRTOS-based desktop OS for RP2350. Single RP2350B chip with 520 KB SRAM, 16 MB flash, optional QSPI PSRAM, DVI output via HSTX.

Core Architecture

Dual-core. Core 0 runs FreeRTOS (UI, input, apps). Core 1 runs bare-metal DispHSTX DVI scanline renderer.

Task Priorities

OptionDescription
USB (Highest)TinyUSB CDC serial console
Input (3)PS/2 keyboard/mouse polling & event routing
Compositor (2)Window manager event dispatch & screen compositing
Heartbeat (1)LED blink
Shell (per-terminal)Command-line interpreter
App (per-app)ELF binary execution context

Memory Map

Flash (16 MB)

OS sits in top 1 MB (0x10F00000). Lower ~15 MB reserved for user firmware flashable from Start menu. sys_table at 0x10FFF000. Boot redirect: after flashing user firmware, OS reboots via watchdog; holding Space on PS/2 escapes back to OS.

SRAM (520 KB)

  • FreeRTOS heap (Heap4)
  • Task stacks
  • Framebuffer (150 KB β€” 640Γ—480 @ 4bpp, 2 pixels/byte, stride 320 bytes)
  • Window manager state
  • Terminal buffers
  • Static BSS

PSRAM

Optional, up to 16 MB. Used for ELF application memory. QSPI on CS1, auto-detected at boot.

Display Pipeline

App code β†’ display primitives (set_pixel, hline_fast, blit_glyph) β†’ Framebuffer (4bpp packed) β†’ DispHSTX (Core 1) β†’ HSTX peripheral β†’ DVI TMDS β†’ Monitor

Video Modes

OptionDescription
Desktop640Γ—480 @ 60 Hz, 4-bit (16 colors), 2 px/byte
Fullscreen320Γ—240 @ 60 Hz, 8-bit (256 colors), 1 px/byte (emulator apps)

Palette is RGB565 from RGB888. Mode switch via display_request_mode() during vblank, no DVI restart. In fullscreen 8bpp, compositor and input tasks are bypassed.

Window Manager

Up to 16 simultaneous windows, Z-order stacking, each has outer frame rect, flags, title, event/paint callbacks. Client area = frame minus decorations.

Compositing

  • Dispatches queued input events to focused window
  • Repaints dirty windows back-to-front
  • Draws decorations (title bar, borders, buttons)
  • Renders taskbar
  • Stamps mouse cursor overlay

Event Flow

PS/2 interrupt β†’ Input task β†’ Event queue β†’ Compositor task β†’ window event_handler() β†’ App logic β†’ wm_invalidate() β†’ repaint

Application Model

ELF Loading

Standalone ARM ELF binaries from SD card. Compiled against apps/api/frankos-app.h. Call through sys_table at 0x10FFF000.

sys_table

Fixed-address array of 500+ function pointers. Apps don't depend on OS binary layout. Key ranges: 0–100 MOS2 core (fs, memory, tasks), 404–442 GUI (windows, drawing, menus), 443–450 MP3/audio, 451–454 clipboard, 455–490 controls (scrollbar, textarea, file dialogs, find/replace, MOD playback), 491–535 PSRAM, file assoc, video mode, direct FB, volume.

App Lifecycle

  • User launches app
  • OS creates FreeRTOS task + loads ELF into PSRAM
  • main() creates window via wm_create_window()
  • event_handler callback handles events
  • paint_handler paints client area
  • On close: wm_destroy_window() + task exits + memory freed

App Suspension

Only foreground app runs on shared 8 KB stack. On focus switch, stack saved to PSRAM and next app's restored. Background-flagged apps (APPFLAG_BACKGROUND) keep running.

Audio

  • I2S output via PIO on GPIO 20–21
  • PWM beeper on GPIO 22
  • Mixer: 4 concurrent channels at 44100 Hz with linear interpolation
  • Codecs: Helix MP3 + HxCMod tracker + OPL FM synth (MIDI)
  • Volume: 5 levels persisted in settings

Hard Fault Recovery

Crash dumps saved to uninitialized SRAM survive warm resets for post-mortem debugging.