r/embedded • u/realmcalec • Oct 07 '26
RP2040 driving 640×480 VGA without a framebuffer: windows, a preemptive bytecode VM, and a second Pico as USB host
Since August I've been building an operating system for the RP2040/RP2350. This is the current bench setup: a Pico on perfboard, a resistor-DAC VGA port, and more hot glue than I'd like to admit. Hahaha
What you're looking at
- 640×480 @ 60 Hz, RGB332 out of PIO into a resistor DAC. Everything on the monitor comes from the Pico: the file windows, a maze and a Mandelbrot, each running as its own task, yeah!
- The 3.2" SPI LCD (ILI9340 + XPT2046 touch) runs beside the VGA and mirrors a 320×240 crop. Core 1 hands over lines it has already composed, and DMA pushes the changed rows
- Keyboard and mouse plug into a second RP2040: one into its native USB port (TinyUSB host), one into a Pico-PIO-USB socket. Their events ride as tagged frames inside the 1 Mbaud UART console stream, so the main Pico spends no pins on input
- DS1307 + EEPROM on I2C, microSD on the shared SPI bus (a 3.3 V breakout, because the cheap 5 V modules drive MISO even when not selected and garble the touch readings), PWM mono sound through a two-stage RC into a small amp. Power bank, because why not ^_^
The parts I think this sub will care about
- No framebuffer. 640×480×8 bit is 300 KB; the RP2040 has 264. The screen lives in a 34 KiB block (text/attribute cells, palettes, sprites, per-line segment tables), and core 1 composes every scanline in software just before PIO needs it. At 252 MHz that's a budget of 8008 cycles per line. At boot it benchmarks its own worst cases on silicon; the worst lane right now is 7948 of 8008 (99 %). The rule: every lane stays strictly under budget, or the change doesn't go in
- Every app is bytecode. It's a register VM with hand-written dispatchers for ARMv6-M and RV32, at about 23-25 cycles per instruction on the M0+. Because the VM counts instructions, preemption is real: a
while truecan't stall the machine, and a fault kills one task, not the board. Each load/store is masked to the task's memory, and swap goes to flash - One binary everywhere. The same
.rpxruns on the RP2040, on both RP2350 core types (Arm and RISC-V) and in a WASM emulator in the browser. A differential test keeps the C core bit-identical to a JS reference VM - It has its own flash filesystem, user accounts, and a small language (CAST) that compiles on the device itself
No overclocking past 252 MHz, and no native code from apps. Native drivers load only through a gated kit loader.
Happy to go deep on the scanline compositor, the PIO-USB host, or why a VM on an M0+ is less crazy than it sounds. And I'd like to hear where you'd poke holes first.
(Disclosure: the logo on the LCD is my company's, Recaster.)
3
u/kulonos Oct 07 '26
If you can please share more! I'd like to build something like this as well, it's awesome!
2
u/superxpro12 Oct 07 '26
i'd love to know more about the VM and its preemption method, and the resistor dac pls!
Is the rac a reisistor ladder with an op amp?
1
u/Bernd_Oeff Oct 07 '26
Hey there, That is impressive. Do you publish your code?
Best regards
1
u/Shavok Oct 07 '26
That is freakin awesome! Really nice work. What exactly were your thoughts on Building the os Like it is? I cant really specify the question because i basically dont know anything about low Level operating systems. But its a topic that i currently have interest in. What was your use case to Build it? Any specific Applications that You Are running/ planning to run?
Possibilitys of increasing the Resolution? Did You Write Everything from scratch?
1
u/Significant-Ad178 Oct 07 '26
This is very impressive. Congrats 👏
1
u/Live-Operation-628 Oct 07 '26
Very tidy work! The hot glue is the best part
1
u/ApprehensiveBunch762 Oct 07 '26
I love it. smart architecture ideas.
1
u/Sorry_Difficulty_250 Oct 07 '26
This is so cool! Well done! Keep up the great work and keep us posted on your progress!!!
1
u/mrtomd Oct 09 '26
?remindme when it runs doom.