
STM32 BlackPill LED Tutorial: Step-by-Step Guide to GPIO Programming
STM32 BlackPill LED Tutorial: Step-by-Step Guide to GPIO Programming
The STM32F401 BlackPill is a powerful, compact development board ideal for embedded systems learning. This tutorial walks you through setting up STM32CubeIDE, writing your first GPIO program, and flashing it onto the board.
🖼️ Board Overview
Top view of the Black Pill V1.2 board
🧭 Pinout Diagram
Pinout diagram for the STM32F401CCU6 BlackPill board
🛠 Setup Steps
1. Install STM32CubeIDE: Download STM32CubeIDE from STMicroelectronics and install it. Ensure ST-Link drivers are installed if needed.
2. Connect the Board: Use a Micro USB cable or ST-Link to connect the board. Connect SWDIO, SWCLK, GND, and 3.3V if using ST-Link.
3. Create a Project: Open STM32CubeIDE → File → New STM32 Project → Search for STM32F401CCU6 → Name your project BlinkLED.
🔌 ST-Link V2 to BlackPill Connection
ST-Link V2 |
BlackPill |
SWDIO |
SWDIO |
SWCLK |
SWCLK |
GND |
GND |
3.3V |
3.3V |
ST-Link V2 connected to STM32F401 BlackPill using SWD interface
Initial setup of BlackPill in STM32CubeIDE
Creating a new project for STM32F401CCU6
Configuring GPIO pins in STM32CubeIDE
Additional GPIO settings and configuration
📦 Materials Required
· STM32F401 BlackPill board
· USB cable (Micro USB)
· ST-Link V2 Programmer (optional)
· LED (optional for breadboard test)
· Breadboard & jumper wires
🧑💻 Blink LED Code
// USER CODE BEGIN 2
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
// USER CODE END 2
// Infinite loop
// USER CODE BEGIN WHILE
while (1)
{
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(500);
// USER CODE END WHILE
// USER CODE BEGIN 3
}
// USER CODE END WHILE
🚀 Upload & Run
Click the green play button or go to Run → Debug in STM32CubeIDE. The onboard LED connected to PC13 should start blinking.
Debugging interface in STM32CubeIDE showing the debug button and configuration
❌ Troubleshooting
· Check ST-Link or USB connections
· Confirm pin configurations in your .ioc file
· Ensure proper power to the board