-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplatform.c
42 lines (31 loc) · 898 Bytes
/
platform.c
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
#include <libopencm3/cm3/systick.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include "platform.h"
volatile uint32_t __systick;
/* Handlers */
void sys_tick_handler(void) { __systick++; }
/* API */
int platform_init(void) {
/* clock */
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]);
if (!systick_set_frequency(SYSTICK_FREQ, rcc_ahb_frequency))
return -1;
systick_counter_enable();
/* led */
rcc_periph_clock_enable(RCC_GPIOC);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
GPIO13);
gpio_clear(GPIOC, GPIO13);
/* enable interrupts */
systick_interrupt_enable();
return 0;
}
void set_led(bool on) {
if (!on) {
gpio_set(GPIOC, GPIO13);
} else {
gpio_clear(GPIOC, GPIO13);
}
}
uint32_t get_systick(void) { return __systick; }