Activating the On-Board LED of the STM32 Black Pill: a Simple Guide

by Bhumika_Chawla in Circuits > Microcontrollers

62 Views, 1 Favorites, 0 Comments

Activating the On-Board LED of the STM32 Black Pill: a Simple Guide

1400px-Black_pill_pinout.png

Welcome to our step-by-step guide on using STM32CubeIDE to control the built-in LED of the STM32 Black Pill microcontroller. We've designed this tutorial to be easy to follow, even if you're new to embedded development. You'll learn how to set up your environment, get to know the Black Pill's hardware, and write code to control the LED. This basic exercise is essential for getting started with microcontroller programming. Let's dive in and explore together!

Supplies

Before we get started with embedded programming, make sure you have the following:


1. A laptop or desktop computer with STM32CubeIDE and STM32CubeProgrammer installed.


2. An STM32 Black Pill development board.


3. A USB cable that works with your board for connection and programming.


Having these ready will ensure a smooth and hassle-free programming experience. Let's dive in!

Making a New Project File in STM32CubeIDE

Screenshot 2024-05-06 084053.png

OPEN File>New>STM32 Project

ADD Configurations

Screenshot 2024-05-06 084145.png

Find and select your STMboard

In our case we will be using STM32F401CCU6

Configuring Your Board and Clocks

Screenshot 2024-05-06 084302.png
Screenshot 2024-05-06 084257.png

Once Done With These Steps Press CTRL+S to generate "main.c" File

Entering the Code

Screenshot 2024-05-06 084354.png

Locate and Open the main.c file (located in Core>>SRC>>main.c) & and add the above code in While(1) Loop

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 1);

HAL_Delay(500);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0);

HAL_Delay(500);

Here we have used Pin 13 beacuse it has the internal LED Connected to it

Debug

Screenshot 2024-05-06 084625.png

Click on Debug


Locate File Locate in System

Screenshot 2024-05-06 084703.png

Right click on Project and click on show in system explorer and copy the path

Open STMCubeProgrammer

Screenshot 2024-05-06 084820.png

Connect the STM Board using USB

Modify the Download Settings and Select "Begin Automatic Mode."

Screenshot 2024-05-06 084922.png

Done, LED Is Now Blinking

Screenshot 2024-05-06 085031.png