stm-game was a personal project meant for studying some low-power design concepts, in the form of a small, hand-held gaming device. This project also involved my first attempt at designing, ordering, and soldering together a PCB prototype.

The device is built around the STM32L011F4 in its TSSOP20 package. This microcontroller can run at up to 32MHz, and comes with just 16kB of flash and 2kB of RAM; however, this chip is still quite capable of running some simple games.

The display is an EA DOGS102N-6 LCD, which provides a 102x64 monochrome screen at sub-milliamp power consumption. A four-way digital joystick, three push-buttons, and the power switch are also seen here.

On the back of the device is the microcontroller, a CR2032 battery and 3.0V regulator, and some capacitors. At the bottom right is a pin header exposing VCC, ground, reset, and the two SWD programmer pins. Conveniently, the SWD pins can also be used by the low-power UART peripherial, opening the door to games involving other devices.

For firmware, the real-time operating system ChibiOS/NIL was chosen. ChibiOS provides a high-quality HAL, and the NIL RTOS allows for threading or other useful facilities. The current firmware is single-threaded, so the RTOS portion may be dropped to free additional flash space.

The core firmware was designed to be minimal, allowing as much space for game code as possible. The core abstracts display rendering and the button inputs, manages low-power sleeping, and provides a "pause" functionality to both pause the current game and provide a voltage reading of the battery. Below, see the device paused while playing a poor-quality Flappy Bird clone (the bottom-right number is the battery voltage):

Multiple steps are taken to realize the lowest possible power consumption. To begin, the microcontroller sleeps on a wait-for-interrupt loop between game frames. This sleep is specifically executed in a low-power run mode. Games are executed at a 10Hz refresh rate to get in additional sleeping time. The final enhancment to this arrangement involves running the microcontroller at its lowest Vcore (1.2V), raising clock speed to 4MHz while game processing, and dropping to just 64kHz while idling.

Through these features, the device as a whole is able to achieve an active power consumption rate of just ~340uA. The "pause" feature puts the display to sleep as well, lowering consumption further to ~272uA.

The Flappy Bird clone is the most complete game at the moment. The puzzle game 2048 is currently a work-in-progress. The current firmware leaves at least 8kB of flash available for a game, though available RAM is about a couple hundred bytes. Hardware improvements could allow for more complex games, but at the moment it is a game in its own sense to see what can fit into the memory available.

Find stm-game's firmware on bitgloo code.