This is a simple blinky project for the STM32 Nucleo-F446RE board using CMake as the build system.
- ARM GCC Toolchain (arm-none-eabi-gcc)
- CMake (version 3.15 or higher)
- OpenOCD or STM32CubeProgrammer for flashing
- Make or Ninja build system
- Create a build directory and navigate to it:
mkdir build && cd build
- Generate the build files:
cmake -DCMAKE_BUILD_TYPE=Debug ..
- Build the project:
make
-
Connect your Nucleo board via USB
-
Flash the program:
openocd -f board/st_nucleo_f4.cfg -c "program stm32-blinky.elf verify reset exit"
- For debugging, start OpenOCD in a separate terminal:
openocd -f board/st_nucleo_f4.cfg
- In another terminal, connect GDB:
arm-none-eabi-gdb build/stm32-blinky.elf
(gdb) target extended-remote localhost:3333
(gdb) monitor reset halt
(gdb) load
(gdb) continue
-
Connect your Nucleo board via USB
-
Launch STM32CubeProgrammer
-
Click 'Connect' to establish connection with the board
-
Click 'Open file' and select the generated .elf file
-
Click 'Download' to flash the program
The onboard LED (LD2) will blink with a 1-second period (500ms on, 500ms off).
-
If OpenOCD fails to connect, check if:
- The board is properly connected via USB
- You have the necessary permissions to access the USB device
- The correct OpenOCD configuration file is being used
-
If the LED doesn't blink:
- Check if the board is powered
- Verify that the program was flashed successfully
- Try resetting the board
.
├── CMakeLists.txt # Main CMake configuration file
├── cmake/
│ └── arm-none-eabi-toolchain.cmake # Toolchain configuration
├── Core/
│ ├── Inc/ # Header files
│ ├── Src/ # Source files
│ └── Startup/ # Startup code
└── Drivers/ # STM32 HAL drivers