UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
tm4c_startup_gcc.c
1 //*****************************************************************************
2 //
3 // startup_gcc.c - Startup code for use with GNU tools.
4 //
5 // Copyright (c) 2011-2017 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Texas Instruments (TI) is supplying this software for use solely and
9 // exclusively on TI's microcontroller products. The software is owned by
10 // TI and/or its suppliers, and is protected under applicable copyright
11 // laws. You may not combine this software with "viral" open-source
12 // software in order to form a larger program.
13 //
14 // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
15 // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
16 // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
18 // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
19 // DAMAGES, FOR ANY REASON WHATSOEVER.
20 //
21 // This is part of revision 2.1.4.178 of the DK-TM4C123G Firmware Package.
22 //
23 //*****************************************************************************
24 
25 #include <stdint.h>
26 #include "inc/hw_nvic.h"
27 #include "inc/hw_types.h"
28 
29 //*****************************************************************************
30 //
31 // Forward declaration of the default fault handlers.
32 //
33 //*****************************************************************************
34 void ResetISR(void);
35 static void NmiSR(void);
36 static void FaultISR(void);
37 static void IntDefaultHandler(void);
38 
39 //*****************************************************************************
40 //
41 // The entry point for the application.
42 //
43 //*****************************************************************************
44 extern int main(void);
45 
46 //*****************************************************************************
47 //
48 // Reserve space for the system stack.
49 //
50 //*****************************************************************************
51 extern char *__StackTop;
52 
53 //*****************************************************************************
54 //
55 // The vector table. Note that the proper constructs must be placed on this to
56 // ensure that it ends up at physical address 0x0000.0000.
57 //
58 //*****************************************************************************
59 /* GCC Pedantic warning is suppressed here due to the stack pointer cast */
60 #pragma GCC diagnostic push // Save GCC Warnings state
61 #pragma GCC diagnostic ignored "-Wpedantic" // Disable pendantic flag
62 
63 __attribute__ ((section(".intvecs")))
64 void (* const g_pfnVectors[])(void) =
65 {
66  (void (*)(void))&__StackTop,
67  // The initial stack pointer
68  ResetISR, // The reset handler
69  NmiSR, // The NMI handler
70  FaultISR, // The hard fault handler
71  IntDefaultHandler, // The MPU fault handler
72  IntDefaultHandler, // The bus fault handler
73  IntDefaultHandler, // The usage fault handler
74  0, // Reserved
75  0, // Reserved
76  0, // Reserved
77  0, // Reserved
78  IntDefaultHandler, // SVCall handler
79  IntDefaultHandler, // Debug monitor handler
80  0, // Reserved
81  IntDefaultHandler, // The PendSV handler
82  IntDefaultHandler, // The SysTick handler
83  IntDefaultHandler, // GPIO Port A
84  IntDefaultHandler, // GPIO Port B
85  IntDefaultHandler, // GPIO Port C
86  IntDefaultHandler, // GPIO Port D
87  IntDefaultHandler, // GPIO Port E
88  IntDefaultHandler, // UART0 Rx and Tx
89  IntDefaultHandler, // UART1 Rx and Tx
90  IntDefaultHandler, // SSI0 Rx and Tx
91  IntDefaultHandler, // I2C0 Master and Slave
92  IntDefaultHandler, // PWM Fault
93  IntDefaultHandler, // PWM Generator 0
94  IntDefaultHandler, // PWM Generator 1
95  IntDefaultHandler, // PWM Generator 2
96  IntDefaultHandler, // Quadrature Encoder 0
97  IntDefaultHandler, // ADC Sequence 0
98  IntDefaultHandler, // ADC Sequence 1
99  IntDefaultHandler, // ADC Sequence 2
100  IntDefaultHandler, // ADC Sequence 3
101  IntDefaultHandler, // Watchdog timer
102  IntDefaultHandler, // Timer 0 subtimer A
103  IntDefaultHandler, // Timer 0 subtimer B
104  IntDefaultHandler, // Timer 1 subtimer A
105  IntDefaultHandler, // Timer 1 subtimer B
106  IntDefaultHandler, // Timer 2 subtimer A
107  IntDefaultHandler, // Timer 2 subtimer B
108  IntDefaultHandler, // Analog Comparator 0
109  IntDefaultHandler, // Analog Comparator 1
110  IntDefaultHandler, // Analog Comparator 2
111  IntDefaultHandler, // System Control (PLL, OSC, BO)
112  IntDefaultHandler, // FLASH Control
113  IntDefaultHandler, // GPIO Port F
114  IntDefaultHandler, // GPIO Port G
115  IntDefaultHandler, // GPIO Port H
116  IntDefaultHandler, // UART2 Rx and Tx
117  IntDefaultHandler, // SSI1 Rx and Tx
118  IntDefaultHandler, // Timer 3 subtimer A
119  IntDefaultHandler, // Timer 3 subtimer B
120  IntDefaultHandler, // I2C1 Master and Slave
121  IntDefaultHandler, // Quadrature Encoder 1
122  IntDefaultHandler, // CAN0
123  IntDefaultHandler, // CAN1
124  0, // Reserved
125  0, // Reserved
126  IntDefaultHandler, // Hibernate
127  IntDefaultHandler, // USB0
128  IntDefaultHandler, // PWM Generator 3
129  IntDefaultHandler, // uDMA Software Transfer
130  IntDefaultHandler, // uDMA Error
131  IntDefaultHandler, // ADC1 Sequence 0
132  IntDefaultHandler, // ADC1 Sequence 1
133  IntDefaultHandler, // ADC1 Sequence 2
134  IntDefaultHandler, // ADC1 Sequence 3
135  0, // Reserved
136  0, // Reserved
137  IntDefaultHandler, // GPIO Port J
138  IntDefaultHandler, // GPIO Port K
139  IntDefaultHandler, // GPIO Port L
140  IntDefaultHandler, // SSI2 Rx and Tx
141  IntDefaultHandler, // SSI3 Rx and Tx
142  IntDefaultHandler, // UART3 Rx and Tx
143  IntDefaultHandler, // UART4 Rx and Tx
144  IntDefaultHandler, // UART5 Rx and Tx
145  IntDefaultHandler, // UART6 Rx and Tx
146  IntDefaultHandler, // UART7 Rx and Tx
147  0, // Reserved
148  0, // Reserved
149  0, // Reserved
150  0, // Reserved
151  IntDefaultHandler, // I2C2 Master and Slave
152  IntDefaultHandler, // I2C3 Master and Slave
153  IntDefaultHandler, // Timer 4 subtimer A
154  IntDefaultHandler, // Timer 4 subtimer B
155  0, // Reserved
156  0, // Reserved
157  0, // Reserved
158  0, // Reserved
159  0, // Reserved
160  0, // Reserved
161  0, // Reserved
162  0, // Reserved
163  0, // Reserved
164  0, // Reserved
165  0, // Reserved
166  0, // Reserved
167  0, // Reserved
168  0, // Reserved
169  0, // Reserved
170  0, // Reserved
171  0, // Reserved
172  0, // Reserved
173  0, // Reserved
174  0, // Reserved
175  IntDefaultHandler, // Timer 5 subtimer A
176  IntDefaultHandler, // Timer 5 subtimer B
177  IntDefaultHandler, // Wide Timer 0 subtimer A
178  IntDefaultHandler, // Wide Timer 0 subtimer B
179  IntDefaultHandler, // Wide Timer 1 subtimer A
180  IntDefaultHandler, // Wide Timer 1 subtimer B
181  IntDefaultHandler, // Wide Timer 2 subtimer A
182  IntDefaultHandler, // Wide Timer 2 subtimer B
183  IntDefaultHandler, // Wide Timer 3 subtimer A
184  IntDefaultHandler, // Wide Timer 3 subtimer B
185  IntDefaultHandler, // Wide Timer 4 subtimer A
186  IntDefaultHandler, // Wide Timer 4 subtimer B
187  IntDefaultHandler, // Wide Timer 5 subtimer A
188  IntDefaultHandler, // Wide Timer 5 subtimer B
189  IntDefaultHandler, // FPU
190  0, // Reserved
191  0, // Reserved
192  IntDefaultHandler, // I2C4 Master and Slave
193  IntDefaultHandler, // I2C5 Master and Slave
194  IntDefaultHandler, // GPIO Port M
195  IntDefaultHandler, // GPIO Port N
196  IntDefaultHandler, // Quadrature Encoder 2
197  0, // Reserved
198  0, // Reserved
199  IntDefaultHandler, // GPIO Port P (Summary or P0)
200  IntDefaultHandler, // GPIO Port P1
201  IntDefaultHandler, // GPIO Port P2
202  IntDefaultHandler, // GPIO Port P3
203  IntDefaultHandler, // GPIO Port P4
204  IntDefaultHandler, // GPIO Port P5
205  IntDefaultHandler, // GPIO Port P6
206  IntDefaultHandler, // GPIO Port P7
207  IntDefaultHandler, // GPIO Port Q (Summary or Q0)
208  IntDefaultHandler, // GPIO Port Q1
209  IntDefaultHandler, // GPIO Port Q2
210  IntDefaultHandler, // GPIO Port Q3
211  IntDefaultHandler, // GPIO Port Q4
212  IntDefaultHandler, // GPIO Port Q5
213  IntDefaultHandler, // GPIO Port Q6
214  IntDefaultHandler, // GPIO Port Q7
215  IntDefaultHandler, // GPIO Port R
216  IntDefaultHandler, // GPIO Port S
217  IntDefaultHandler, // PWM 1 Generator 0
218  IntDefaultHandler, // PWM 1 Generator 1
219  IntDefaultHandler, // PWM 1 Generator 2
220  IntDefaultHandler, // PWM 1 Generator 3
221  IntDefaultHandler // PWM 1 Fault
222 };
223 
224 #pragma GCC diagnostic pop // Restore GCC Warnings state
225 
226 //*****************************************************************************
227 //
228 // The following are constructs created by the linker, indicating where the
229 // the "data" and "bss" segments reside in memory. The initializers for the
230 // for the "data" segment resides immediately following the "text" segment.
231 //
232 //*****************************************************************************
233 extern uint32_t __data_load__;
234 extern uint32_t __data_start__;
235 extern uint32_t __data_end__;
236 extern uint32_t __bss_start__;
237 extern uint32_t __bss_end__;
238 
239 //*****************************************************************************
240 //
241 // This is the code that gets called when the processor first starts execution
242 // following a reset event. Only the absolutely necessary set is performed,
243 // after which the application supplied entry() routine is called. Any fancy
244 // actions (such as making decisions based on the reset cause register, and
245 // resetting the bits in that register) are left solely in the hands of the
246 // application.
247 //
248 //*****************************************************************************
249 void
250 ResetISR(void)
251 {
252  uint32_t *pui32Src, *pui32Dest;
253 
254  //
255  // Copy the data segment initializers from flash to SRAM.
256  //
257  pui32Src = &__data_load__;
258  for(pui32Dest = &__data_start__; pui32Dest < &__data_end__; )
259  {
260  *pui32Dest++ = *pui32Src++;
261  }
262 
263  //
264  // Zero fill the bss segment.
265  //
266  __asm(" ldr r0, =__bss_start__\n"
267  " ldr r1, =__bss_end__\n"
268  " mov r2, #0\n"
269  " .thumb_func\n"
270  "zero_loop:\n"
271  " cmp r0, r1\n"
272  " it lt\n"
273  " strlt r2, [r0], #4\n"
274  " blt zero_loop");
275 
276  //
277  // Enable the floating-point unit. This must be done here to handle the
278  // case where main() uses floating-point and the function prologue saves
279  // floating-point registers (which will fault if floating-point is not
280  // enabled). Any configuration of the floating-point unit using DriverLib
281  // APIs must be done here prior to the floating-point unit being enabled.
282  //
283  // Note that this does not use DriverLib since it might not be included in
284  // this project.
285  //
286  HWREG(NVIC_CPAC) = ((HWREG(NVIC_CPAC) &
287  (uint32_t)~(NVIC_CPAC_CP10_M | NVIC_CPAC_CP11_M)) |
288  NVIC_CPAC_CP10_FULL | NVIC_CPAC_CP11_FULL);
289 
290  //
291  // Call the application's entry point.
292  //
293  main();
294 }
295 
296 //*****************************************************************************
297 //
298 // This is the code that gets called when the processor receives a NMI. This
299 // simply enters an infinite loop, preserving the system state for examination
300 // by a debugger.
301 //
302 //*****************************************************************************
303 static void
304 NmiSR(void)
305 {
306  //
307  // Enter an infinite loop.
308  //
309  while(1)
310  {
311  }
312 }
313 
314 //*****************************************************************************
315 //
316 // This is the code that gets called when the processor receives a fault
317 // interrupt. This simply enters an infinite loop, preserving the system state
318 // for examination by a debugger.
319 //
320 //*****************************************************************************
321 static void
322 FaultISR(void)
323 {
324  //
325  // Enter an infinite loop.
326  //
327  while(1)
328  {
329  }
330 }
331 
332 //*****************************************************************************
333 //
334 // This is the code that gets called when the processor receives an unexpected
335 // interrupt. This simply enters an infinite loop, preserving the system state
336 // for examination by a debugger.
337 //
338 //*****************************************************************************
339 static void
340 IntDefaultHandler(void)
341 {
342  //
343  // Go into an infinite loop.
344  //
345  while(1)
346  {
347  }
348 }
int main(void)
Runs all module tests.
Definition: test.c:19