STM32 Black Pill Board | Blinking On-board LED

by Anjandeep Singh in Circuits > Microcontrollers

25 Views, 1 Favorites, 0 Comments

STM32 Black Pill Board | Blinking On-board LED

STM32F103C8T6_Black_Pill-1.jpg
317353.jpg

This blog post is a guide to start your STM32 Black Pill and control the on-board LED using a program on STM32CubeIDE.

Supplies

Software:

  • STM32CubeIDE
  • STM32CubeProgrammer

Hardware:

  • Desktop or a laptop
  • USB-C cable
  • STM32 Black Pill

Create a Project File on STM32CubeIDE

stm32cubeide_c86Q5q8ObT.png
stm32cubeide_aQMVUfP8JB.png
stm32cubeide_NxTXNfbBzj.png

Create a project file.

  • Type the project name.
  • Choose your preferred programming language, binary type and project type.
  • Choose "Add necessary library files" for less errors and problems.

Pinout & Clock Configurations

stm32cubeide_fVcwb6DVus.png
stm32cubeide_jk2YLx1CDV.png

Follow the steps shown in the attachments. And configure the pin-out and clock as per your board and requirement.

Save your file.

Code

  • Save your file, this will generate files.
  • Go to Core < Src < main.c.

  • Go to int main() which is around line 95.
  • Change the code inside while(1).

[while(1) is an infinite loop which is used in embedded electronics.]

    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 1);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0);
HAL_Delay(500);
  • Finally, debug the code.

Open the Project File in File Explorer

stm32cubeide_7YcPKXCTnL.png
  • Copy the path of .elf file.

Setup STM32CubeProgrammer

javaw_MODih5pSe7.png
javaw_TLY6Y1rZBA.png
javaw_xBd5Pxp5LM.png
javaw_XCMB6vhBOu.png
javaw_b5d3BPjPBx.png
  • We will bootload STM using USB, this tutorial does not use ST-Link.
  • Next, press on "Open file" and select the .elf file from the project folder.
  • Press on "Download".


  • Go to "Erasing and Programming" from the menu in the left.
  • Go to file path and select the .elf file and press "Start automatic mode".


Result

javaw_7pphejCDUV.png

Once compiled, disconnect and reconnect the STM board using USB-C cable.


Voila, your STM32 Board's onboard LED should now start blinking.


Thank you!