summaryrefslogtreecommitdiff
path: root/src/main.c
blob: 50d7fdc7d75d9c372a6dc966da48b77df8fa6dfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// vim: shiftwidth=4 tabstop=4 noexpandtab


#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>


/*
SYSCLK should be at 72.000.000 Hz
--> 18.000.000 __asm__("nop") per second (one instruction --> 4 clock cycles)
--> 18.000 __asm__("nop") per millisecond
*/
#define DELAY_MS 18000  // FIXME seems to be too slow by factor of 4


static void clock_init(void);
static void gpio_init(void);
static void delay(uint32_t delay);


void main(void)
{
	clock_init();
	gpio_init();

	while(1){
		gpio_toggle(GPIOC, GPIO13);
		delay(250 * DELAY_MS);
	}
}


static void clock_init(void)
{
	rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]);
	rcc_periph_clock_enable(RCC_GPIOC);  // for PC13 blinking
}


static void gpio_init(void)
{
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
	gpio_set(GPIOC, GPIO13);
}


static void delay(uint32_t delay)
{
	for (uint32_t i = 0; i < delay; i++) {
		__asm__("nop");
	}
}