STM32 LED Blink Project - Nucleo-F446RE

A simple LED blinking example for STM32 Nucleo-F446RE using libopencm3.

Prerequisites

  1. libopencm3: Download and build libopencm3
  2. ARM GCC toolchain: Install arm-none-eabi-gcc
  3. OpenOCD: For flashing and debugging
  4. ST-LINK: Hardware programmer (you have ST-LINK/V2.1)

Installation on Arch Linux

# Install ARM GCC toolchain
sudo pacman -S arm-none-eabi-gcc arm-none-eabi-newlib arm-none-eabi-gdb

# Install OpenOCD
sudo pacman -S openocd

# Clone and build libopencm3
git clone https://github.com/libopencm3/libopencm3.git
cd libopencm3
make
export OPENCM3_DIR=$(pwd)

Hardware Configuration

The example is configured for:

  • Board: Nucleo-F446RE
  • LED Pin: PA5 (green user LED)
  • Target: STM32F446RET6

Important: This code is specifically configured for Nucleo-F446RE. For other boards, modify the LED_PORT and LED_PIN definitions in main.c.

Building

# Set libopencm3 path (if not already set)
export OPENCM3_DIR=/path/to/libopencm3

# Build the project
make

# Or use the convenience script
./flash.sh

Flashing

Using the Flash Script (Recommended)

./flash.sh

Manual Flashing

# Build first
make

# Flash using make target
make flash

# Or manual OpenOCD command
openocd -f stlink.cfg -c "program led_blink.elf verify reset exit"

Expected Output

When successful, you should see:

  • Programming Started
  • Programming Finished
  • Verified OK
  • Resetting Target

Testing

After successful flashing:

  1. Startup: LED flashes 3 times quickly (startup confirmation)
  2. Main loop: LED blinks continuously at 1Hz (500ms on, 500ms off)
  3. LED location: Green user LED near the USB connector on Nucleo board

Troubleshooting

If LED doesn't blink:

  1. Power: Ensure Nucleo board is connected via USB
  2. Connection: Verify ST-LINK connection with ./status.sh
  3. Board type: Confirm you have a Nucleo-F446RE board

Project Structure

stm32_led_blink/
├── main.c              # Main application code (LED blink)
├── Makefile            # Build configuration using libopencm3
├── stlink.cfg          # OpenOCD configuration for ST-LINK
├── flash.sh            # Build and flash script
├── status.sh           # Environment status checker
└── README.md           # This file

Quick Start

  1. Check environment: ./status.sh
  2. Build and flash: ./flash.sh
  3. Manual build: make
  4. Manual flash: make flash
  5. Clean: make clean

The LED should start blinking immediately after flashing!

Files

  • main.c: LED blink source code
  • Makefile: Build configuration using libopencm3
  • stlink.cfg: OpenOCD configuration
  • flash.sh: Complete build and flash automation
  • status.sh: Development environment checker

License

This project uses libopencm3, which is licensed under LGPL v3.