-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
72 lines (61 loc) · 1.54 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* @file - main.c
* @author - Harlan James <root@aboyandhisgnu.org>
* @description - Quick and dirt light blinkage from scratch for the
* STM32F4(07VG) Discovery board.
*/
#include <stdint.h>
#define DELAY 0xEFFFF
/**
* @Register Definitions - Register addresses
*/
#define RCC_AHB1ENR (*(volatile uint32_t *)0x40023830)
#define GPIOD_MODER (*(volatile uint32_t *)0x40020C00)
#define GPIOD_ODR (*(volatile uint32_t *)0x40020C14)
/**
* @Register Bits - The following values are used to configure the GPIO
* registers.
*
* @see - http://www.hertaville.com/stm32f0-gpio-tutorial-part-1.html
* @seealso - RM0090 (reference manual, contains register maps)
*/
#define GPIO_MODE_OUT (1 << 3)
#define PIN_12_OUTPUT (1 << 24)
#define PIN_13_OUTPUT (1 << 26)
#define PIN_14_OUTPUT (1 << 28)
#define PIN_15_OUTPUT (1 << 30)
#define LED_GREEN (1 << 12)
#define LED_ORANGE (1 << 13)
#define LED_RED (1 << 14)
#define LED_BLUE (1 << 15)
/**
* @blink_light - Blinks the light for based on the DELAY
*
* @param led - the light to blink
*/
void blink_light(uint16_t led)
{
uint32_t i;
/* ON */
GPIOD_ODR |= led;
for (i = 0; i < DELAY; i++);
/* OFF */
GPIOD_ODR &= ~led;
for (i = 0; i < DELAY; i++);
}
/**
* @main - Main entry point for the program. Turns a light on and off!
*/
int main(void)
{
RCC_AHB1ENR |= GPIO_MODE_OUT;
GPIOD_MODER = (PIN_12_OUTPUT) | (PIN_13_OUTPUT) | (PIN_14_OUTPUT) |
(PIN_15_OUTPUT);
for (;;)
{
blink_light(LED_GREEN);
blink_light(LED_ORANGE);
blink_light(LED_RED);
blink_light(LED_BLUE);
}
}