Step by Step Guidance to Blink External Connected LED Using HAL Programming on STM32CubeIDE and STM32CubeProgrammer

by Jasleen_kaur in Circuits > Microcontrollers

51 Views, 0 Favorites, 0 Comments

Step by Step Guidance to Blink External Connected LED Using HAL Programming on STM32CubeIDE and STM32CubeProgrammer

WhatsApp Image 2024-04-24 at 01.35.14_a5055dc9.jpg

Welcome to our exciting tutorial on how to utilize STM32CubeIDE to make the external LED with your STM32 Black Pill board. Our step-by-step guide is perfect for professionals who want a clear and concise walkthrough on how to harness the full potential of this powerful microcontroller. Over the course of this tutorial, we'll cover everything you need to know, from setting up your development environment to writing efficient code to manage the LED. You'll gain a solid understanding of embedded development and build the skills you need to tackle even the most complex projects. Join us as we delve into the world of microcontroller programming with the utmost precision and professionalism, and bring your projects to the next level!

Supplies

1.STM32 Black Pill

2.STM32CubeIDE

3.STM32CubeProgrammer

4.C-type cable

5.LED

6.Jumper Wire

Creating a New Project

Screenshot 2024-04-24 004346.png
  • Open STM32CubeIDE>click on files>select>new>stm32 projects



Adding MCU/MPU Selector Features for STM32 Project

Screenshot 2024-04-24 004518.png
Screenshot 2024-04-24 004628.png
Screenshot 2024-04-24 005040.png
  • Enter the Commerical Number of STM32 you want to work with( used Commerical Number in this project:STM32F401CCU6)
  • Select the required type of configuration of STM32.
  • Then click next.
  • A dialogue box appears >type the name of the project
  • The project file is created to work on it.


Pinout Configurations

Screenshot 2024-04-24 005136.png
Screenshot 2024-04-24 005429.png
Screenshot 2024-04-24 005153.png
  • Select RCC from System Core.
  • Select the Cereamic/crystal response in High speed clock.
  • Some configurations wlll be added ,i.e,RCC_OSC_IN & RCC_OSC_OUT ON STM32 board of cubeide.
  • Select the Pin number for output .(here I used PA12).


Clock Configuration

Screenshot 2024-04-24 005547.png
  • Select clock configuration.
  • Select HSE and PLLCLK in PLL Source MUX & System Clock MUX respectively.
  • Then select resolve clock issues.

Generating the Code

Screenshot 2024-04-24 005823.png
  • Select the project from dialogue box.
  • Select generate code option from it.
  • The code gets generated.

Creating .Ioc File

Screenshot 2024-04-24 005916.png
Screenshot 2024-04-24 010003.png
Screenshot 2024-04-24 010250.png
  • Select the file you working on (from the left side)>right click on it.
  • A option box appears>select properties.
  • Then the dialogue box opens >select the C/C++ Build (from left side of it).
  • Select settings>MCU Post build Ouput
  • Choose the options shown in the image.
  • Then apply and close.
  • The .ioc file is created.

Main.c

Screenshot 2024-04-24 010333.png
Screenshot 2024-04-24 010345.png
  • Select the core from the File .
  • Go to Src>select main.c.
  • Main.c gets open to write code.(A code is generated already to help you in the configuration and to identify pin numbers you selected as output pin)


Writing Code

Screenshot 2024-04-24 010611.png
  • Write the code in while loop.

Code:

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,0);

{HAL_Delay(500);}

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,1);

{HAL_Delay(500);}


Debug the Code

Screenshot 2024-04-24 010656.png
  • Select Build >select option 1.debug

Copying the Path Of.elf File

Screenshot 2024-04-24 011243.png
WhatsApp Image 2024-04-24 at 01.23.29_b2e43a7c.jpg
  • After debuging the ;if any error arises then remove all the error and if no error comes then go to .ioc file.
  • Select .ioc file right click on it ,a option box appears.
  • Select show in>system explorer.
  • Files will be opened.
  • Select the .elf file and copy its path.

Adding the .elf on STM32CubeProgramer

Screenshot 2024-04-24 012530.png
Screenshot 2024-04-24 012556.png
Screenshot 2024-04-24 012614.png
  • Open the STM32CubeProgrammer.
  • Select the Open file option >paste the path copied of .elf file there.
  • File is added.

Breadboard Connection

WhatsApp Image 2024-04-24 at 01.37.07_d994726d.jpg
  • Place the Stm32 on breadboard.
  • Connect the LED with STM32 by the pin given in STM32CubeIDE.
  • Ground the LED with the ground pin from STM32.

Connect the STM32

Screenshot 2024-04-24 013747.png
Screenshot 2024-04-24 202245.png
  • Connect the STM32 Black pill with Laptop.
  • Connect it with STM32CubeProgrammer by USB.
  • BOOT the STM32 to connect it.
  • After connecting click on Connect.

Download the File

Screenshot 2024-04-24 013301.png
Screenshot 2024-04-24 013307.png
  • Goto Download>paste the copied of .elf file here also
  • Click on Start Automatic Mode.

LED Starts Blinking

WhatsApp Image 2024-04-24 at 01.35.14_a5055dc9.jpg
  • Disconnect the STM32.
  • Then connect again and you will see that the LED is blinking.