usnake icon indicating copy to clipboard operation
usnake copied to clipboard

A rust implementation of the game snake for the stm32f3 discovery board.

usnake :snake:

Build Status

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).

Getting started

Hardware setup

The hardware required for gameplay includes:

Pin configuration is described in main.rs as part of the init() routine.

Playing the game

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.

License

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.