1 #include <libopencm3/stm32/rcc.h>
2 #include <libopencm3/stm32/gpio.h>
3 #include <libopencm3/stm32/timer.h>
5 static void delay_ms(unsigned int ms)
7 timer_set_period(TIM3, 2*ms);
8 timer_enable_counter(TIM3);
9 while (TIM_CR1(TIM3) & TIM_CR1_CEN)
15 rcc_clock_setup_in_hse_8mhz_out_72mhz();
16 rcc_periph_clock_enable(RCC_GPIOC);
17 rcc_periph_clock_enable(RCC_TIM3);
19 // PC13 = BluePill LED
20 gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
22 timer_set_prescaler(TIM3, 35999); // 72 MHz / 36000 = 2 kHz
23 timer_set_mode(TIM3, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_DOWN);
24 timer_one_shot_mode(TIM3);
27 gpio_clear(GPIOC, GPIO13);
29 gpio_set(GPIOC, GPIO13);