Skip to content

cherry-here/stm32-arm-cortex-projects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

STM32F103C8 LED Blinking Timer -- ARM Cortex-M3

Configured STM32F103C8 (Blue Pill) GPIO and TIM2 peripheral to blink an on-board LED at precise 2-second intervals using HAL library, demonstrating register-level timer prescaler and auto-reload calculations for embedded bare-metal programming.

Overview

Configured the STM32F103C8T6 "Blue Pill" microcontroller to blink its on-board LED (PC13) at precise 2-second intervals using the TIM2 general-purpose timer peripheral. The project demonstrates fundamental ARM Cortex-M3 bare-metal concepts including GPIO port configuration (output push-pull), RCC clock enable for GPIOC and TIM2, timer prescaler and auto-reload register calculations, and NVIC interrupt handling via HAL callbacks.

The timer is driven from the APB1 bus clock (72 MHz after PLL multiplication from the 8 MHz HSE crystal), with a prescaler of 7200 and auto-reload of 10000 yielding exactly 2.0 seconds between toggle events. Built and flashed using STM32CubeIDE with the HAL library framework, verified on hardware with an oscilloscope on PC13 confirming the 0.5 Hz square wave output.

Key Metrics

Metric Value
Blink Interval 2.0 seconds
Timer TIM2 peripheral
System Clock 72 MHz
Framework HAL + bare-metal

Hardware Connection Table

Component STM32 Pin Connection Notes
On-board LED PC13 Active-low (built-in) LED ON = Pin LOW
HSE Crystal PD0 (OSC_IN) 8 MHz crystal Pierce oscillator
HSE Crystal PD1 (OSC_OUT) 8 MHz crystal 20 pF load caps
ST-Link SWDIO PA13 ST-Link V2 Serial Wire Data
ST-Link SWCLK PA14 ST-Link V2 Serial Wire Clock
ST-Link 3.3V 3.3V ST-Link V2 Target power
ST-Link GND GND ST-Link V2 Common ground
NRST NRST ST-Link V2 Reset (optional)

Clock Tree

HSE Crystal (8 MHz)
        v
PLL (x9 multiplication)
        v
SYSCLK = 72 MHz -> AHB = 72 MHz
                    v
              APB1 = 36 MHz (/2)
                    v
         Timer Clock = 72 MHz (auto-doubled when APB1 prescaler != 1)
                    v
              TIM2 (PSC=7199, ARR=9999)
                    v
         1 Hz overflow -> LED toggle -> 2.0s blink period

Timer Calculation

Parameter Value Explanation
TIM2 Clock 72 MHz APB1 timer auto-double
PSC (Prescaler) 7199 72 MHz / 7200 = 10 kHz tick
ARR (Auto-Reload) 9999 10 kHz / 10000 = 1 Hz
Toggle Period 2.0 s Toggle on each overflow

Tech Stack

  • MCU: STM32F103C8T6 (ARM Cortex-M3 @ 72 MHz)
  • Toolchain: STM32CubeIDE
  • Framework: HAL Library + bare-metal register access
  • Debugger: ST-Link V2 (SWD)
  • Language: C

Author

Mothi Charan Naik Desavath -- Embedded Systems Engineer

About

STM32F103C8 LED Blinking Timer -- ARM Cortex-M3 bare-metal TIM2 peripheral config, HAL library, 72 MHz clock tree, 2s precise interval

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors