Introduction: Using TMSTM 32 for LED Blinking

Hey there, embedded aficionados! Ready to infuse some life into your STM32 Black Pill? This tutorial is your roadmap to illuminating the onboard LED. Whether you're a seasoned STM32 guru or just dipping your toes into the hardware pool, this guide provides a smooth entry point to mastering GPIO pin configuration and hardware manipulation on the Black Pill. Let's roll up our sleeves and get that LED pulsing!




Attachments

Supplies

Before delving into embedded programming, let's prepare your arsenal. Let's ensure you have the necessary tools and software:

Development Environment:

  • A laptop or desktop computer
  • STM32CubeIDE
  • STM32CubeProgrammer

Hardware:

  • STM32 Black Pill development board
  • USB cable that's compatible with the board




Step 1: Making a New Project in STM32 CUBE IDE

Navigate to the "Files" tab, then select "New" followed by "STM32 Project". Assign a unique name to your project to continue.

Step 2: Adding Configuration to STM Board

Locate the component "STM32F401CCU6" in the search bar. Once found, select the necessary component and proceed by clicking "Next".

Step 3: Let's Configure the Board Settings:

  1. In the STM32 slide, choose "STM32".
  2. Select pin 13 as GPIO output.
  3. Proceed to configure the other settings.
  4. Set the RCC Mode configuration.



Step 4: The Next Step Is to Configure the Clock Settings:

Choose the high-speed clock and set it to ceramic/crystal response.


Step 5: Configuring MCU Post-Build Outputs:

Here's how to configure MCU Post-Build Outputs:

  1. Access Project Properties: Right-click on your project name in the Project Explorer and choose "Properties."
  2. Navigate to C/C++ Build Settings: In the project properties window, find the "C/C++ Build" section, expand it, and select "Settings."
  3. Enable MCU Post-Build Outputs: Within the "Settings" tab, locate the "MCU Post Build outputs" section. Tick the boxes next to your preferred output options, as demonstrated in the provided image if available.




Step 6: Code Configuration

  1. Go to the "Project" tab.
  2. Find and open the main.c file.
  3. Locate the main() function within the file.
  4. Inside the main() function, find the while(1) loop.
  5. Add your code within the while(1) loop.




Step 7: Code Building

Used GPIO Pin number 13 you can use other GPIO Pins


HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 1);

HAL_Delay(5000);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0);

HAL_Delay(5000);

> Upload the code and wait for it to build properly and check for any error or bug!!

Step 8: Debugging

Debug the code with the help of the in hammer icon in task bar.

Step 9: Copying the Path of Elf File

  1. Locate the .ioc file:
  2. Search for it in the Project Explorer on the left side, listed under your project name.
  3. Copy the file path:
  4. Right-click on the .ioc file and select the option to copy its path.
  5. This action copies the complete file location, ready for pasting wherever needed.




Step 10: Connect Board to Programmer

  1. Connect your STM board to your computer via USB cable.
  2. In STM32CubeProgrammer, locate and select the option to connect to the board.
  3. Ensure that the connection is successful and the board is recognized by the software.


Step 11: Configure Download Settings and Activate Automatic Downloads

Step 12: LED Blinks