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