-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
43 lines (35 loc) · 940 Bytes
/
main.cpp
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
/* PB1 is connected to the onboard LED on the STM32F030F4P6 breakout board. */
#define PORT_LED_ONBOARD GPIOB
#define PIN_LED_ONBOARD GPIO1
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <core/core.h>
/* set STM32 to clock by 48MHz from HSI oscillator */
static void clock_setup(void)
{
rcc_clock_setup_in_hsi_out_48mhz();
/* Enable clocks to the GPIO subsystems */
rcc_periph_clock_enable(RCC_GPIOB);
}
static void gpio_setup(void)
{
gpio_mode_setup(PORT_LED_ONBOARD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PIN_LED_ONBOARD);
}
int main(void)
{
clock_setup();
gpio_setup();
/* setup systick to generate 2 LED flashes per second */
systick_init();
/* Do nothing in main loop */
while (1)
{
static const uint16_t period = 500;
static elapsedMillis timer = period;
if (timer >= period)
{
timer = 0;
gpio_toggle(PORT_LED_ONBOARD, PIN_LED_ONBOARD);
}
}
}