-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
85 lines (83 loc) · 2.56 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
void init(void);
void Default_Handler(void);
extern void ADC_Handler(void); //added
extern void EXTI_Handler(void); //added
extern int main(void); //added
// The following are 'declared' in the linker script
extern unsigned char INIT_DATA_VALUES;
extern unsigned char INIT_DATA_START;
extern unsigned char INIT_DATA_END;
extern unsigned char BSS_START;
extern unsigned char BSS_END;
// the section "vectors" is placed at the beginning of flash
// by the linker script
const void * Vectors[] __attribute__((section(".vectors"))) ={
(void *)0x20001000, /* Top of stack (4k) */
init, /* Reset Handler */
Default_Handler, /* NMI */
Default_Handler, /* Hard Fault */
Default_Handler, /* MemManage */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
Default_Handler, /* SVCall */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
Default_Handler, /* PendSV */
Default_Handler, /* SysTick */
/* External interrupt handlers follow */
Default_Handler, /* 0: WWDG */
Default_Handler, /* 1: Reserved */
Default_Handler, /* 2: RTC */
Default_Handler, /* 3: FLASH */
Default_Handler, /* 4: RCC */
Default_Handler, /* 5: EXTI0_1 */
Default_Handler, /* 6: EXTI2_3 */
Default_Handler , /* 7: EXTI4_15 */
Default_Handler, /* 8: Reserved */
Default_Handler, /* 9: DMA_CH1 */
Default_Handler, /* 10: DMA_CH2_3 */
Default_Handler, /* 11: DMA_CH4_5 */
ADC_Handler, /* 12: ADC */ // changed to own handler.
Default_Handler, /* 13: TIM1_BRK_UP_TRG_COM */
Default_Handler, /* 14: TIM1_CC */
Default_Handler, /* 15: Reserved */
Default_Handler, /* 16: TIM3 */
Default_Handler, /* 17: Reserved */
Default_Handler, /* 18: Reserved */
Default_Handler, /* 19: TIM14 */
Default_Handler, /* 20: TIM15 */
Default_Handler, /* 21: TIM16 */
Default_Handler, /* 22: TIM17 */
Default_Handler, /* 23: I2C1 */
Default_Handler, /* 24: I2C2 */
Default_Handler, /* 25: SPI1 */
Default_Handler, /* 26: SPI2 */
Default_Handler, /* 27: USART1 */
Default_Handler /* 28: USART2 */
};
void init()
{
// do global/static data initialization
unsigned char *src;
unsigned char *dest;
unsigned len;
src= &INIT_DATA_VALUES;
dest= &INIT_DATA_START;
len= &INIT_DATA_END-&INIT_DATA_START;
while (len--)
*dest++ = *src++;
// zero out the uninitialized global/static variables
dest = &BSS_START;
len = &BSS_END - &BSS_START;
while (len--)
*dest++=0;
main();
}
void Default_Handler()
{
while(1);
}