Project 02- Snake game for STM32F429-Discovery board

After first FFT project, I’ve decided to make a simple snake game. Basically I’ve made it in Labview first for my partial exam at the university. It looked great so why not port it also to STM32F429-Discovery board which has everything already prepared for us.

You just need USB OTG cable and external keyboard to drive snake and you are ready to play.

Snake game


  • Works on STM32F429-Discovery board
  • Supports external keyboard using USB HID Host stack on STM32
  • Supports selecting different speeds
    • More speed, more points
  • Standard snake game mode
    • Your goal is to make snake larger as possible
  • Supports 2 game modes
    • Mode 0: If you hit wall, game is stopped
    • Mode 1: If you hit wall, snake will come out at the other side of game area
  • Supports pause mode

Keyboard buttons and actions

Keyboard style for this project is QWERTY. If you put keyboard correct to USB, then GREEN led will be on, to detect this.

To operate with snake game, you will need buttons below:

  • All characters are LOWERCASE
  • w‘, ‘s‘, ‘a‘, ‘d‘: move snake to direction you want
  • r‘: resets game and starts again
  • m‘: toggles game mode between Mode 0 and Mode 1
  • u‘,’i‘: changes snake speed
  • p‘: toggles pause mode

When gameover occurs to you for some reason, you can press ‘r‘ (reset) key to reset it.

Source code

Entire project and source codes are in the bottom download. If you have any problems with compile (you shouldn’t have), there is also Snake.hex file included in project.

Project 02- STM32F429-Discovery Snake game

Tell me your best result in comments 😉


Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Jörg Boge

    What’s Project 1 ?

  • Adzak

    Simple snake game for STM32F4/29-Discovery board – The current version.
    .TargetsSTM32F429_Discoveryproject.axf: error: L6047U: The size of this image (33420 bytes) exceeds the maximum allowed for this version of the linker
    µVision V5.12.0.0
    Copyright (C) 2014 ARM Ltd and ARM Germany GmbH. All rights reserved.

    License Information:


    Tool Version Numbers:
    Toolchain: MDK-Lite Version:
    Toolchain Path: D:Program Files (x86)Keil_v5ARMARMCCBin
    C Compiler: Armcc.exe V5.05 (build 41)
    Assembler: Armasm.exe V5.05 (build 41)
    Linker/Locator: ArmLink.exe V5.05 (build 41)
    Library Manager: ArmAr.exe V5.05 (build 41)
    Hex Converter: FromElf.exe V5.05 (build 41)
    CPU DLL: SARMCM3.DLL V5.1.0.0
    Dialog DLL: DCM.DLL V1.13.0.0
    Target DLL: SeggerJL2CM3.dll
    Dialog DLL: TCM.DLL V1.14.2.0

    Any help?

    • You have .hex file included.
      Use ST-Link Utility to upload game to board.

  • Adzak

    Thanks a lot for the quick response!
    Of course, I can load the finished program.
    But playing in a snake, it is not my goal.
    I play in a “compilation” 🙂

  • Karda Yürür

    I’m converting this project to pacman game by using my old pacman game code in C#, it almost worked perfect but I can’t erase the lcd at the beginning of game loop. How can erase lcd drawing a big filled rectangle with black or white color did not work ? I’m using STM32F429-Discovery board.

    • Use TM_ILI9341_DrawFilledRectangle().

      • Karda Yürür

        OK, I found out that I have some wrong parameters in TM_ILI9341_DrawFilledRectangle() call in my adapter function, I fixed it.

        • Nice to hear.

          Send project .hex file to see your great work :))

          • Karda Yürür

            Never mind I will share everything that I built on your library after game will work as expected. Now there some weird behavior on player side. Enemy’s logic are more complex but It worked without touching single line. Of course I ported C# to C :))