4 #include <libopencm3/cm3/cortex.h>
5 #include <libopencm3/cm3/nvic.h>
6 #include <libopencm3/cm3/systick.h>
7 #include <libopencm3/stm32/rcc.h>
8 #include <libopencm3/stm32/gpio.h>
10 static void clock_setup(void)
12 rcc_clock_setup_in_hse_8mhz_out_72mhz();
14 rcc_periph_clock_enable(RCC_GPIOC);
16 rcc_periph_reset_pulse(RST_GPIOC);
19 static void gpio_setup(void)
21 // PC13 = BluePill LED
22 gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
23 gpio_clear(GPIOC, GPIO13);
26 static volatile u32 ms_ticks;
28 void sys_tick_handler(void)
33 static void tick_setup(void)
35 systick_set_frequency(1000, 72000000);
36 systick_counter_enable();
37 systick_interrupt_enable();
40 static void delay_ms(uint ms)
42 u32 start_ticks = ms_ticks;
43 while (ms_ticks - start_ticks < ms)
52 cm_enable_interrupts();
55 gpio_toggle(GPIOC, GPIO13);
57 gpio_toggle(GPIOC, GPIO13);