ADuCM302x Device Drivers API Reference Manual  Release 3.1.2.0
startup_ADuCM3029.c
1 /* File: startup_ADuCM3029.c
2  * Startup file for Analog Devices ADuCM3029 processor
3  *
4  * Based on startup_ARMCM3.c
5  *
6  */
7 /* Copyright (c) 2011 - 2014 ARM LIMITED
8  Portions Copyright (c) 2016 - 2018 Analog Devices, Inc.
9 
10  All rights reserved.
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are met:
13  - Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15  - Redistributions in binary form must reproduce the above copyright
16  notice, this list of conditions and the following disclaimer in the
17  documentation and/or other materials provided with the distribution.
18  - Neither the name of ARM nor the names of its contributors may be used
19  to endorse or promote products derived from this software without
20  specific prior written permission.
21  *
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  POSSIBILITY OF SUCH DAMAGE.
33  ---------------------------------------------------------------------------*/
34 
35 #include <stdint.h>
36 #include <rtos_map/adi_rtos_map.h>
37 
38 /*----------------------------------------------------------------------------
39  Linker generated Symbols
40  *----------------------------------------------------------------------------*/
41 extern uint32_t __etext;
42 extern uint32_t __data_start__;
43 extern uint32_t __data_end__;
44 extern uint32_t __copy_table_start__;
45 extern uint32_t __copy_table_end__;
46 extern uint32_t __zero_table_start__;
47 extern uint32_t __zero_table_end__;
48 extern uint32_t __bss_start__;
49 extern uint32_t __bss_end__;
50 extern uint32_t __StackTop;
51 
52 /*----------------------------------------------------------------------------
53  Exception / Interrupt Handler Function Prototype
54  *----------------------------------------------------------------------------*/
55 typedef void( *pFunc )( void );
56 
57 
58 /*----------------------------------------------------------------------------
59  External References
60  *----------------------------------------------------------------------------*/
61 #ifndef __START
62 extern void _start(void) __attribute__((noreturn)); /* PreeMain (C library entry point) */
63 #else
64 extern int __START(void) __attribute__((noreturn)); /* main entry point */
65 #endif
66 
67 #ifndef __NO_SYSTEM_INIT
68 extern void SystemInit (void); /* CMSIS System Initialization */
69 #endif
70 
71 
72 /*----------------------------------------------------------------------------
73  Internal References
74  *----------------------------------------------------------------------------*/
75 void Default_Handler(void); /* Default empty handler */
76 
77 
78 /*----------------------------------------------------------------------------
79  User Initial Stack & Heap
80  *----------------------------------------------------------------------------*/
81 #ifndef __STACK_SIZE
82  #define __STACK_SIZE 0x00000400
83 #endif
84 static uint8_t stack[__STACK_SIZE] __attribute__ ((aligned(8), used, section(".stack")));
85 
86 #ifndef __HEAP_SIZE
87  #define __HEAP_SIZE 0x00000C00
88 #endif
89 #if __HEAP_SIZE > 0
90 static uint8_t heap[__HEAP_SIZE] __attribute__ ((aligned(8), used, section(".heap")));
91 #endif
92 
93 /*----------------------------------------------------------------------------
94  Exception / Interrupt Handler
95  *----------------------------------------------------------------------------*/
96 /* Cortex-M3 Processor Exceptions */
97 void Reset_Handler (void) __attribute__ ((weak, alias("Reset_Handler_C")));
98 void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
99 void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
100 void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
101 void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
102 void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
103 void SVC_HANDLER (void) __attribute__ ((weak, alias("Default_Handler")));
104 void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
105 void PENDSV_HANDLER (void) __attribute__ ((weak, alias("Default_Handler")));
106 void SYSTICK_HANDLER (void) __attribute__ ((weak, alias("Default_Handler")));
107 
108 /* ARMCM3 Specific Interrupts */
109 void RTC1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
110 void Ext_Int0_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
111 void Ext_Int1_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
112 void Ext_Int2_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
113 void Ext_Int3_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
114 void WDog_Tmr_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
115 void Vreg_over_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
116 void Battery_Voltage_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
117 void RTC0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
118 void GPIO_A_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
119 void GPIO_B_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
120 void GP_Tmr0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
121 void GP_Tmr1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
122 void Flash0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
123 void UART_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
124 void SPI0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
125 void SPI2_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
126 void I2C0_Slave_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
127 void I2C0_Master_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
128 void DMA_Err_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
129 void DMA_SPI2_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
130 void DMA_SPI2_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
131 void DMA_SPORT0A_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
132 void DMA_SPORT0B_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
133 void DMA_SPI0_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
134 void DMA_SPI0_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
135 void DMA_SPI1_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
136 void DMA_SPI1_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
137 void DMA_UART_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
138 void DMA_UART_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
139 void DMA_I2C0_STX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
140 void DMA_I2C0_SRX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
141 void DMA_I2C0_MX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
142 void DMA_AES0_IN_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
143 void DMA_AES0_OUT_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
144 void DMA_FLASH0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
145 void SPORT0A_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
146 void SPORT0B_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
147 void Crypto_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
148 void DMA_ADC0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
149 void GP_Tmr2_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
150 void Crystal_osc_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
151 void SPI1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
152 void PLL_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
153 void RNG_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
154 void Beep_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
155 void ADC_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
156 void DMA_SIP0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
157 void DMA_SIP1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
158 void DMA_SIP2_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
159 void DMA_SIP3_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
160 void DMA_SIP4_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
161 void DMA_SIP5_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
162 void DMA_SIP6_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
163 void DMA_SIP7_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
164 
165 /*----------------------------------------------------------------------------
166  Exception / Interrupt Vector table
167  *----------------------------------------------------------------------------*/
168 const pFunc __Vectors[] __attribute__ ((section(".vectors"))) = {
169  /* Cortex-M3 Exceptions Handler */
170  (pFunc)&__StackTop, /* Initial Stack Pointer */
171  Reset_Handler, /* -15 */
172  NMI_Handler, /* -14 */
173  HardFault_Handler, /* -13 */
174  MemManage_Handler, /* -12 */
175  BusFault_Handler, /* -11 */
176  UsageFault_Handler, /* -10 */
177  0, /* -9 */
178  0, /* -8 */
179  0, /* -7 */
180  0, /* -6 */
181  SVC_HANDLER, /* -5 */
182  DebugMon_Handler, /* -4 */
183  0, /* -3 */
184  PENDSV_HANDLER, /* -2 */
185  SYSTICK_HANDLER, /* -1 */
186 
187  /* External interrupts */
188  RTC1_Int_Handler, /* 0 */
189  Ext_Int0_Handler, /* 1 */
190  Ext_Int1_Handler, /* 2 */
191  Ext_Int2_Handler, /* 3 */
192  Ext_Int3_Handler, /* 4 */
193  WDog_Tmr_Int_Handler, /* 5 */
194  Vreg_over_Int_Handler, /* 6 */
195  Battery_Voltage_Int_Handler, /* 7 */
196  RTC0_Int_Handler, /* 8 */
197  GPIO_A_Int_Handler, /* 9 */
198  GPIO_B_Int_Handler, /* 10 */
199  GP_Tmr0_Int_Handler, /* 11 */
200  GP_Tmr1_Int_Handler, /* 12 */
201  Flash0_Int_Handler, /* 13 */
202  UART_Int_Handler, /* 14 */
203  SPI0_Int_Handler, /* 15 */
204  SPI2_Int_Handler, /* 16 */
205  I2C0_Slave_Int_Handler, /* 17 */
206  I2C0_Master_Int_Handler, /* 18 */
207  DMA_Err_Int_Handler, /* 19 */
208  DMA_SPI2_TX_Int_Handler, /* 20 */
209  DMA_SPI2_RX_Int_Handler, /* 21 */
210  DMA_SPORT0A_Int_Handler, /* 22 */
211  DMA_SPORT0B_Int_Handler, /* 23 */
212  DMA_SPI0_TX_Int_Handler, /* 24 */
213  DMA_SPI0_RX_Int_Handler, /* 25 */
214  DMA_SPI1_TX_Int_Handler, /* 26 */
215  DMA_SPI1_RX_Int_Handler, /* 27 */
216  DMA_UART_TX_Int_Handler, /* 28 */
217  DMA_UART_RX_Int_Handler, /* 29 */
218  DMA_I2C0_STX_Int_Handler, /* 30 */
219  DMA_I2C0_SRX_Int_Handler, /* 31 */
220  DMA_I2C0_MX_Int_Handler, /* 32 */
221  DMA_AES0_IN_Int_Handler, /* 33 */
222  DMA_AES0_OUT_Int_Handler, /* 34 */
223  DMA_FLASH0_Int_Handler, /* 35 */
224  SPORT0A_Int_Handler, /* 36 */
225  SPORT0B_Int_Handler, /* 37 */
226  Crypto_Int_Handler, /* 38 */
227  DMA_ADC0_Int_Handler, /* 39 */
228  GP_Tmr2_Int_Handler, /* 40 */
229  Crystal_osc_Int_Handler, /* 41 */
230  SPI1_Int_Handler, /* 42 */
231  PLL_Int_Handler, /* 43 */
232  RNG_Int_Handler, /* 44 */
233  Beep_Int_Handler, /* 45 */
234  ADC_Int_Handler, /* 46 */
235  0, /* 47 */
236  0, /* 48 */
237  0, /* 49 */
238  0, /* 50 */
239  0, /* 51 */
240  0, /* 52 */
241  0, /* 53 */
242  0, /* 54 */
243  0, /* 55 */
244  DMA_SIP0_Int_Handler, /* 56 */
245  DMA_SIP1_Int_Handler, /* 57 */
246  DMA_SIP2_Int_Handler, /* 58 */
247  DMA_SIP3_Int_Handler, /* 59 */
248  DMA_SIP4_Int_Handler, /* 60 */
249  DMA_SIP5_Int_Handler, /* 61 */
250  DMA_SIP6_Int_Handler, /* 62 */
251  DMA_SIP7_Int_Handler, /* 63 */
252 };
253 
254 
255 /*----------------------------------------------------------------------------
256  Reset Handler C is called immediately on controller reset, unless
257  ADI_DISABLE_INSTRUCTION_SRAM is defined in reset_ADuCM3029.S.
258  *----------------------------------------------------------------------------*/
259 void Reset_Handler_C(void) {
260  uint32_t *pSrc, *pDest;
261  uint32_t *pTable __attribute__((unused));
262 
263 /* Firstly it copies data from read only memory to RAM. There are two schemes
264  * to copy. One can copy more than one sections. Another can only copy
265  * one section. The former scheme needs more instructions and read-only
266  * data to implement than the latter.
267  * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */
268 
269 #ifdef __STARTUP_COPY_MULTIPLE
270 /* Multiple sections scheme.
271  *
272  * Between symbol address __copy_table_start__ and __copy_table_end__,
273  * there are array of triplets, each of which specify:
274  * offset 0: LMA of start of a section to copy from
275  * offset 4: VMA of start of a section to copy to
276  * offset 8: size of the section to copy. Must be multiply of 4
277  *
278  * All addresses must be aligned to 4 bytes boundary.
279  */
280  pTable = &__copy_table_start__;
281 
282  for (; pTable < &__copy_table_end__; pTable = pTable + 3) {
283  pSrc = (uint32_t*)*(pTable + 0);
284  pDest = (uint32_t*)*(pTable + 1);
285  for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; ) {
286  *pDest++ = *pSrc++;
287  }
288  }
289 #else
290 /* Single section scheme.
291  *
292  * The ranges of copy from/to are specified by following symbols
293  * __etext: LMA of start of the section to copy from. Usually end of text
294  * __data_start__: VMA of start of the section to copy to
295  * __data_end__: VMA of end of the section to copy to
296  *
297  * All addresses must be aligned to 4 bytes boundary.
298  */
299  pSrc = &__etext;
300  pDest = &__data_start__;
301 
302  for ( ; pDest < &__data_end__ ; ) {
303  *pDest++ = *pSrc++;
304  }
305 #endif /*__STARTUP_COPY_MULTIPLE */
306 
307 /* This part of work usually is done in C library startup code. Otherwise,
308  * define this macro to enable it in this startup.
309  *
310  * There are two schemes too. One can clear multiple BSS sections. Another
311  * can only clear one section. The former is more size expensive than the
312  * latter.
313  *
314  * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
315  * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
316  */
317 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE
318 /* Multiple sections scheme.
319  *
320  * Between symbol address __copy_table_start__ and __copy_table_end__,
321  * there are array of tuples specifying:
322  * offset 0: Start of a BSS section
323  * offset 4: Size of this BSS section. Must be multiply of 4
324  */
325  pTable = &__zero_table_start__;
326 
327  for (; pTable < &__zero_table_end__; pTable = pTable + 2) {
328  pDest = (uint32_t*)*(pTable + 0);
329  for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; ) {
330  *pDest++ = 0;
331  }
332  }
333 #elif defined (__STARTUP_CLEAR_BSS)
334 /* Single BSS section scheme.
335  *
336  * The BSS section is specified by following symbols
337  * __bss_start__: start of the BSS section.
338  * __bss_end__: end of the BSS section.
339  *
340  * Both addresses must be aligned to 4 bytes boundary.
341  */
342  pDest = &__bss_start__;
343 
344  for ( ; pDest < &__bss_end__ ; ) {
345  *pDest++ = 0ul;
346  }
347 #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
348 
349 #ifndef __NO_SYSTEM_INIT
350  SystemInit();
351 #endif
352 
353 #ifndef __START
354 #define __START _start
355 #endif
356  __START();
357 
358 }
359 
360 
361 /*----------------------------------------------------------------------------
362  Default Handler for Exceptions / Interrupts
363  *----------------------------------------------------------------------------*/
364 void Default_Handler(void) {
365 
366  while(1);
367 }
void SystemInit(void)
Sets up the microcontroller system. Initializes the System and updates the relocate vector table...
void SPORT0A_Int_Handler(void)
void SPORT0B_Int_Handler(void)
void DMA_SPORT0B_Int_Handler(void)
void DMA_SPORT0A_Int_Handler(void)