• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    Rust
  • License
    BSD 2-Clause "Sim...
  • Created almost 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

VGA-style video output for STM32F4 processors, in Rust

m4vga-rs

Build Status

This crate provides 800x600 60fps graphics on the STM32F407 microcontroller. The observant reader will note that the STM32F407 has no video hardware, or enough RAM to hold an 800x600 color image. So how does m4vga get high-res color video out of it?

Magic.

Recording of the tunnel demo on a small monitor

This is a rewrite of my C++ library m4vgalib, plus ports of my collection of m4vgalib demos. It is still a work in progress. (If you're curious, see my notes on the port.)

(As of quite recently, several of the demos also compile for another platform without video hardware: WebAssembly.)

Why this is interesting

Mostly because it's really hard. I've got four CPU cycles per pixel to work with, and any variation in timing will corrupt the display.

The Demos

The demo main files live in m4demos/src/bin, though the core implementations of several of the demos have migrated into the fx directory.

  • conway: full-screen Conway's Game of Life at 60fps -- that's 28.8 million cell updates per second, for a budget of 5 cycles per update (not counting video generation).

  • hires_text: 80x37 text mode. Each character has adjustable foreground and background colors. This is boring to watch but technically interesting.

  • horiz_tp: generates a display calibration pattern of vertical stripes. This also demonstrates how to write a simple m4vga-based demo in 40 lines of code.

  • poly3: a tumbling dodecahedron made of solid polygons, with basic lighting.

  • rook: high-resolution 3D wireframe model with thousands of polygons, plus scrolling text. (The model is from my chess set).

  • rotozoom: old-school texture transform effect providing rotation and scaling. This is chunky (400x300) to save RAM...which is still too much data to double-buffer. This uses a trick to prevent tearing.

  • tunnel: demoscene "tunnel zoomer" effect drawing shaded textured graphics at 60fps. (This one is also 400x300, but it's hard to notice at speed.)

  • xor_pattern: fullscreen procedural texture with smooth scrolling. Demonstrates how to add a custom assembly language raster function.

Building it

All of this is tested only on Linux, but it should work on Mac -- though you'll have to translate the commands below to your package manager of choice.

Web target

I recently made the core of m4vga portable, and I'm gradually porting demos to run on WebAssembly. While this is less exciting than running on a real, resource-starved microcontroller, it gives you a way to test out the code without having to move a bunch of wires around.

First, follow the Rust WASM setup guide here. In short, you will need Rust, wasm-pack, and npm. (Debian/Ubuntu users: the ancient npm in apt will not work.)

Now:

$ wasm-pack build -- -p m4vga-wasm-demos
$ (cd www; npm run start)

Point a browser at http://localhost:8080/ and you should be able to view the demos!

Microcontroller target

You will need an STM32F407-based board to run this on; I use the STM32F4-Discovery because it's really cheap. Hook it up to a VGA connector according to my instructions for C++.

I recommend following the setup chapters from the Rust Embedded book. In particular, you need to have Rust and you need to make Rust aware of the cross compilation target we're using here:

$ rustup target add thumbv7em-none-eabihf

You will also need a GNU ARM toolchain to compile the assembly language routines. On Arch:

$ sudo pacman -S arm-none-eabi-{gcc,newlib}

On Ubuntu, the system ships an ancient version of GCC, but since we're only assembling this is okay:

$ sudo apt-get install gcc-arm-none-eabi

Now you should be able to compile everything by entering:

$ cargo build --release

This will deposit several demo binaries in target/thumbv7em-none-eabihf/release/.

And if you start openocd (tested with version 0.10) in this directory, it will pick up the openocd.cfg file automagically, and (from a separate terminal) you can flash one of the demos by typing:

$ cargo run --release --bin horiz_tp

More Repositories

1

lilos

A wee async RTOS for Cortex-M
Rust
399
star
2

m4vgalib

VGA-style video generation for STM32F4 processors
C++
102
star
3

keybrain

Drop-in replacement controller for WASD CODE v2B keyboard
Rust
74
star
4

etl

Embedded Template Library
C++
56
star
5

rtiow-rust

Ray tracer from Peter Shirley's Ray Tracing In One Weekend / The Next Week, but in Rust.
Rust
49
star
6

ruckus

Procedural CAD for Weirdos
Racket
44
star
7

bare-metal-wasm-example

Full code from my "Tiny WebAssembly graphics demos" blog post. http://cliffle.com/blog/bare-metal-wasm/
HTML
44
star
8

catibo

Rust implementation of the CTB/CBDDLP/PHZ 3d printing file formats.
Rust
43
star
9

cfm

A 16-bit CPU and self-hosting Forth system for the Lattice ICE40 FPGA, written in Haskell.
Haskell
41
star
10

m4vgalib-demos

Assorted demos for m4vgalib
C++
40
star
11

rp2040-rustboot

RP2040 bootloader in Rust
Rust
36
star
12

swddude

A SWD programmer for ARM Cortex microcontrollers.
C++
36
star
13

minimal-embedded-rust

Example code and build environment for Rust on Cortex-M4.
Rust
24
star
14

brittle-kernel

A security-oriented microkernel for Cortex-M microcontrollers
C++
21
star
15

httpd2

A fast modern static file server, patterned after Publicfile, written in Rust.
Rust
19
star
16

lilosdbg

Prototype debugger for lilos
Rust
14
star
17

rp2040-usb-device-in-one-file

Shows how to implement USB device on RP2040 in Rust, in a single file, with no hidden parts.
Rust
11
star
18

rs80

A fairly speedy emulator for the Intel 8080, written in safe Rust
Rust
11
star
19

corncobs

Corny COBS encode/decode for Rust no_std targets
Rust
10
star
20

debugdb

DWARF program analysis crate
Rust
10
star
21

cobble-build

A simple build system for modular software.
Python
9
star
22

lilist

A Rust doubly-linked intrusive list with Miri tests
Rust
9
star
23

hubpack

Predictable serde format for embedded (or larger) systems
Rust
7
star
24

visit-diff

Efficiently discover and report differences between data structures (in Rust).
Rust
6
star
25

pushr-for-android

[obsolete] Simple, easy way to push photos to Flickr from your Android-powered phone. Based loosely on the iPhone program of the same name.
Java
5
star
26

lilos1

A tiny bare-bones OS for AVR.
C++
5
star
27

httpd1

A static HTTP server, in the style of Publicfile, written in Rust.
Rust
5
star
28

propasm

Assembler for the Parallax Propeller microcontroller
Java
5
star
29

gcc-arm-embedded

Mirror of ARM's GCC project on Launchpad
Shell
4
star
30

seff

Decent text rendering for resource-constrained devices.
Rust
3
star
31

uf2l

A tool (2l, get it?) for working with UF2 firmware images.
Rust
3
star
32

WatchMaestro

A Java library for controlling the MetaWatch
Java
3
star
33

runcible

eBook reader firmware based on Qt
C++
3
star
34

s3g-toolkit

Command-line tools for manipulating RepRap/MakerBot S3G files.
C++
3
star
35

rxbanish

Hide the X11 mouse pointer while you're typing.
Rust
3
star
36

xmonad-config

My configuration for the XMonad window manager.
Haskell
2
star
37

bsrv

Bluespec RISC-V tinkering
Bluespec
2
star
38

lasgrav

Simple raster image to laser engraver tool
Rust
1
star
39

flabbergast-hs

Variations on a theme in word game solving.
Haskell
1
star
40

docker-tensorflow

1
star
41

kallisti

The settings and software that I use to operate my MakerBot Cupcake.
1
star
42

Swamp-Thing

Laser-cut swamp cooler design.
1
star
43

wordier

Wordier names for standard library operations, for clarity.
Rust
1
star
44

stm32c0-metapac-example

Me figuring out how to use stm32-metapac on the stm32c0
Rust
1
star