STM32
Microcontroller
Tutorial
BLINKING AN LED DEMONSTRATION
DATE: 14.03.2025
PRESENTER: M MUJAHID
ELT-2K22-402
ELECTRONICS (A)
SESSION 2024-2025
Introduction
• What is STM32 Microcontroller?
- STM32 is a series of ARM Cortex-M based microcontrollers.
- Known for high performance, low power, and extensive periphe
- It is Developed by STMicroelectronics.
• Tutorial Objective:
- Understanding basic usage of STM32.
- Practical demonstration of blinking an LED.
Required Components
• Hardware:
1. STM32 Microcontroller Board (e.g., STM32F103C8T6)
2. LED
3. Resistor (220Ω)
4. Breadboard
5. Jumper Wires
6. ST-Link Programmer
• Software:
1. STM32CubeIDE (Free & Powerful Development Environment)
Hardware Connections
• Connecting the LED to STM32:
1. Connect the positive terminal (Anode) of the LED to GPIO pin (
PA5).
2. Connect the negative terminal (Cathode) through a 220Ω resis
GND.
Software Setup
• What is STM32CubeIDE?
- A free and powerful development environment for STM32
microcontrollers.
• Steps to Create a Project:
1. Open STM32CubeIDE and create a new project.
2. Select your STM32 microcontroller model.
3. Configure GPIO pin (PA5) as 'Output'.
Code Explanation
#include “main.h”
// Delay function (if HAL_Delay is not used)
void delay(uint32_t time) {
for(uint32_t I = 0; I < time * 4000; i++);
}
int main(void) {
HAL_Init(); // Initialize the HAL Library
__HAL_RCC_GPIOA_CLK_ENABLE(); // Enable clock for GPIOA (adjust as per your board)
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5; // Select the pin (e.g., PA5 on Nucleo Board)
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Output mode
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // Initialize GPIOA Pin 5
while (1) {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); // Toggle LED
HAL_Delay(500); // Delay 500ms
}
}
Programming & Testing
• Steps to Upload the Program:
1. Compile the code.
2. Upload it to the STM32 board using ST-Link Programmer.
• Testing:
- Observe the LED blinking every 500ms.
Results
• The LED blinks successfully.
• Demonstrates the basic use of STM32 microcontroller.