xref: /btstack/port/msp432p401lp-cc256x/startup_msp432p401r_gcc.c (revision f7529f1d2431b7f584bf8a875d1f2c4baaa3134c)
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v3_10_00_09
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2014, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
17  * *  Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * *  Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  * --/COPYRIGHT--*/
37 //*****************************************************************************
38 //
39 // Copyright (C) 2012 - 2015 Texas Instruments Incorporated - http://www.ti.com/
40 //
41 // Redistribution and use in source and binary forms, with or without
42 // modification, are permitted provided that the following conditions
43 // are met:
44 //
45 //  Redistributions of source code must retain the above copyright
46 //  notice, this list of conditions and the following disclaimer.
47 //
48 //  Redistributions in binary form must reproduce the above copyright
49 //  notice, this list of conditions and the following disclaimer in the
50 //  documentation and/or other materials provided with the
51 //  distribution.
52 //
53 //  Neither the name of Texas Instruments Incorporated nor the names of
54 //  its contributors may be used to endorse or promote products derived
55 //  from this software without specific prior written permission.
56 //
57 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
58 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
59 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
60 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
61 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
63 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
67 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 //
69 // MSP432 Family Interrupt Vector Table for GCC
70 //
71 //****************************************************************************
72 
73 #include <stdint.h>
74 
75 /* Forward declaration of the default fault handlers. */
76 static void resetISR(void);
77 static void nmiISR(void);
78 static void faultISR(void);
79 static void defaultISR(void);
80 
81 #ifndef HWREG
82 #define HWREG(x) (*((volatile uint32_t *)(x)))
83 #endif
84 
85 /* system initialization funtion */
86 extern void SystemInit(void);
87 
88 /* Entry point for the application. */
89 extern int main(void);
90 
91 /* External declarations for the interrupt handlers used by the application. */
92 /* To be added by the user */
93 extern void EUSCIA2_IRQHandler(void);
94 
95 /* To be added by the user */
96 extern void SysTick_Handler(void);
97 
98 /* Interrupt vector table.  Note that the proper constructs must be placed on this to */
99 /* ensure that it ends up at physical address 0x0000.0000 or at the start of          */
100 /* the program if located at a start address other than 0.                            */
101 void (* const interruptVectors[])(void) __attribute__ ((section (".intvecs"))) =
102 {
103     (void (*)(void))((uint32_t)0x20004000),
104                                             /* The initial stack pointer */
105     resetISR,                               /* The reset handler         */
106     nmiISR,                                 /* The NMI handler           */
107     faultISR,                               /* The hard fault handler    */
108     defaultISR,                             /* The MPU fault handler     */
109     defaultISR,                             /* The bus fault handler     */
110     defaultISR,                             /* The usage fault handler   */
111     0,                                      /* Reserved                  */
112     0,                                      /* Reserved                  */
113     0,                                      /* Reserved                  */
114     0,                                      /* Reserved                  */
115     defaultISR,                             /* SVCall handler            */
116     defaultISR,                             /* Debug monitor handler     */
117     0,                                      /* Reserved                  */
118     defaultISR,                             /* The PendSV handler        */
119     SysTick_Handler,                        /* The SysTick handler       */
120     defaultISR,                             /* PSS ISR                   */
121     defaultISR,                             /* CS ISR                    */
122     defaultISR,                             /* PCM ISR                   */
123     defaultISR,                             /* WDT ISR                   */
124     defaultISR,                             /* FPU ISR                   */
125     defaultISR,                             /* FLCTL ISR                 */
126     defaultISR,                             /* COMP0 ISR                 */
127     defaultISR,                             /* COMP1 ISR                 */
128     defaultISR,                             /* TA0_0 ISR                 */
129     defaultISR,                             /* TA0_N ISR                 */
130     defaultISR,                             /* TA1_0 ISR                 */
131     defaultISR,                             /* TA1_N ISR                 */
132     defaultISR,                             /* TA2_0 ISR                 */
133     defaultISR,                             /* TA2_N ISR                 */
134     defaultISR,                             /* TA3_0 ISR                 */
135     defaultISR,                             /* TA3_N ISR                 */
136     defaultISR,                             /* EUSCIA0 ISR               */
137     defaultISR,                             /* EUSCIA1 ISR               */
138     EUSCIA2_IRQHandler,                     /* EUSCIA2 ISR               */
139     defaultISR,                             /* EUSCIA3 ISR               */
140     defaultISR,                             /* EUSCIB0 ISR               */
141     defaultISR,                             /* EUSCIB1 ISR               */
142     defaultISR,                             /* EUSCIB2 ISR               */
143     defaultISR,                             /* EUSCIB3 ISR               */
144     defaultISR,                             /* ADC14 ISR                 */
145     defaultISR,                             /* T32_INT1 ISR              */
146     defaultISR,                             /* T32_INT2 ISR              */
147     defaultISR,                             /* T32_INTC ISR              */
148     defaultISR,                             /* AES ISR                   */
149     defaultISR,                             /* RTC ISR                   */
150     defaultISR,                             /* DMA_ERR ISR               */
151     defaultISR,                             /* DMA_INT3 ISR              */
152     defaultISR,                             /* DMA_INT2 ISR              */
153     defaultISR,                             /* DMA_INT1 ISR              */
154     defaultISR,                             /* DMA_INT0 ISR              */
155     defaultISR,                             /* PORT1 ISR                 */
156     defaultISR,                             /* PORT2 ISR                 */
157     defaultISR,                             /* PORT3 ISR                 */
158     defaultISR,                             /* PORT4 ISR                 */
159     defaultISR,                             /* PORT5 ISR                 */
160     defaultISR,                             /* PORT6 ISR                 */
161     defaultISR,                             /* Reserved 41               */
162     defaultISR,                             /* Reserved 42               */
163     defaultISR,                             /* Reserved 43               */
164     defaultISR,                             /* Reserved 44               */
165     defaultISR,                             /* Reserved 45               */
166     defaultISR,                             /* Reserved 46               */
167     defaultISR,                             /* Reserved 47               */
168     defaultISR,                             /* Reserved 48               */
169     defaultISR,                             /* Reserved 49               */
170     defaultISR,                             /* Reserved 50               */
171     defaultISR,                             /* Reserved 51               */
172     defaultISR,                             /* Reserved 52               */
173     defaultISR,                             /* Reserved 53               */
174     defaultISR,                             /* Reserved 54               */
175     defaultISR,                             /* Reserved 55               */
176     defaultISR,                             /* Reserved 56               */
177     defaultISR,                             /* Reserved 57               */
178     defaultISR,                             /* Reserved 58               */
179     defaultISR,                             /* Reserved 59               */
180     defaultISR,                             /* Reserved 60               */
181     defaultISR,                             /* Reserved 61               */
182     defaultISR,                             /* Reserved 62               */
183     defaultISR                              /* Reserved 63               */
184 };
185 
186 /* This is the code that gets called when the processor first starts execution */
187 /* following a reset event.  Only the absolutely necessary set is performed,   */
188 /* after which the application supplied entry() routine is called.  Any fancy  */
189 /* actions (such as making decisions based on the reset cause register, and    */
190 /* resetting the bits in that register) are left solely in the hands of the    */
191 /* application.                                                                */
192 extern uint32_t __data_load__;
193 extern uint32_t __data_start__;
194 extern uint32_t __data_end__;
195 
196 void resetISR(void)
197 {
198     /* Copy the data segment initializers from flash to SRAM. */
199     uint32_t *pui32Src, *pui32Dest;
200 
201     pui32Src = &__data_load__;
202     for(pui32Dest = &__data_start__; pui32Dest < &__data_end__; )
203     {
204         *pui32Dest++ = *pui32Src++;
205     }
206 
207     /* Zero fill the bss segment. */
208     __asm("    ldr     r0, =__bss_start__\n"
209           "    ldr     r1, =__bss_end__\n"
210           "    mov     r2, #0\n"
211           "    .thumb_func\n"
212           "zero_loop:\n"
213           "        cmp     r0, r1\n"
214           "        it      lt\n"
215           "        strlt   r2, [r0], #4\n"
216           "        blt     zero_loop");
217 
218     /* Call system initialization routine */
219   SystemInit();
220 
221     /* Call the application's entry point. */
222     main();
223 }
224 
225 
226 /* This is the code that gets called when the processor receives a NMI.  This  */
227 /* simply enters an infinite loop, preserving the system state for examination */
228 /* by a debugger.                                                              */
229 static void nmiISR(void)
230 {
231     /* Enter an infinite loop. */
232     while(1)
233     {
234     }
235 }
236 
237 
238 /* This is the code that gets called when the processor receives a fault        */
239 /* interrupt.  This simply enters an infinite loop, preserving the system state */
240 /* for examination by a debugger.                                               */
241 static void faultISR(void)
242 {
243     /* Enter an infinite loop. */
244     while(1)
245     {
246     }
247 }
248 
249 
250 /* This is the code that gets called when the processor receives an unexpected  */
251 /* interrupt.  This simply enters an infinite loop, preserving the system state */
252 /* for examination by a debugger.                                               */
253 static void defaultISR(void)
254 {
255     /* Enter an infinite loop. */
256     while(1)
257     {
258     }
259 }
260