ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
startup_ADuCM4050.c
1 /* File: startup_ADuCM4050.c
2  * Startup file for Analog Devices ADuCM4050 processor
3  *
4  * Based on startup_ARMCM4.c
5  *
6  */
7 /* Copyright (c) 2011 - 2014 ARM LIMITED
8  Portions Copyright (c) 2016 - 2020 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 /* Defining __PROGRAM_START enables the usage of start up code in Reset_Handler_C instead of the
36  * ARM provided __cmsis_start. __cmsis_start introduced in ARM CMSIS 5.6.0 as part of cmsis_gcc.h,
37  * imports copy table and zero table symbols (__copy_table_start__, __zero_table_start__ et al)
38  * as structures rather than words. This function is currently faulty as detailed in
39  * https://github.com/ARM-software/CMSIS_5/issues/632 */
40 #ifdef __PROGRAM_START
41 #undef __PROGRAM_START
42 #endif
43 #define __PROGRAM_START
44 
45 #include <stdint.h>
46 #include <rtos_map/adi_rtos_map.h>
47 
48 
49 /*----------------------------------------------------------------------------
50  Linker generated Symbols
51  *----------------------------------------------------------------------------*/
52 extern uint32_t __etext;
53 extern uint32_t __data_start__;
54 extern uint32_t __data_end__;
55 extern uint32_t __copy_table_start__;
56 extern uint32_t __copy_table_end__;
57 extern uint32_t __zero_table_start__;
58 extern uint32_t __zero_table_end__;
59 extern uint32_t __bss_start__;
60 extern uint32_t __bss_end__;
61 extern uint32_t __StackTop;
62 
63 /*----------------------------------------------------------------------------
64  Exception / Interrupt Handler Function Prototype
65  *----------------------------------------------------------------------------*/
66 typedef void( *pFunc )( void );
67 
68 
69 /*----------------------------------------------------------------------------
70  External References
71  *----------------------------------------------------------------------------*/
72 #ifndef __START
73 extern void _start(void) __attribute__((noreturn)); /* PreeMain (C library entry point) */
74 #else
75 extern int __START(void) __attribute__((noreturn)); /* main entry point */
76 #endif
77 
78 #ifndef __NO_SYSTEM_INIT
79 extern void SystemInit (void); /* CMSIS System Initialization */
80 #endif
81 
82 
83 /*----------------------------------------------------------------------------
84  Internal References
85  *----------------------------------------------------------------------------*/
86 void Default_Handler(void); /* Default empty handler */
87 
88 
89 /*----------------------------------------------------------------------------
90  User Initial Stack & Heap
91  *----------------------------------------------------------------------------*/
92 #ifndef __STACK_SIZE
93  #define __STACK_SIZE 0x00000400
94 #endif
95 static uint8_t stack[__STACK_SIZE] __attribute__ ((aligned(8), used, section(".stack")));
96 
97 #ifndef __HEAP_SIZE
98  #define __HEAP_SIZE 0x00000C00
99 #endif
100 #if __HEAP_SIZE > 0
101 static uint8_t heap[__HEAP_SIZE] __attribute__ ((aligned(8), used, section(".heap")));
102 #endif
103 
104 /*----------------------------------------------------------------------------
105  Exception / Interrupt Handler
106  *----------------------------------------------------------------------------*/
107 /* Cortex-M4 Processor Exceptions */
108 void Reset_Handler (void) __attribute__ ((weak, alias("Reset_Handler_C")));
109 void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
110 void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
111 void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
112 void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
113 void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
114 void SVC_HANDLER (void) __attribute__ ((weak, alias("Default_Handler")));
115 void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
116 void PENDSV_HANDLER (void) __attribute__ ((weak, alias("Default_Handler")));
117 void SYSTICK_HANDLER (void) __attribute__ ((weak, alias("Default_Handler")));
118 
119 /* ARMCM4 Specific Interrupts */
120 void RTC1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
121 void Ext_Int0_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
122 void Ext_Int1_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
123 void Ext_Int2_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
124 void Ext_Int3_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
125 void WDog_Tmr_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
126 void Vreg_over_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
127 void Battery_Voltage_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
128 void RTC0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
129 void GPIO_A_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
130 void GPIO_B_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
131 void GP_Tmr0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
132 void GP_Tmr1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
133 void Flash0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
134 void UART0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
135 void SPI0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
136 void SPI2_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
137 void I2C0_Slave_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
138 void I2C0_Master_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
139 void DMA_Err_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
140 void DMA_SPIH_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
141 void DMA_SPIH_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
142 void DMA_SPORT0A_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
143 void DMA_SPORT0B_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
144 void DMA_SPI0_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
145 void DMA_SPI0_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
146 void DMA_SPI1_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
147 void DMA_SPI1_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
148 void DMA_UART0_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
149 void DMA_UART0_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
150 void DMA_I2C0_STX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
151 void DMA_I2C0_SRX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
152 void DMA_I2C0_MX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
153 void DMA_AES0_IN_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
154 void DMA_AES0_OUT_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
155 void DMA_FLASH0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
156 void SPORT0A_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
157 void SPORT0B_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
158 void Crypto_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
159 void DMA_ADC0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
160 void GP_Tmr2_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
161 void Crystal_osc_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
162 void SPI1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
163 void PLL_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
164 void RNG_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
165 void Beep_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
166 void ADC0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
167 void DMA_SIP0_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
168 void DMA_SIP1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
169 void DMA_SIP2_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
170 void DMA_SIP3_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
171 void DMA_SIP4_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
172 void DMA_SIP5_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
173 void DMA_SIP6_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
174 void DMA_SIP7_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
175 void UART1_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
176 void DMA_UART1_TX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
177 void DMA_UART1_RX_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
178 void RGB_Tmr_Int_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
179 void Root_Clk_Err_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
180 
181 /*----------------------------------------------------------------------------
182  Exception / Interrupt Vector table
183  *----------------------------------------------------------------------------*/
184 const pFunc __Vectors[] __attribute__ ((section(".vectors"))) = {
185  /* Cortex-M4 Exceptions Handler */
186  (pFunc)&__StackTop, /* Initial Stack Pointer */
187  Reset_Handler, /* -15 */
188  NMI_Handler, /* -14 */
189  HardFault_Handler, /* -13 */
190  MemManage_Handler, /* -12 */
191  BusFault_Handler, /* -11 */
192  UsageFault_Handler, /* -10 */
193  0, /* -9 */
194  0, /* -8 */
195  0, /* -7 */
196  0, /* -6 */
197  SVC_HANDLER, /* -5 */
198  DebugMon_Handler, /* -4 */
199  0, /* -3 */
200  PENDSV_HANDLER, /* -2 */
201  SYSTICK_HANDLER, /* -1 */
202 
203  /* External interrupts */
204  RTC1_Int_Handler, /* 0 */
205  Ext_Int0_Handler, /* 1 */
206  Ext_Int1_Handler, /* 2 */
207  Ext_Int2_Handler, /* 3 */
208  Ext_Int3_Handler, /* 4 */
209  WDog_Tmr_Int_Handler, /* 5 */
210  Vreg_over_Int_Handler, /* 6 */
211  Battery_Voltage_Int_Handler, /* 7 */
212  RTC0_Int_Handler, /* 8 */
213  GPIO_A_Int_Handler, /* 9 */
214  GPIO_B_Int_Handler, /* 10 */
215  GP_Tmr0_Int_Handler, /* 11 */
216  GP_Tmr1_Int_Handler, /* 12 */
217  Flash0_Int_Handler, /* 13 */
218  UART0_Int_Handler, /* 14 */
219  SPI0_Int_Handler, /* 15 */
220  SPI2_Int_Handler, /* 16 */
221  I2C0_Slave_Int_Handler, /* 17 */
222  I2C0_Master_Int_Handler, /* 18 */
223  DMA_Err_Int_Handler, /* 19 */
224  DMA_SPIH_TX_Int_Handler, /* 20 */
225  DMA_SPIH_RX_Int_Handler, /* 21 */
226  DMA_SPORT0A_Int_Handler, /* 22 */
227  DMA_SPORT0B_Int_Handler, /* 23 */
228  DMA_SPI0_TX_Int_Handler, /* 24 */
229  DMA_SPI0_RX_Int_Handler, /* 25 */
230  DMA_SPI1_TX_Int_Handler, /* 26 */
231  DMA_SPI1_RX_Int_Handler, /* 27 */
232  DMA_UART0_TX_Int_Handler, /* 28 */
233  DMA_UART0_RX_Int_Handler, /* 29 */
234  DMA_I2C0_STX_Int_Handler, /* 30 */
235  DMA_I2C0_SRX_Int_Handler, /* 31 */
236  DMA_I2C0_MX_Int_Handler, /* 32 */
237  DMA_AES0_IN_Int_Handler, /* 33 */
238  DMA_AES0_OUT_Int_Handler, /* 34 */
239  DMA_FLASH0_Int_Handler, /* 35 */
240  SPORT0A_Int_Handler, /* 36 */
241  SPORT0B_Int_Handler, /* 37 */
242  Crypto_Int_Handler, /* 38 */
243  DMA_ADC0_Int_Handler, /* 39 */
244  GP_Tmr2_Int_Handler, /* 40 */
245  Crystal_osc_Int_Handler, /* 41 */
246  SPI1_Int_Handler, /* 42 */
247  PLL_Int_Handler, /* 43 */
248  RNG_Int_Handler, /* 44 */
249  Beep_Int_Handler, /* 45 */
250  ADC0_Int_Handler, /* 46 */
251  0, /* 47 */
252  0, /* 48 */
253  0, /* 49 */
254  0, /* 50 */
255  0, /* 51 */
256  0, /* 52 */
257  0, /* 53 */
258  0, /* 54 */
259  0, /* 55 */
260  DMA_SIP0_Int_Handler, /* 56 */
261  DMA_SIP1_Int_Handler, /* 57 */
262  DMA_SIP2_Int_Handler, /* 58 */
263  DMA_SIP3_Int_Handler, /* 59 */
264  DMA_SIP4_Int_Handler, /* 60 */
265  DMA_SIP5_Int_Handler, /* 61 */
266  DMA_SIP6_Int_Handler, /* 62 */
267  DMA_SIP7_Int_Handler, /* 63 */
268  0, /* 64 */
269  0, /* 65 */
270  UART1_Int_Handler, /* 66 */
271  DMA_UART1_TX_Int_Handler, /* 67 */
272  DMA_UART1_RX_Int_Handler, /* 68 */
273  RGB_Tmr_Int_Handler, /* 69 */
274  0, /* 70 */
275  Root_Clk_Err_Handler, /* 71 */
276 };
277 
278 
279 /*----------------------------------------------------------------------------
280  Reset Handler C is called immediately on controller reset, unless
281  ADI_DISABLE_INSTRUCTION_SRAM is defined in reset_ADuCM4050.S.
282  *----------------------------------------------------------------------------*/
283 void Reset_Handler_C(void) {
284  uint32_t *pSrc, *pDest;
285  uint32_t *pTable __attribute__((unused));
286 
287 /* Invoke SystemInit() to configure the SRAM memory. This needs to happen
288  * before copy-code, else the target memory spaces may not be accessible.
289  */
290 #ifndef __NO_SYSTEM_INIT
291  SystemInit();
292 #endif
293 
294 /* Copy data from read only memory to RAM. There are two schemes
295  * to copy. One can copy more than one sections. Another can only copy
296  * one section. The former scheme needs more instructions and read-only
297  * data to implement than the latter.
298  * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */
299 
300 #ifdef __STARTUP_COPY_MULTIPLE
301 /* Multiple sections scheme.
302  *
303  * Between symbol address __copy_table_start__ and __copy_table_end__,
304  * there are array of triplets, each of which specify:
305  * offset 0: LMA of start of a section to copy from
306  * offset 4: VMA of start of a section to copy to
307  * offset 8: size of the section to copy. Must be multiply of 4
308  *
309  * All addresses must be aligned to 4 bytes boundary.
310  */
311  pTable = &__copy_table_start__;
312 
313  for (; pTable < &__copy_table_end__; pTable = pTable + 3) {
314  pSrc = (uint32_t*)*(pTable + 0);
315  pDest = (uint32_t*)*(pTable + 1);
316  for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; ) {
317  *pDest++ = *pSrc++;
318  }
319  }
320 #else
321 /* Single section scheme.
322  *
323  * The ranges of copy from/to are specified by following symbols
324  * __etext: LMA of start of the section to copy from. Usually end of text
325  * __data_start__: VMA of start of the section to copy to
326  * __data_end__: VMA of end of the section to copy to
327  *
328  * All addresses must be aligned to 4 bytes boundary.
329  */
330  pSrc = &__etext;
331  pDest = &__data_start__;
332 
333  for ( ; pDest < &__data_end__ ; ) {
334  *pDest++ = *pSrc++;
335  }
336 #endif /*__STARTUP_COPY_MULTIPLE */
337 
338 /* This part of work usually is done in C library startup code. Otherwise,
339  * define this macro to enable it in this startup.
340  *
341  * There are two schemes too. One can clear multiple BSS sections. Another
342  * can only clear one section. The former is more size expensive than the
343  * latter.
344  *
345  * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
346  * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
347  */
348 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE
349 /* Multiple sections scheme.
350  *
351  * Between symbol address __copy_table_start__ and __copy_table_end__,
352  * there are array of tuples specifying:
353  * offset 0: Start of a BSS section
354  * offset 4: Size of this BSS section. Must be multiply of 4
355  */
356  pTable = &__zero_table_start__;
357 
358  for (; pTable < &__zero_table_end__; pTable = pTable + 2) {
359  pDest = (uint32_t*)*(pTable + 0);
360  for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; ) {
361  *pDest++ = 0;
362  }
363  }
364 #elif defined (__STARTUP_CLEAR_BSS)
365 /* Single BSS section scheme.
366  *
367  * The BSS section is specified by following symbols
368  * __bss_start__: start of the BSS section.
369  * __bss_end__: end of the BSS section.
370  *
371  * Both addresses must be aligned to 4 bytes boundary.
372  */
373  pDest = &__bss_start__;
374 
375  for ( ; pDest < &__bss_end__ ; ) {
376  *pDest++ = 0ul;
377  }
378 #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
379 
380 #ifndef __START
381 #define __START _start
382 #endif
383  __START();
384 
385 }
386 
387 
388 /*----------------------------------------------------------------------------
389  Default Handler for Exceptions / Interrupts
390  *----------------------------------------------------------------------------*/
391 void Default_Handler(void) {
392 
393  while(1);
394 }
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)