External LED Blinking on STM32 Using HAL Programming
by Maitali sharma in Circuits > Microcontrollers
21 Views, 0 Favorites, 0 Comments
External LED Blinking on STM32 Using HAL Programming
This is an instructable for using STM32 Black Pill which uses STM32F401CCU6 micro-controller for controlling an external LED using ST's native IDE, STM32CubeIDE. This tutorial does not use ST-LINK.
Create Project on STM32CubeIDE
- Create new project on STM32CubeIDE by following the steps on the attachment.
- Select the appropriate name for the task and press "Finish."
Select Appropriate Board
Save your file.
Code
- Open "main.c" file.
- Go to line 95, in "while(1)" write the code to send a HIGH [digital 1] output, then add a delay and send a LOW [digital 0] output to the LED.
- Your code should look something like in the attachment.
- You can also use toggle function.
- Finally, press the debug button from the menu bar or use F11 shortcut key.
Interfacing of External LED
- As I chose PB10 for GPIO, I'll connect the +ve terminal of the LED to it.
- And connect -ve terminal of the LED to GND. You can check the pinout of ground from attachment shown above.
Setup STM32CubeProgrammer
- Choose USB as the connection method. [This tutorial does not use ST-LINK.]
- Enter boot-loader mode by the steps in the attachment. Refresh until it shows up and press "Connect."
Your STM32 board should show up in the device manager under Universal Serial Bus devices if done correctly.
- Press on "Open file" and choose the .elf file from STM32 project directory.
- Press download.
- Go to the download icon from the menu in the left and press browse. Again select the .elf file.
- Once done, check the options as shown in the attachment.
- Finally, press on "Start automatic mode."
- Once a message saying "Please disconnect device n:1 and connect the next..." shows up reconnect your STM32 board.