Build Guide for Mini Arcade Machines

6:35 pm Projects

Edit: Updated instructions to discuss the game ROM

Have an STM32F407 Discovery board? Have a CRT scope with XY inputs? Try out Asteroids and Battlezone for yourself.

These directions assume you are running Linux.

First, get (git?) the source code: Asteroids Battlezone

Also go out and find the game ROM on the internet and put it in ../roms/. The file should be called “Battlezone” or “Asteroids”. The project makefile looks for it at this location.

Download the STM32F4-Discovery firmware libraries.

You’ll also need a toolchain. I’ve been using the prebuilt GCC 4.8 from here. Once you’ve installed it make sure it works by typing

arm-none-eabi-gcc -v

Then you will need to edit the makefile in the asteroids/bzone directory and set up the library path. Look for the line

STM32F4_PERIPH_PATH=/rnasbkup/STM32F4/STM32F4-Discovery_FW_V1.1.0

and set it to point to the ST firmware libraries you downloaded earlier. Try to build it by typing

make

If all goes well, it will generate the main.axf output file.

Now for programming the Discovery board itself. Get OpenOCD version 0.8 or above (many Linux distributions still have older versions in their repositories, so be careful). Make sure your udev rules include an entry for the ST-Link debugger:

SUBSYSTEM=="usb",ATTRS{idVendor}=="0483",ATTRS{idProduct}=="3748",GROUP="plugdev",MODE="0660"

Put this in a file “99-stm” (or whatever) and put it in /etc/udev/rules.d. Then run

sudo udevadm control --reload-rules

Plug in the Discovery board and open two console windows. In the first, run

openocd -f board/stm32f4discovery.cfg

And make sure it connects to the board.
In the other window, go to the directory which has the main.axf file you built earlier, and run

arm-none-eabi-gdb main.axf

In the GDB console, you’ll need to attach to the openocd session and flash the firmware, as follows

target extended-remote localhost:3333
mon reset halt
load
mon reset init
c

…I just typed that out from memory. If it worked, you’ll see a blinking LED on the Discovery board, and analog vectors should be coming out of PA4 and PA5. Whew!

19 Responses
  1. Dave :

    Date: June 16, 2015 @ 12:53 pm

    This is great! I’m hoping to connect it to some cheap ebay laser galvanometers for a projection screen size asteroids and battlezone fun. Quick question- I’ve got a successful build (main.axf) which actually required adding an stm32f4xx_conf.h for the discovery libraries in launchpad GCC 4.9. I cut the LRCK line as indicated, but have made no other hardware modifications. I’m hooked up to an XY scope, but I don’t see any action from PA4 and PA5 (I think PA4 is stuck at 2.5V and PA5 is at 0). Any clue what I’ve missed? Thanks again!

  2. eric :

    Date: June 20, 2015 @ 6:38 pm

    Dave–Can you step around in the debugger? You can set a breakpoint in dac_out() or draw_line() to see if they are getting called frequently.

  3. Anders M :

    Date: June 18, 2015 @ 3:16 pm

    Amazing project!
    I have some nice RFT B10S3 CRTs here that I want to try this with. I’ve managed to find different revisions of the ROM files for Asteroids, do you know if this project is compatible with all of them? All of the ROM packages I found consist of separate files that are images of the individual EEPROMs, with six digit numbers as the file name. Do these files need to be concantenated in numerical order?

    Anders M

  4. eric :

    Date: June 22, 2015 @ 5:39 pm

    Anders–the gencell.rb script looks for the individual EPROM files and maps them correctly into the memory space, so it’s basically automatic. You might have to check the script file to make sure your images have the correct file names.

  5. hedley :

    Date: June 21, 2015 @ 12:08 pm

    I just pulled the bzone from git juist now, did a build and I do see the game on the scope. (a totally foreign machine for the build too). arm-none-eabi-gcc 4.8.3 was used. Eric’s observation is good. You should be able to ^C and see where it is, step, bkpt @dac_out etc.

  6. michael :

    Date: June 24, 2015 @ 12:42 pm

    Really nice! Congratulations Eric!
    I managed to compile the asteroid code but I had to compile the drivers lib separately.
    My sope shows the vectors very nicely but there are some flaws:
    1. the letters in “PUSH START” are rendered without break. The P for example read as a R etc.
    2. there is very bright point in the upper left at the zero of the score.

    are these hardware (scope) related?

  7. eric :

    Date: June 27, 2015 @ 5:03 pm

    Michael–it sounds like your scope is not blanking the video between lines. The bright point is the 6502 emulator running code, since it just lets the beam sit for a while (blanked). If your scope has a Z axis input try tying it to GPIOC[0]. You might need a transistor inverter depending on the scope’s Z axis polarity.

  8. Dave :

    Date: June 25, 2015 @ 11:19 pm

    Thank you guys. Yep, planted a breakpoint in dac_out and found that it never got caught. When I break and step, PC never increments, it’s stuck on stm32f4_discovery_audio_codec line 973, and the timeout never decrements. This happens with both projects. I had to build the std peripheral library (and enable it in atm32f4xx.h) and assemble the startup code before I could successfully make.

  9. Dave :

    Date: July 1, 2015 @ 1:40 pm

    Continued troubleshooting, wrote my own makefile that grabs and compiles the necessary library files with identical compiler switches and started from a clean install. It compiles and links fine (mostly implicit declaration warnings during compile). When debugging, everything starts off smoothly, but the codec initialization (from init_board() locks up- specifically at stm32f4_discovery_audio_codec.c line 1308, which based on the code is what it’s supposed to do on codec timeout. Can anybody offer a suggestion? Do I have faulty hardware?(my discovery board IS a few years old but simple blink tests work fine)

    Thanks for any suggestions- I’m learning a ton here. And if anybody wants that Makefile I’m happy to put it up somewhere.

  10. eric :

    Date: July 1, 2015 @ 9:49 pm

    Dave–Check the I2C bus going to the codec. It sounds like the STM32 is having trouble communicating with it.

  11. Dave :

    Date: July 6, 2015 @ 7:29 pm

    eric- Thanks! Turns out that was it, picked up a new board. Works great. Time to go order a cheap galvanometer. Can’t believe there’s a Z axis too.

  12. Ian Barnes :

    Date: August 24, 2015 @ 12:31 pm

    Hi there, bought a discovery board to use with an old oscilloscope. I am compiling under windows using GCC ARM Embedded and gunwin32 make tools. Using the makefile, the project compiles but when it comes to compile the StdPeriph Driver it falls over. Unfortunately I have not been able to fix it myself, and could really use some pointers on what to try. The compilation output can be viewed here: http://pastebin.com/raw.php?i=U3tAbPCk
    Any ideas?
    Cheers, Ian.

  13. Ian Barnes :

    Date: August 26, 2015 @ 3:42 pm

    I am guessing it’s because there is no makefile in the STM32F4-Discovery firmware libraries download. Is it possible you can supply the makefile you used?
    Cheers,
    Ian.

  14. eric :

    Date: August 26, 2015 @ 9:54 pm

    Ian–Working on it, we’ll put it in the repository soon. Stay tuned! (Edit: Makefiles are updated in both repositories)

  15. Ian Barnes :

    Date: November 14, 2015 @ 8:25 pm

    I see now there are two changed files in the repository, makefile and makefile2. Not sure if I am supposed to move these to the STM32F4-Discovery firmware libraries? I have tried to compile but it doesn’t seem to have changed anything, I still get the same error? Would really like to get this going, so please persevere with me 🙂

  16. eric :

    Date: November 21, 2015 @ 3:49 pm

    makefile2 is launched by makefile, so build that part as usual. The firmware libraries can be found here in this zip archive, which includes a makefile for generating the peripheral library.

  17. Fred :

    Date: January 24, 2016 @ 2:10 pm

    Is there anyone that can help with this. I don’t have the knowledge to get this to compile.. I’d gladly pay someone for a compiled file I could just upload to the board.. Fredkono(at)gmail.com

  18. Rich :

    Date: February 15, 2017 @ 11:38 pm

    Just trying to see if I can compile this under windows… (I am a masochist…)

    I will keep plugging away, but in the meantime I hit an unknown type error for RCC_ClocksTypeDef.

    I guess I need to tweak the mile file for find some .h files somewhere….?

  19. Rich :

    Date: February 16, 2017 @ 12:42 am

    Got a bit further using the STM32 libraries from the linked github mentioned in one of the posts just above instead of the libraries from ST’s website, as linked to at the start of the page.

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.