1 //*****************************************************************************
3 // startup_gcc.c - Startup code for use with GNU tools.
5 // Copyright (c) 2009 Luminary Micro, Inc. All rights reserved.
6 // Software License Agreement
8 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
9 // exclusively on LMI's microcontroller products.
11 // The software is owned by LMI and/or its suppliers, and is protected under
12 // applicable copyright laws. All rights are reserved. You may not combine
13 // this software with "viral" open-source software in order to form a larger
14 // program. Any use in violation of the foregoing restrictions may subject
15 // the user to criminal sanctions under applicable laws, as well as to civil
16 // liability for the breach of the terms and conditions of this license.
18 // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
22 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
24 // This is part of revision 32 of the Stellaris CMSIS Package.
26 //*****************************************************************************
28 #define WEAK __attribute__ ((weak))
30 //*****************************************************************************
32 // Forward declaration of the default fault handlers.
34 //*****************************************************************************
35 void WEAK Reset_Handler(void);
36 static void Default_Handler(void);
37 void WEAK NMI_Handler(void);
38 void WEAK HardFault_Handler(void);
39 void WEAK MemManage_Handler(void);
40 void WEAK BusFault_Handler(void);
41 void WEAK UsageFault_Handler(void);
42 void WEAK MemManage_Handler(void);
43 void WEAK SVC_Handler(void);
44 void WEAK DebugMon_Handler(void);
45 void WEAK PendSV_Handler(void);
46 void WEAK SysTick_Handler(void);
48 void WEAK WDT_IRQHandler(void);
49 void WEAK TIMER0_IRQHandler(void);
50 void WEAK TIMER1_IRQHandler(void);
51 void WEAK TIMER2_IRQHandler(void);
52 void WEAK TIMER3_IRQHandler(void);
53 void WEAK UART0_IRQHandler(void);
54 void WEAK UART1_IRQHandler(void);
55 void WEAK UART2_IRQHandler(void);
56 void WEAK UART3_IRQHandler(void);
57 void WEAK PWM1_IRQHandler(void);
58 void WEAK I2C0_IRQHandler(void);
59 void WEAK I2C1_IRQHandler(void);
60 void WEAK I2C2_IRQHandler(void);
61 void WEAK SPI_IRQHandler(void);
62 void WEAK SSP0_IRQHandler(void);
63 void WEAK SSP1_IRQHandler(void);
64 void WEAK PLL0_IRQHandler(void);
65 void WEAK RTC_IRQHandler(void);
66 void WEAK EINT0_IRQHandler(void);
67 void WEAK EINT1_IRQHandler(void);
68 void WEAK EINT2_IRQHandler(void);
69 void WEAK EINT3_IRQHandler(void);
70 void WEAK ADC_IRQHandler(void);
71 void WEAK BOD_IRQHandler(void);
72 void WEAK USB_IRQHandler(void);
73 void WEAK CAN_IRQHandler(void);
74 void WEAK DMA_IRQHandler(void);
75 void WEAK I2S_IRQHandler(void);
76 void WEAK ENET_IRQHandler(void);
77 void WEAK RIT_IRQHandler(void);
78 void WEAK MCPWM_IRQHandler(void);
79 void WEAK QEI_IRQHandler(void);
80 void WEAK PLL1_IRQHandler(void);
81 void WEAK USBActivity_IRQHandler(void);
82 void WEAK CANActivity_IRQHandler(void);
84 //*****************************************************************************
86 // The entry point for the application.
88 //*****************************************************************************
89 extern int main(void);
91 //*****************************************************************************
93 // Reserve space for the system stack.
95 //*****************************************************************************
96 static unsigned long pulStack[64];
98 //*****************************************************************************
100 // The vector table. Note that the proper constructs must be placed on this to
101 // ensure that it ends up at physical address 0x0000.0000.
103 //*****************************************************************************
104 __attribute__ ((section(".isr_vector")))
105 void (* const g_pfnVectors[])(void) =
107 (void (*)(void))((unsigned long)pulStack + sizeof(pulStack)),
108 // The initial stack pointer
109 Reset_Handler, // The reset handler
110 NMI_Handler, // The NMI handler
111 HardFault_Handler, // The hard fault handler
112 MemManage_Handler, // The MPU fault handler
113 BusFault_Handler, // The bus fault handler
114 UsageFault_Handler, // The usage fault handler
115 0xeffffcbf, // Interrupt CRC
119 SVC_Handler, // SVCall handler
120 DebugMon_Handler, // Debug monitor handler
122 PendSV_Handler, // The PendSV handler
123 SysTick_Handler, // The SysTick handler
126 // External Interrupts
128 WDT_IRQHandler, /* 16: Watchdog Timer */
129 TIMER0_IRQHandler, /* 17: Timer0 */
130 TIMER1_IRQHandler, /* 18: Timer1 */
131 TIMER2_IRQHandler, /* 19: Timer2 */
132 TIMER3_IRQHandler, /* 20: Timer3 */
133 UART0_IRQHandler, /* 21: UART0 */
134 UART1_IRQHandler, /* 22: UART1 */
135 UART2_IRQHandler, /* 23: UART2 */
136 UART3_IRQHandler, /* 24: UART3 */
137 PWM1_IRQHandler, /* 25: PWM1 */
138 I2C0_IRQHandler, /* 26: I2C0 */
139 I2C1_IRQHandler, /* 27: I2C1 */
140 I2C2_IRQHandler, /* 28: I2C2 */
141 SPI_IRQHandler, /* 29: SPI */
142 SSP0_IRQHandler, /* 30: SSP0 */
143 SSP1_IRQHandler, /* 31: SSP1 */
144 PLL0_IRQHandler, /* 32: PLL0 Lock (Main PLL) */
145 RTC_IRQHandler, /* 33: Real Time Clock */
146 EINT0_IRQHandler, /* 34: External Interrupt 0 */
147 EINT1_IRQHandler, /* 35: External Interrupt 1 */
148 EINT2_IRQHandler, /* 36: External Interrupt 2 */
149 EINT3_IRQHandler, /* 37: External Interrupt 3 */
150 ADC_IRQHandler, /* 38: A/D Converter */
151 BOD_IRQHandler, /* 39: Brown-Out Detect */
152 USB_IRQHandler, /* 40: USB */
153 CAN_IRQHandler, /* 41: CAN */
154 DMA_IRQHandler, /* 42: General Purpose DMA */
155 I2S_IRQHandler, /* 43: I2S */
156 ENET_IRQHandler, /* 44: Ethernet */
157 RIT_IRQHandler, /* 45: Repetitive Interrupt Timer */
158 MCPWM_IRQHandler, /* 46: Motor Control PWM */
159 QEI_IRQHandler, /* 47: Quadrature Encoder Interface */
160 PLL1_IRQHandler, /* 48: PLL1 Lock (USB PLL) */
161 USBActivity_IRQHandler, /* 49: USB Activity interrupt to wakeup */
162 CANActivity_IRQHandler /* 50: CAN Activity interrupt to wakeup */
165 //*****************************************************************************
167 // The following are constructs created by the linker, indicating where the
168 // the "data" and "bss" segments reside in memory. The initializers for the
169 // for the "data" segment resides immediately following the "text" segment.
171 //*****************************************************************************
172 extern unsigned long _etext;
173 extern unsigned long _sdata;
174 extern unsigned long _edata;
175 extern unsigned long _sbss;
176 extern unsigned long _ebss;
178 //*****************************************************************************
180 // This is the code that gets called when the processor first starts execution
181 // following a reset event. Only the absolutely necessary set is performed,
182 // after which the application supplied entry() routine is called. Any fancy
183 // actions (such as making decisions based on the reset cause register, and
184 // resetting the bits in that register) are left solely in the hands of the
187 //*****************************************************************************
191 unsigned long *pulSrc, *pulDest;
194 // Copy the data segment initializers from flash to SRAM.
197 for(pulDest = &_sdata; pulDest < &_edata; )
199 *pulDest++ = *pulSrc++;
203 // Zero fill the bss segment. This is done with inline assembly since this
204 // will clear the value of pulDest if it is not kept in a register.
206 __asm(" ldr r0, =_sbss\n"
213 " strlt r2, [r0], #4\n"
217 // Call the application's entry point.
222 //*****************************************************************************
224 // Provide weak aliases for each Exception handler to the Default_Handler.
225 // As they are weak aliases, any function with the same name will override
228 //*****************************************************************************
229 #pragma weak WDT_IRQHandler = Default_Handler
230 #pragma weak TIMER0_IRQHandler = Default_Handler
231 #pragma weak TIMER1_IRQHandler = Default_Handler
232 #pragma weak TIMER2_IRQHandler = Default_Handler
233 #pragma weak TIMER3_IRQHandler = Default_Handler
234 #pragma weak UART0_IRQHandler = Default_Handler
235 #pragma weak UART1_IRQHandler = Default_Handler
236 #pragma weak UART2_IRQHandler = Default_Handler
237 #pragma weak UART3_IRQHandler = Default_Handler
238 #pragma weak PWM1_IRQHandler = Default_Handler
239 #pragma weak I2C0_IRQHandler = Default_Handler
240 #pragma weak I2C1_IRQHandler = Default_Handler
241 #pragma weak I2C2_IRQHandler = Default_Handler
242 #pragma weak SPI_IRQHandler = Default_Handler
243 #pragma weak SSP0_IRQHandler = Default_Handler
244 #pragma weak SSP1_IRQHandler = Default_Handler
245 #pragma weak PLL0_IRQHandler = Default_Handler
246 #pragma weak RTC_IRQHandler = Default_Handler
247 #pragma weak EINT0_IRQHandler = Default_Handler
248 #pragma weak EINT1_IRQHandler = Default_Handler
249 #pragma weak EINT2_IRQHandler = Default_Handler
250 #pragma weak EINT3_IRQHandler = Default_Handler
251 #pragma weak ADC_IRQHandler = Default_Handler
252 #pragma weak BOD_IRQHandler = Default_Handler
253 #pragma weak USB_IRQHandler = Default_Handler
254 #pragma weak CAN_IRQHandler = Default_Handler
255 #pragma weak DMA_IRQHandler = Default_Handler
256 #pragma weak I2S_IRQHandler = Default_Handler
257 #pragma weak ENET_IRQHandler = Default_Handler
258 #pragma weak RIT_IRQHandler = Default_Handler
259 #pragma weak MCPWM_IRQHandler = Default_Handler
260 #pragma weak QEI_IRQHandler = Default_Handler
261 #pragma weak PPL1_IRQHandler = Default_Handler
262 #pragma weak USBActivity_IRQHandler = Default_Handler
263 #pragma weak CANActivity_IRQHandler = Default_Handler
265 //*****************************************************************************
267 // This is the code that gets called when the processor receives an unexpected
268 // interrupt. This simply enters an infinite loop, preserving the system state
269 // for examination by a debugger.
271 //*****************************************************************************
273 Default_Handler(void)
276 // Go into an infinite loop.