A simple LED blinking example for STM32 Nucleo-F446RE using libopencm3.
- libopencm3: Download and build libopencm3
- ARM GCC toolchain: Install arm-none-eabi-gcc
- OpenOCD: For flashing and debugging
- ST-LINK: Hardware programmer (you have ST-LINK/V2.1)
# 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)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.
# Set libopencm3 path (if not already set)
export OPENCM3_DIR=/path/to/libopencm3
# Build the project
make
# Or use the convenience script
./flash.sh./flash.sh# 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"When successful, you should see:
- Programming Started
- Programming Finished
- Verified OK
- Resetting Target
After successful flashing:
- Startup: LED flashes 3 times quickly (startup confirmation)
- Main loop: LED blinks continuously at 1Hz (500ms on, 500ms off)
- LED location: Green user LED near the USB connector on Nucleo board
- Power: Ensure Nucleo board is connected via USB
- Connection: Verify ST-LINK connection with
./status.sh - Board type: Confirm you have a Nucleo-F446RE board
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
- Check environment:
./status.sh - Build and flash:
./flash.sh - Manual build:
make - Manual flash:
make flash - Clean:
make clean
The LED should start blinking immediately after flashing!
main.c: LED blink source codeMakefile: Build configuration using libopencm3stlink.cfg: OpenOCD configurationflash.sh: Complete build and flash automationstatus.sh: Development environment checker
This project uses libopencm3, which is licensed under LGPL v3.