-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
66 lines (54 loc) · 1.33 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
typedef unsigned int uint32_t;
#define RRC_AHB1ENR (*(volatile uint32_t *) 0x40023830)
#define GPIOD_BASE (0x40020C00)
#define GPIOD_MODER (*(volatile uint32_t *) (GPIOD_BASE + 0x00))
#define GPIOD_ODR (*(volatile uint32_t *) (GPIOD_BASE + 0x14))
#define LED_PATTERN (1<<15 | 1<<14 | 1<<13 | 1<<12)
/* ram addresses, 4-byte aligned */
extern uint32_t _sstack, _estack;
extern uint32_t _sdata_ram, _edata_ram;
extern uint32_t _sbss, _ebss;
/* rom addresses, 4-byte aligned */
extern uint32_t _svector, _evector;
extern uint32_t _sdata_rom, _edata_rom;
void main(void)
{
uint32_t *src, *dst;
/* copy data section to ram */
src = &_sdata_rom;
dst = &_sdata_ram;
while (dst < &_edata_ram) {
*dst++ = *src++;
}
/* zero out bss section in ram */
dst = &_sbss;
while (dst < &_ebss) {
*dst++ = 0;
}
/* enable gpio PORTD clock */
RRC_AHB1ENR |= 1<<3;
/* set gpios D12-D15 as output */
GPIOD_MODER |= 1<<30 | 1<<28 | 1<<26 | 1<<24;
/* set gpios D12-D15 high */
GPIOD_ODR |= LED_PATTERN;
for (;;) {
for (int i = 0; i < 1000000; i++) {
asm("nop");
}
GPIOD_ODR ^= LED_PATTERN;
}
}
void nmi_handler(void)
{
for (;;);
}
void hardfault_handler(void)
{
for (;;);
}
uint32_t *vectors[] __attribute__ ((section("vector_table")))= {
(uint32_t *) &_estack,
(uint32_t *) main,
(uint32_t *) nmi_handler,
(uint32_t *) hardfault_handler
};