STM32 Microcontroller Tutorial
STM32 Microcontroller Tutorial
Microcontroller
Tutorial
BLINKING AN LED DEMONSTRATION
DATE: 14.03.2025
PRESENTER: M MUJAHID
ELT-2K22-402
ELECTRONICS (A)
SESSION 2024-2025
Introduction
• 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
• What is STM32CubeIDE?
- A free and powerful development environment for STM32
microcontrollers.
#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
• Testing:
- Observe the LED blinking every 500ms.
Results