Playing Tetris in SPARK on a SAM4S ARM Cortex-M4 MCU


Just when we thought we’d seen the ‘80s game played on nearly everything, a group of Makers have built it onto an MCU. 


For many, Tetris is simply a tile-matching video game originally designed and programmed by Alexey Pajitnov in 1984. However, for others, it inspires endless possibilities of Maker projects. Most recently, AdaCore’s Tristan Gingold and Yannick Moy have devised the highly-popular puzzle on an Atmel | SMART SAM4S ARM Cortex-M4 microcontroller.

board_tetris_zoom

“There are even versions of Tetris written in Ada. But there was no version of Tetris written in SPARK, so we’ve repaired that injustice. Also, there was no version of Tetris for the Atmel SAM4S ARM processor, another injustice we’ve repaired,” the duo writes.

The concept first stemmed from their colleague Quentin Ochem, who had been searching for a flashy demo for GNAT using SPARK on ARM, to run on the SAM4S Xplained Pro Evaluation Kit. Luckily, this kit features an OLED1 extension with a small rectangular display, which surely enough, immediately ‘SPARKed’ the idea of Tetris. Now, throw in the five buttons overall between the main card and the extension, and the team had all the necessary hardware to bring the project to life.

atmel_board

In total, the entire build took approximately five days to complete. Both Gingold and Moy advise, “Count two days for designing, coding and proving the logic of the game in SPARK, another two days for developing the BSP for the board, and a half day for putting it all together.”

For those unfamiliar with SPARK, it is a subset of Ada that can be analyzed very precisely for checking global data usage, data initialization, program integrity and functional correctness. Mostly, it excludes pointers and tasking, which proved not to be a problem for Tetris.

board_tetris-1

While we’ve seen the retro game played on everything from t-shirts to bracelets, we’ve never experienced the game literally on an MCU. As the team notes, all of the necessary sources can be downloaded in the tetris.tgz archive, while those interested in designing one of their own can find a detailed breakdown of the entire build here.

1 thought on “Playing Tetris in SPARK on a SAM4S ARM Cortex-M4 MCU

  1. Pingback: Tetris and Makers go together like peanut butter and jelly | Atmel | Bits & Pieces

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s