#include "stm32f1xx.h"
int main(void)
{
/* 1. Enable GPIOC clock */
RCC->APB2ENR |= (1U << 4);
/* 2. Configure PC13 as general-purpose push-pull output */
GPIOC->CRH &= ~(0xFU << 20);
GPIOC->CRH |= (0x2U << 20);
/* 3. Enable TIM2 clock */
RCC->APB1ENR |= (1U << 0);
/* 4. Configure TIM2 for 100 ms */
TIM2->PSC = 7199;
TIM2->ARR = 999;
TIM2->CNT = 0;
/* Generate an update event to load timer settings */
TIM2->EGR = 1U;
/* Clear update flag */
TIM2->SR &= ~1U;
/* 5. Start TIM2 */
TIM2->CR1 |= 1U;
while (1)
{
/* Check timer update flag */
if (TIM2->SR & 1U)
{
/* Clear flag */
TIM2->SR &= ~1U;
/* Toggle PC13 */
GPIOC->ODR ^= (1U << 13);
}
}
}Loading
stm32-bluepill
stm32-bluepill