diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 29 |
1 files changed, 17 insertions, 12 deletions
@@ -1,47 +1,52 @@ +// vim: shiftwidth=4 tabstop=4 noexpandtab #include <libopencm3/stm32/rcc.h> #include <libopencm3/stm32/gpio.h> -#define DELAY 100000 +/* +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 -void clock_init(void); -void gpio_init(void); -void delay(void); +static void clock_init(void); +static void gpio_init(void); +static void delay(uint32_t delay); -int main(void) +void main(void) { clock_init(); gpio_init(); while(1){ gpio_toggle(GPIOC, GPIO13); - delay(); + delay(250 * DELAY_MS); } - - return 0; } -void clock_init(void) +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 } -void gpio_init(void) +static void gpio_init(void) { gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); gpio_set(GPIOC, GPIO13); } -void delay(void) +static void delay(uint32_t delay) { - for (int i = 0; i < DELAY; i++) { + for (uint32_t i = 0; i < delay; i++) { __asm__("nop"); } } |