First, ensure that you have the STM32CubeIDE installed on your computer. If not, download and install it from the STMicroelectronics website.
Step 2: Creating a New ProjectOpen STM32CubeIDE and create a new project:
- Go to File > New > STM32 Project.
- Select the appropriate part number for your Black Pill board (e.g., STM32F103C8T6).
- Name your project and set the location.
- In the Pinout & Configuration tab, find the pin connected to the on-board LED (usually PC13).
- Set the pin mode to GPIO_Output.
Open the main.c
file and write the following code inside the while(1)
loop:
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(500);
This code toggles the LED state and creates a 500ms delay between each toggle, effectively blinking the LED.
Step 5: Building and Flashing the Code- Click on the Build button to compile your project.
- Connect your Black Pill board to the computer using a USB cable.
- Use the Run > Debug option to flash the program onto your board.
Once the code is flashed, the on-board LED should start blinking. Congratulations, you’ve successfully programmed your STM32 Black Pill board!
Comments