Projects

DIY hand-held games console: Hello World

Last updated: July 2, 2022, 11:53 p.m.

I've got a collection of parts on hand left over from various projects or bought for projects that never started, so I'm going to try and build a system as a prototype. The core of the system is the STM32F429 which I have on a "Discovery board". The one I'm using is the original production run STM32F429I-DISCO board which has long since been replaced by the STM32F429I-DISC1 board. As far as I can see the only real difference between these is a newer ST-Link which supports virtual serial port as well as SWD/JTAG programming. While more convenient all I need for the old board is an extra serial to USB adapter which I have anyway.

Getting a project setup

I'm using the STM32CubeMX tool to generate my project. While it has some issues with more advanced usage it's the fastest and easiest way to get started. Since the board I'm using is an ST one I just typed in the part number (actually the new STM32F429I-DISC1 because the DISCO was discontinued before this tool was properly mature so it's not supported) and allowed it to initialize all peripherals in their default configurations.

Getting the basic configuration started for a CubeMX project on an ST dev board needs very little work.

Hello CubeMX: Getting the basic configuration started for a CubeMX project on an ST dev board needs very little work.

I didn't change any of the peripheral/firmware settings. I did have to name the project, so far I decided NoodleGame since it's going to look like a pile of noodles as I hook up all the prototype parts. I had to set the toolchain but selecting Makefile should make it easy to use with VSCode which is my preferred editor at the moment.

Other than setting a project name and location I had to select the Toolchain as Makefile.

Project settings: Other than setting a project name and location I had to select the Toolchain as Makefile.

Then it's just a case of clicking "Generate Code" on the toolbar, and waiting while it downloads hundreds of MB of firmware files (why so much stuff?!). Once the process has finished I closed the dialogue that pops up and opened the folder in VSCode.

STM32 project opened in VSCode ready to start editing.

VSCode STM32 Project: STM32 project opened in VSCode ready to start editing.

I'm working on Ubuntu and just installed GCC for ARM microcontrollers from APT (gcc-arm-none-eabi). I've got the STM32-for-VSCode extension installed in VSCode so once I've opened the project I just have to click the extension icon and click build, it generates all the necessary project configuration to build the Makefile project I generated with CubeMX. Again, flashing is just a case of clicking "Flash STM32" in the extension (assuming you have OpenOCD, the extension should help you get this setup but I already had it, "sudo apt install openocd" so nothing more to do for me). This tool is very convenient, but most of what it's doing is writing the *.json files which live in the .vscode folder. Once you've got those setup your project will work in VSCode without the extension. You can always run "make" manually without installing VSCode which means you're not tied to the IDE (always a good thing in embedded development where projects can be maintained for longer than an IDE exists...)

This extension is very convenient if you don't want to write your own launch.json

STM32-for-VSCode: This extension is very convenient if you don't want to write your own launch.json

Now, the only issue with flashing this onto the device is that it doesn't do anything. We need to add some application code.

In the generated main.c file I found the function StartDefaultTask and changed the content of the endless for loop to send a string out of the UART and then wait 1 second (1000 ticks):

for(;;)
{
    HAL_UART_Transmit(&huart1, "Hello World\r\n", 13, 0xffff);
    osDelay(1000);
}

Now flash that onto the board, connect with PuTTY to the USB serial adapter I wired up and:

Hello World coming from the new project via the serial port

Hello World in PuTTY: Hello World coming from the new project via the serial port

Obviously there's no useful functionality here yet and we've got a lot of peripherals to reconfigure and add to achieve the goal of having something more game console like but we've got a working development environment and toolchain.

You can browse the code at this point by checking out this commit on GitHub.

Section:
Projects
Tags:
ARM,
VSCode,
Toolchain

Comments

Posting comments is not currently possible. If you want to discuss this article you can reach me on twitter or via email.


Contact

Email: nathan@nathandumont.com

Mastodon: @hairymnstr@mastodon.social