A rust implementation of the game snake for the stm32f3 discovery board.
Using the stm32f3, an 8x8 LED display and an analog joystick, I implemented snake using Rust's real-time embedded framework for Cortex-M microcontrollers - Real Time For the Masses (RTFM). This project was primarily a learning exercise in understanding how Rust can be used to solve some of the challenges inherent in embedded application development. It includes examples of how to:
- Initialise peripherals and interact with them (i.e. digital pins for the display, and ADCs for the joystick).
- Use RTFM to orchestrate software tasks that share mutable resources (i.e. peripherals).
- Write
macros!
to simplify repeated code patterns, in this case:- Logging messages through, and ensuring exclusive access to, Cortex's standard ITM peripheral.
- Scheduling tasks based on the
sysclk
frequency and a desired delay (in seconds).
The hardware required for gameplay includes:
- STM32F3DISCOVERY
- MAX7219 LED display
- Analog Joystick
Pin configuration is described in main.rs
as part of the init()
routine.
To build and flash this game, I would suggest following the stm32f3-discovery tutorial here to prepare your development environment. Assuming one has the necessary tools installed, the contained Makefile
can be used to build and flash the board.
$ make flash
Once the binary has been flashed the LED display will start to cycle through a binary pattern - this means the system is now ready for play. To start the game, click the joystick.
All source code (including code snippets) is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.