/
main.c
50 lines (38 loc) · 920 Bytes
/
main.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
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <stdint.h>
#include "stm32f0xx.h"
#include "stm32f0xx_conf.h"
#define BLINK_DELAY_MS (500)
volatile uint32_t tickMs = 0;
void init() {
// ---------- SysTick timer -------- //
if (SysTick_Config(SystemCoreClock / 1000)) {
// Capture error
while (1){};
}
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_Init(GPIOA, &(GPIO_InitTypeDef){GPIO_Pin_15, GPIO_Mode_OUT, GPIO_Speed_2MHz, GPIO_OType_PP, GPIO_PuPd_NOPULL});
}
int main(void) {
uint32_t nextBlink;
uint32_t blinkState = 0;
init();
nextBlink = tickMs + BLINK_DELAY_MS;
for(;;) {
if(tickMs > nextBlink) {
nextBlink = tickMs + BLINK_DELAY_MS;
if(blinkState) {
GPIO_SetBits(GPIOA, GPIO_Pin_15);
} else {
GPIO_ResetBits(GPIOA, GPIO_Pin_15);
}
blinkState ^= 1;
}
__WFI();
}
return 0;
}
void SysTick_Handler(void)
{
tickMs++;
}