]> mj.ucw.cz Git - home-hw.git/blob - protab/blink2/blink.c
test-neopixel-square: init
[home-hw.git] / protab / blink2 / blink.c
1 #include <libopencm3/cm3/systick.h>
2 #include <libopencm3/stm32/rcc.h>
3 #include <libopencm3/stm32/gpio.h>
4
5 static void delay_ms(unsigned int ms)
6 {
7         systick_clear();
8         for (unsigned int i=0; i<ms; i++)
9                 while (!systick_get_countflag())
10                         ;
11 }
12
13 int main(void)
14 {
15         rcc_clock_setup_in_hse_8mhz_out_72mhz();
16         rcc_periph_clock_enable(RCC_GPIOC);
17
18         // PC13 = BluePill LED
19         gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
20
21         systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
22         systick_set_reload(71999);
23         systick_counter_enable();
24
25         for (;;) {
26                 gpio_clear(GPIOC, GPIO13);
27                 delay_ms(100);
28                 gpio_set(GPIOC, GPIO13);
29                 delay_ms(500);
30         }
31
32         return 0;
33 }