Get Started With STM32 Black Pill and STM Cube IDE to Blink On-board LED

by Tushar_Garg in Circuits > Microcontrollers

147 Views, 0 Favorites, 0 Comments

Get Started With STM32 Black Pill and STM Cube IDE to Blink On-board LED

1_aiQ43PXl_gJJwShT5KNjpQ.jpg

Welcome embedded enthusiasts! Are you ready to light up your world (or at least your STM32 Black Pill)? This tutorial will guide you step-by-step through activating the on-board LED. Whether you're a seasoned STM32 developer or just getting started, this is a perfect entry point to learn the ropes of configuring GPIO pins and manipulating hardware on the Black Pill. Let's get that LED blinking!

Supplies

Untitled design.png

Before we dive into embedded programming, let's get your toolkit ready. We'll need to install some essential software and ensure you have the right equipment:

  • Development Environment:
  • A laptop or desktop computer
  • STM32CubeIDE
  • STM32CubeProgrammer
  • Hardware:
  • STM32 Black Pill development board
  • Compatible USB cable

Making a New Project File in STM32CubeIDE

FU7F2J5LUGYMWQ4.png
4.png

GOTO---->> Go to files>New>STM32 Project>>Name the project

Add the Configurations for Your STM Board

2.png
3.png

Search For Component---->> Search For Component STM32F401CCU6> Select the required and then click on "Next".

Configuring the Board Settings

FEXZ5XWLUGYMX1L.png
F5A8ZF3LUGYMX1Z.png

The slide will open with STM32 >select the pin (13 as GPIO_output)>>then set the other settings (RCC Mode configuration>>high speed clock to ceramic/crystal response.

Configure Your Clock

FU3B19WLT5T3KMM.png

Settings

FOUQG5HLUGYMY1O.png

Configure MCU Post-Build Outputs:

  1. Access Project Properties: Right-click on your project name in the Project Explorer and select "Properties."
  2. Navigate to C/C++ Build Settings: Within the project properties window, locate the "C/C++ Build" section and expand it. Then, select "Settings."
  3. Enable MCU Post-Build Outputs: Under the "Settings" tab, find the section labeled "MCU Post Build outputs." Check the boxes next to the desired output options displayed in the provided image (assuming the image shows the specific options you want to enable).


Open Main.c File

FZ8121SLT5T3KON.png

GOTO Project and find main.c file

Goto While(1) in Main() and Add Your Code

FXAH6TLLT5T3KUB.png

Used GPIO Pin number 13 you can use other GPIO Pins


HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 1);

HAL_Delay(5000);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0);

HAL_Delay(5000);

Debug

FN4GWL4LUGYN07R.png

Debug the code using the option available in hammer icon in task bar.

Copy the Path Of.elf File

F4SN3YZLUGYN0Z4.png

To copy the path of your project's .ioc file in STM32CubeIDE:

1. Find the .ioc file:

  • Look for it in the Project Explorer window (left side) under your project name.

2. Right-click and copy:

  • Right-click the .ioc file and choose "Copy Path" (or similar).

This copies the entire file location for pasting elsewhere.

Open STMCubeProgrammer and Connect to STM Board Via USB

FOEPK4ZLT5T3LJ0.png

Click on Open File and Paste the Copied Path

FK4GRO0LT5T3LLQ.png

Go to Download Options (Found in Toolbar on the Left)

FXTQHFPLT5T3LO2.png

Configure Download Settings and Activate Automatic Downloads

FFKBDKCLT5T3LYV.png

On Board LED Will Start Blinking.

STM32.jpg

Congratulations! That blinking LED is a great first step in your embedded systems journey.