1 #include <libopencm3/stm32/rcc.h>
2 #include <libopencm3/stm32/gpio.h>
3 #include <libopencm3/stm32/timer.h>
7 rcc_clock_setup_in_hse_8mhz_out_72mhz();
8 rcc_periph_clock_enable(RCC_GPIOB);
9 rcc_periph_clock_enable(RCC_GPIOC);
10 rcc_periph_clock_enable(RCC_TIM3);
11 rcc_periph_reset_pulse(RST_TIM3); // XXX
13 // PC13 = BluePill LED
14 gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
15 gpio_set(GPIOC, GPIO13);
18 gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO0);
20 timer_set_prescaler(TIM3, 1); // 72 MHz / 2 = 36 MHz
21 timer_set_mode(TIM3, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
22 timer_set_period(TIM3, 999); // 36 MHz / 1000 = 36 kHz
23 timer_update_on_overflow(TIM3);
25 timer_set_oc_mode(TIM3, TIM_OC3, TIM_OCM_PWM1);
26 timer_set_oc_value(TIM3, TIM_OC3, 50);
27 timer_set_oc_polarity_high(TIM3, TIM_OC3);
28 timer_enable_oc_output(TIM3, TIM_OC3);
30 timer_enable_counter(TIM3);