Minimal STM32 project for using GPIO pins - as an example, this uses a button connected to pin B1 to control an LED connected to pin B3. This is a minimal project to demonstrate supporting two different chip architectures - the STM32F031 (Cortex-M0) and STM32L031 (Cortex-M0+).
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
boot_code Remove the system clock configuration code from these early tutorials. May 21, 2018
LICENSE Button-controlled LED example project, which can build and run on eit… Apr 25, 2018


This is a minimal project to demonstrate how to support multiple microcontroller cores in a single project, with minimal code changes. The project supports both Cortex-M0 'STM32F031K6' and Cortex-M0+ 'STM32L031K6' chips.

The example project initializes pin B1 as input with a built-in pull-up resistor; it listens for button presses on a button connected to ground. pin B3 is set to push-pull output, and it is connected to a built-in LED on ST's "Nucleo" board.

Uploading and Debugging

A Makefile is provided, and I've tested the program with 'Nucleo-32' boards for both chips. To upload the resulting program, you can use your choice of uploader/debugger. I use GDB and Texane's "stlink" project:

It's a fairly simple process to upload g a program:

  1. Build the project with make

  2. Plug your board in - for ST's Nucleo boards, you can just use an ordinary micro-USB cable.

  3. Run st-flash write main.bin 0x08000000 to write the compiled binary file to the start of the chip's Flash memory.