Step by Step Guidance to Blink External Connected LED Using HAL Programming on STM32CubeIDE and STM32CubeProgrammer
by Jasleen_kaur in Circuits > Microcontrollers
81 Views, 0 Favorites, 0 Comments
Step by Step Guidance to Blink External Connected LED Using HAL Programming on STM32CubeIDE and STM32CubeProgrammer
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
- Open STM32CubeIDE>click on files>select>new>stm32 projects
Adding MCU/MPU Selector Features for STM32 Project
- 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
- 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
- Select clock configuration.
- Select HSE and PLLCLK in PLL Source MUX & System Clock MUX respectively.
- Then select resolve clock issues.
Generating the Code
- Select the project from dialogue box.
- Select generate code option from it.
- The code gets generated.
Creating .Ioc File
- 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
- 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
- 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
- Select Build >select option 1.debug
Copying the Path Of.elf File
- 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
- Open the STM32CubeProgrammer.
- Select the Open file option >paste the path copied of .elf file there.
- File is added.
Breadboard Connection
- 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
- 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
- Goto Download>paste the copied of .elf file here also
- Click on Start Automatic Mode.
LED Starts Blinking
- Disconnect the STM32.
- Then connect again and you will see that the LED is blinking.