forked from spbnick/stm32-poke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blink.c
49 lines (42 loc) · 1.18 KB
/
blink.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
#include "rcc.h"
#include "gpio.h"
#include "init.h"
#include "stk.h"
#define STOP \
do { \
asm ("wfi"); \
} while (1)
void systick_handler(void) __attribute__ ((isr));
void
systick_handler(void)
{
/* Toggle the LED */
GPIO_C->odr ^= GPIO_ODR_ODR13_MASK;
}
int main(void)
{
/* Basic init */
init();
/*
* Enable I/O ports
*/
/* Enable APB2 clock to I/O port C */
RCC->apb2enr |= RCC_APB2ENR_IOPCEN_MASK;
/*
* Enable LED output
*/
/* Set PC13 to general purpose open-drain output, max speed 2MHz */
GPIO_C->crh = (GPIO_C->crh & (~GPIO_CRH_MODE13_MASK) & (~GPIO_CRH_CNF13_MASK)) |
(GPIO_MODE_OUTPUT_2MHZ << GPIO_CRH_MODE13_LSB) |
(GPIO_CNF_OUTPUT_GP_OPEN_DRAIN << GPIO_CRH_CNF13_LSB);
/*
* Set SysTick timer to fire the interrupt each half-second.
* NOTE the ST PM0056 says: "When HCLK is programmed at the maximum
* frequency, the SysTick period is 1ms."
*/
STK->val = STK->load =
(((STK->calib & STK_CALIB_TENMS_MASK) >> STK_CALIB_TENMS_LSB) + 1) *
500 - 1;
STK->ctrl |= STK_CTRL_ENABLE_MASK | STK_CTRL_TICKINT_MASK;
STOP;
}