-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathinit.c
71 lines (57 loc) · 1.88 KB
/
init.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
// Based on libopencm3 project.
#include <stdint.h>
extern unsigned _data_loadaddr, _data, _edata, _ebss, _stack;
typedef void (*vector_table_entry_t)(void);
typedef struct {
unsigned int *initial_sp_value; /**< Initial stack pointer value. */
vector_table_entry_t reset;
vector_table_entry_t nmi;
vector_table_entry_t hard_fault;
vector_table_entry_t memory_manage_fault; /* not in CM0 */
vector_table_entry_t bus_fault; /* not in CM0 */
vector_table_entry_t usage_fault; /* not in CM0 */
vector_table_entry_t reserved_x001c[4];
vector_table_entry_t sv_call;
vector_table_entry_t debug_monitor; /* not in CM0 */
vector_table_entry_t reserved_x0034;
vector_table_entry_t pend_sv;
vector_table_entry_t systick;
} vector_table_t;
// A handler that does nothing, we use no interrupts
void null_handler(void) {
while (1);
}
/* Less common symbols exported by the linker script(s): */
typedef void (*funcp_t) (void);
void main(void);
void __attribute__ ((naked)) reset_handler(void) {
volatile unsigned *src, *dest;
for (src = &_data_loadaddr, dest = &_data;
dest < &_edata;
src++, dest++) {
*dest = *src;
}
while (dest < &_ebss)
*dest++ = 0;
/* Ensure 8-byte alignment of stack pointer on interrupts */
/* Enabled by default on most Cortex-M parts, but not M3 r1 */
volatile uint32_t *_scb_ccr = (uint32_t*)0xE000ED14U;
*_scb_ccr |= (1 << 9);
/* Call the application's entry point. */
main();
}
// Vector table (bare minimal one)
__attribute__ ((section(".vectors")))
vector_table_t vector_table = {
.initial_sp_value = &_stack,
.reset = reset_handler,
.nmi = null_handler,
.hard_fault = null_handler,
.memory_manage_fault = null_handler,
.bus_fault = null_handler,
.usage_fault = null_handler,
.debug_monitor = null_handler,
.sv_call = null_handler,
.pend_sv = null_handler,
.systick = null_handler,
};