SAM4S-EK_FreeRTOS+FAT-SL  1.0
An example project to test the functionality of FreeRTOS+FAT-SL using SD card as data storage medium
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
startup_sam4s.c
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------- */
2 /* Atmel Microcontroller Software Support */
3 /* SAM Software Package License */
4 /* ---------------------------------------------------------------------------- */
5 /* Copyright (c) 2014, Atmel Corporation */
6 /* */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without */
10 /* modification, are permitted provided that the following condition is met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, */
13 /* this list of conditions and the disclaimer below. */
14 /* */
15 /* Atmel's name may not be used to endorse or promote products derived from */
16 /* this software without specific prior written permission. */
17 /* */
18 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */
19 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */
21 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */
22 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
24 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
25 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
26 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 /* ---------------------------------------------------------------------------- */
29 
30 #include "sam4s.h"
31 
32 /* Initialize segments */
33 extern uint32_t _sfixed;
34 extern uint32_t _efixed;
35 extern uint32_t _etext;
36 extern uint32_t _srelocate;
37 extern uint32_t _erelocate;
38 extern uint32_t _szero;
39 extern uint32_t _ezero;
40 extern uint32_t _sstack;
41 extern uint32_t _estack;
42 
44 int main(void);
47 void __libc_init_array(void);
48 
49 /* Default empty handler */
50 void Dummy_Handler(void);
51 
52 /* Cortex-M4 core handlers */
53 void NMI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
54 void HardFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
55 void MemManage_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
56 void BusFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
57 void UsageFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
58 void SVC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
59 void DebugMon_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
60 void PendSV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
61 void SysTick_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
62 
63 /* Peripherals handlers */
64 void SUPC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
65 void RSTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
66 void RTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
67 void RTT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
68 void WDT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
69 void PMC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
70 void EFC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
71 #ifdef _SAM4S_EFC1_INSTANCE_
72 void EFC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
73 #endif /* _SAM4S_EFC1_INSTANCE_ */
74 void UART0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
75 void UART1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
76 void PIOA_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
77 void PIOB_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
78 #ifdef _SAM4S_PIOC_INSTANCE_
79 void PIOC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
80 #endif /* _SAM4S_PIOC_INSTANCE_ */
81 void USART0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
82 #ifdef _SAM4S_USART1_INSTANCE_
83 void USART1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
84 #endif /* _SAM4S_USART1_INSTANCE_ */
85 #ifdef _SAM4S_HSMCI_INSTANCE_
86 void HSMCI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
87 #endif /* _SAM4S_HSMCI_INSTANCE_ */
88 void TWI0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
89 void TWI1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
90 void SPI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
91 void SSC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
92 void TC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
93 void TC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
94 void TC2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
95 #ifdef _SAM4S_TC1_INSTANCE_
96 void TC3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
97 #endif /* _SAM4S_TC1_INSTANCE_ */
98 #ifdef _SAM4S_TC1_INSTANCE_
99 void TC4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
100 #endif /* _SAM4S_TC1_INSTANCE_ */
101 #ifdef _SAM4S_TC1_INSTANCE_
102 void TC5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
103 #endif /* _SAM4S_TC1_INSTANCE_ */
104 void ADC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
105 #ifdef _SAM4S_DACC_INSTANCE_
106 void DACC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
107 #endif /* _SAM4S_DACC_INSTANCE_ */
108 void PWM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
109 void CRCCU_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
110 void ACC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
111 void UDP_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
112 
113 /* Exception Table */
114 __attribute__ ((section(".vectors")))
115 const DeviceVectors exception_table = {
116 
117  /* Configure Initial Stack Pointer, using linker-generated symbols */
118  .pvStack = (void*) (&_estack),
119 
120  .pfnReset_Handler = (void*) Reset_Handler,
121  .pfnNMI_Handler = (void*) NMI_Handler,
122  .pfnHardFault_Handler = (void*) HardFault_Handler,
123  .pfnMemManage_Handler = (void*) MemManage_Handler,
124  .pfnBusFault_Handler = (void*) BusFault_Handler,
125  .pfnUsageFault_Handler = (void*) UsageFault_Handler,
126  .pfnReserved1_Handler = (void*) (0UL), /* Reserved */
127  .pfnReserved2_Handler = (void*) (0UL), /* Reserved */
128  .pfnReserved3_Handler = (void*) (0UL), /* Reserved */
129  .pfnReserved4_Handler = (void*) (0UL), /* Reserved */
130  .pfnSVC_Handler = (void*) SVC_Handler,
131  .pfnDebugMon_Handler = (void*) DebugMon_Handler,
132  .pfnReserved5_Handler = (void*) (0UL), /* Reserved */
133  .pfnPendSV_Handler = (void*) PendSV_Handler,
134  .pfnSysTick_Handler = (void*) SysTick_Handler,
135 
136  /* Configurable interrupts */
137  .pfnSUPC_Handler = (void*) SUPC_Handler, /* 0 Supply Controller */
138  .pfnRSTC_Handler = (void*) RSTC_Handler, /* 1 Reset Controller */
139  .pfnRTC_Handler = (void*) RTC_Handler, /* 2 Real Time Clock */
140  .pfnRTT_Handler = (void*) RTT_Handler, /* 3 Real Time Timer */
141  .pfnWDT_Handler = (void*) WDT_Handler, /* 4 Watchdog Timer */
142  .pfnPMC_Handler = (void*) PMC_Handler, /* 5 Power Management Controller */
143  .pfnEFC0_Handler = (void*) EFC0_Handler, /* 6 Enhanced Embedded Flash Controller 0 */
144 #ifdef _SAM4S_EFC1_INSTANCE_
145  .pfnEFC1_Handler = (void*) EFC1_Handler, /* 7 Enhanced Embedded Flash Controller 1 */
146 #else
147  .pvReserved7 = (void*) (0UL), /* 7 Reserved */
148 #endif /* _SAM4S_EFC1_INSTANCE_ */
149  .pfnUART0_Handler = (void*) UART0_Handler, /* 8 UART 0 */
150  .pfnUART1_Handler = (void*) UART1_Handler, /* 9 UART 1 */
151  .pvReserved10 = (void*) (0UL), /* 10 Reserved */
152  .pfnPIOA_Handler = (void*) PIOA_Handler, /* 11 Parallel I/O Controller A */
153  .pfnPIOB_Handler = (void*) PIOB_Handler, /* 12 Parallel I/O Controller B */
154 #ifdef _SAM4S_PIOC_INSTANCE_
155  .pfnPIOC_Handler = (void*) PIOC_Handler, /* 13 Parallel I/O Controller C */
156 #else
157  .pvReserved13 = (void*) (0UL), /* 13 Reserved */
158 #endif /* _SAM4S_PIOC_INSTANCE_ */
159  .pfnUSART0_Handler = (void*) USART0_Handler, /* 14 USART 0 */
160 #ifdef _SAM4S_USART1_INSTANCE_
161  .pfnUSART1_Handler = (void*) USART1_Handler, /* 15 USART 1 */
162 #else
163  .pvReserved15 = (void*) (0UL), /* 15 Reserved */
164 #endif /* _SAM4S_USART1_INSTANCE_ */
165  .pvReserved16 = (void*) (0UL), /* 16 Reserved */
166  .pvReserved17 = (void*) (0UL), /* 17 Reserved */
167 #ifdef _SAM4S_HSMCI_INSTANCE_
168  .pfnHSMCI_Handler = (void*) HSMCI_Handler, /* 18 Multimedia Card Interface */
169 #else
170  .pvReserved18 = (void*) (0UL), /* 18 Reserved */
171 #endif /* _SAM4S_HSMCI_INSTANCE_ */
172  .pfnTWI0_Handler = (void*) TWI0_Handler, /* 19 Two Wire Interface 0 */
173  .pfnTWI1_Handler = (void*) TWI1_Handler, /* 20 Two Wire Interface 1 */
174  .pfnSPI_Handler = (void*) SPI_Handler, /* 21 Serial Peripheral Interface */
175  .pfnSSC_Handler = (void*) SSC_Handler, /* 22 Synchronous Serial Controller */
176  .pfnTC0_Handler = (void*) TC0_Handler, /* 23 Timer/Counter 0 */
177  .pfnTC1_Handler = (void*) TC1_Handler, /* 24 Timer/Counter 1 */
178  .pfnTC2_Handler = (void*) TC2_Handler, /* 25 Timer/Counter 2 */
179 #ifdef _SAM4S_TC1_INSTANCE_
180  .pfnTC3_Handler = (void*) TC3_Handler, /* 26 Timer/Counter 3 */
181 #else
182  .pvReserved26 = (void*) (0UL), /* 26 Reserved */
183 #endif /* _SAM4S_TC1_INSTANCE_ */
184 #ifdef _SAM4S_TC1_INSTANCE_
185  .pfnTC4_Handler = (void*) TC4_Handler, /* 27 Timer/Counter 4 */
186 #else
187  .pvReserved27 = (void*) (0UL), /* 27 Reserved */
188 #endif /* _SAM4S_TC1_INSTANCE_ */
189 #ifdef _SAM4S_TC1_INSTANCE_
190  .pfnTC5_Handler = (void*) TC5_Handler, /* 28 Timer/Counter 5 */
191 #else
192  .pvReserved28 = (void*) (0UL), /* 28 Reserved */
193 #endif /* _SAM4S_TC1_INSTANCE_ */
194  .pfnADC_Handler = (void*) ADC_Handler, /* 29 Analog To Digital Converter */
195 #ifdef _SAM4S_DACC_INSTANCE_
196  .pfnDACC_Handler = (void*) DACC_Handler, /* 30 Digital To Analog Converter */
197 #else
198  .pvReserved30 = (void*) (0UL), /* 30 Reserved */
199 #endif /* _SAM4S_DACC_INSTANCE_ */
200  .pfnPWM_Handler = (void*) PWM_Handler, /* 31 Pulse Width Modulation */
201  .pfnCRCCU_Handler = (void*) CRCCU_Handler, /* 32 CRC Calculation Unit */
202  .pfnACC_Handler = (void*) ACC_Handler, /* 33 Analog Comparator */
203  .pfnUDP_Handler = (void*) UDP_Handler /* 34 USB Device Port */
204 };
205 
210 void Reset_Handler(void)
211 {
212  uint32_t *pSrc, *pDest;
213 
214  /* Initialize the relocate segment */
215  pSrc = &_etext;
216  pDest = &_srelocate;
217 
218  if (pSrc != pDest) {
219  for (; pDest < &_erelocate;) {
220  *pDest++ = *pSrc++;
221  }
222  }
223 
224  /* Clear the zero segment */
225  for (pDest = &_szero; pDest < &_ezero;) {
226  *pDest++ = 0;
227  }
228 
229  /* Set the vector table base address */
230  pSrc = (uint32_t *) & _sfixed;
231  SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk);
232 
233  /* Initialize the C library */
235 
236  /* Branch to main function */
237  main();
238 
239  /* Infinite loop */
240  while (1);
241 }
242 
246 void Dummy_Handler(void)
247 {
248  while (1) {
249  }
250 }
uint32_t _efixed
uint32_t _srelocate
void Dummy_Handler(void)
Default interrupt handler for unused IRQs.
uint32_t _estack
void Reset_Handler(void)
This is the code that gets called on processor reset. To initialize the device, and call the main() r...
uint32_t _sfixed
uint32_t _szero
uint32_t _ezero
uint32_t _erelocate
void __libc_init_array(void)
uint32_t _sstack
__attribute__((naked))
Definition: port.c:391
int main(void)
Application entry point.
uint32_t _etext
void NMI_Handler(void HardFault_Handler void)
Definition: startup_sam4s.c:53