Blinking On-board LED of STM32 Blackpill Board

by Pancham_3545 in Circuits > Electronics

1052 Views, 1 Favorites, 0 Comments

Blinking On-board LED of STM32 Blackpill Board

STM32-blue-pill.jpg



STM32 is a family of 32-bit microcontroller integrated circuits by STMicroelectronics.STM32 microcontrollers offer a large number of serial and parallel communication peripherals which can be interfaced with all kinds of electronic components including sensors, displays, cameras, motors, etc. All STM32 variants come with internal Flash memory and RAM.

Are you ready to dive into the exciting world of STM32 microcontrollers and HAL programming? If so, this tutorial is for you! In this tutorial, we will walk you through the steps to get started with STM32 black pill and STM cube IDE to blink on-board LED using HAL programming.

Before we get started, let's make sure we have all the necessary tools and equipment:

STM32 black pill board

USB cable

STM cube IDE

Basic knowledge of C programming

Step 1: Setting up STM cube IDE

The first step in this process is to download and install the STM cube IDE. You can download it from the official website of STMicroelectronics. After installing the IDE, open it and create a new project. Select the STM32F1xx family and choose the board you are using.

Step 2: Configuring the clock

The next step is to configure the clock for the microcontroller. This is important because it determines the speed at which the microcontroller runs. To do this, go to the "System Clock Configuration" tab and select the desired clock speed.

Step 3: Configuring the GPIO pin

Now we need to configure the GPIO pin that is connected to the on-board LED. In the "Pinout" tab, select the pin that is connected to the LED and set it to output mode.

Step 4: Writing the code

Now it's time to write the code to blink the LED. We will be using HAL programming for this. The code is pretty simple and straightforward. Here's the code:

#include "stm32f1xx_hal.h"

int main(void)

{

 HAL_Init();

 __HAL_RCC_GPIOC_CLK_ENABLE();

 GPIO_InitTypeDef GPIO_InitStruct;

 GPIO_InitStruct.Pin = GPIO_PIN_13;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 while (1)

 {

  HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);

  HAL_Delay(1000);

 }

}

This code initializes the GPIO pin and then toggles its state every second using the HAL_GPIO_TogglePin function.

Step 5: Building and uploading the code

Now that we have written the code, it's time to build it and upload it to the microcontroller. Click on the "Build" button in the IDE to build the code. Once the build is successful, connect the USB cable to the board and upload the code using the "Upload" button.

Step 6: Testing the code

Congratulations! You have successfully written and uploaded the code to blink the on-board LED using STM32 black pill and STM cube IDE. Disconnect the USB cable and power the board using an external power source. You should see the LED blinking every second.

In conclusion, this tutorial covered the basics of getting started with STM32 black pill and STM cube IDE to blink on-board LED using HAL programming. With this knowledge, you can now explore more advanced features and functionalities of the microcontroller and take your skills to the next level.

This tutorial covered the basics of getting started with STM32 black pill and STM cube IDE to blink on-board LED using HAL programming. With this knowledge, you can now explore more advanced features and functionalities of the microcontroller and take your skills to the next level.