|
| 1 | +/** |
| 2 | + * \file |
| 3 | + * |
| 4 | + * \brief Startup file for SAMG55. |
| 5 | + * |
| 6 | + * Copyright (c) 2014-2015 Atmel Corporation. All rights reserved. |
| 7 | + * |
| 8 | + * \asf_license_start |
| 9 | + * |
| 10 | + * \page License |
| 11 | + * |
| 12 | + * Redistribution and use in source and binary forms, with or without |
| 13 | + * modification, are permitted provided that the following conditions are met: |
| 14 | + * |
| 15 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 16 | + * this list of conditions and the following disclaimer. |
| 17 | + * |
| 18 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 19 | + * this list of conditions and the following disclaimer in the documentation |
| 20 | + * and/or other materials provided with the distribution. |
| 21 | + * |
| 22 | + * 3. The name of Atmel may not be used to endorse or promote products derived |
| 23 | + * from this software without specific prior written permission. |
| 24 | + * |
| 25 | + * 4. This software may only be redistributed and used in connection with an |
| 26 | + * Atmel microcontroller product. |
| 27 | + * |
| 28 | + * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED |
| 29 | + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 30 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
| 31 | + * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR |
| 32 | + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 33 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 34 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 35 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 36 | + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 37 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 38 | + * POSSIBILITY OF SUCH DAMAGE. |
| 39 | + * |
| 40 | + * \asf_license_stop |
| 41 | + * |
| 42 | + */ |
| 43 | +/* |
| 44 | + * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> |
| 45 | + */ |
| 46 | + |
| 47 | +#include "samg55.h" |
| 48 | + |
| 49 | +#if __FPU_USED /* CMSIS defined value to indicate usage of FPU */ |
| 50 | +#include "fpu.h" |
| 51 | +#endif |
| 52 | + |
| 53 | +/* Initialize segments */ |
| 54 | +extern uint32_t _sfixed; |
| 55 | +extern uint32_t _efixed; |
| 56 | +extern uint32_t _etext; |
| 57 | +extern uint32_t _srelocate; |
| 58 | +extern uint32_t _erelocate; |
| 59 | +extern uint32_t _szero; |
| 60 | +extern uint32_t _ezero; |
| 61 | +extern uint32_t _sstack; |
| 62 | +extern uint32_t _estack; |
| 63 | + |
| 64 | +/** \cond DOXYGEN_SHOULD_SKIP_THIS */ |
| 65 | +int main(void); |
| 66 | +/** \endcond */ |
| 67 | + |
| 68 | +void __libc_init_array(void); |
| 69 | + |
| 70 | +/* Default empty handler */ |
| 71 | +void Dummy_Handler(void); |
| 72 | + |
| 73 | +/* Cortex-M4 core handlers */ |
| 74 | +void NMI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 75 | +void HardFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 76 | +void MemManage_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 77 | +void BusFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 78 | +void UsageFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 79 | +void SVC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 80 | +void DebugMon_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 81 | +void PendSV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 82 | +void SysTick_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 83 | + |
| 84 | +/* Peripherals handlers */ |
| 85 | +void SUPC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 86 | +void RSTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 87 | +void RTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 88 | +void RTT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 89 | +void WDT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 90 | +void PMC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 91 | +void EFC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 92 | +#ifdef _SAMG55_FLEXCOM7_INSTANCE_ |
| 93 | +void FLEXCOM7_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 94 | +#endif /* _SAMG55_FLEXCOM7_INSTANCE_*/ |
| 95 | +void FLEXCOM0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 96 | +void FLEXCOM1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 97 | +void PIOA_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 98 | +void PIOB_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 99 | +void PDMIC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 100 | +void FLEXCOM2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 101 | +void MEM2MEM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 102 | +void I2SC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 103 | +void I2SC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 104 | +void PDMIC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 105 | +void FLEXCOM3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 106 | +void FLEXCOM4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 107 | +void FLEXCOM5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 108 | +void FLEXCOM6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 109 | +void TC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 110 | +void TC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 111 | +void TC2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 112 | +void TC3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 113 | +void TC4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 114 | +void TC5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 115 | +void ADC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 116 | +void ARM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 117 | +void UHP_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 118 | +void UDP_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 119 | +void CRCCU_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); |
| 120 | + |
| 121 | +/* Exception Table */ |
| 122 | +__attribute__ ((section(".vectors"))) |
| 123 | +const DeviceVectors exception_table = { |
| 124 | + |
| 125 | + /* Configure Initial Stack Pointer, using linker-generated symbols */ |
| 126 | + .pvStack = (void*) (&_estack), |
| 127 | + |
| 128 | + .pfnReset_Handler = (void*) Reset_Handler, |
| 129 | + .pfnNMI_Handler = (void*) NMI_Handler, |
| 130 | + .pfnHardFault_Handler = (void*) HardFault_Handler, |
| 131 | + .pfnMemManage_Handler = (void*) MemManage_Handler, |
| 132 | + .pfnBusFault_Handler = (void*) BusFault_Handler, |
| 133 | + .pfnUsageFault_Handler = (void*) UsageFault_Handler, |
| 134 | + .pfnReserved1_Handler = (void*) (0UL), /* Reserved */ |
| 135 | + .pfnReserved2_Handler = (void*) (0UL), /* Reserved */ |
| 136 | + .pfnReserved3_Handler = (void*) (0UL), /* Reserved */ |
| 137 | + .pfnReserved4_Handler = (void*) (0UL), /* Reserved */ |
| 138 | + .pfnSVC_Handler = (void*) SVC_Handler, |
| 139 | + .pfnDebugMon_Handler = (void*) DebugMon_Handler, |
| 140 | + .pfnReserved5_Handler = (void*) (0UL), /* Reserved */ |
| 141 | + .pfnPendSV_Handler = (void*) PendSV_Handler, |
| 142 | + .pfnSysTick_Handler = (void*) SysTick_Handler, |
| 143 | + |
| 144 | + /* Configurable interrupts */ |
| 145 | + .pfnSUPC_Handler = (void*) SUPC_Handler, /* 0 Supply Controller */ |
| 146 | + .pfnRSTC_Handler = (void*) RSTC_Handler, /* 1 Reset Controller */ |
| 147 | + .pfnRTC_Handler = (void*) RTC_Handler, /* 2 Real Time Clock */ |
| 148 | + .pfnRTT_Handler = (void*) RTT_Handler, /* 3 Real Time Timer */ |
| 149 | + .pfnWDT_Handler = (void*) WDT_Handler, /* 4 Watchdog Timer */ |
| 150 | + .pfnPMC_Handler = (void*) PMC_Handler, /* 5 Power Management Controller */ |
| 151 | + .pfnEFC_Handler = (void*) EFC_Handler, /* 6 Enhanced Flash Controller */ |
| 152 | +#ifdef _SAMG55_FLEXCOM7_INSTANCE_ |
| 153 | + .pfnFLEXCOM7_Handler = (void*) FLEXCOM7_Handler, /* 7 FLEXCOM 7 */ |
| 154 | +#else |
| 155 | + .pvReserved7 = (void*) (0UL), /* 7 Reserved */ |
| 156 | +#endif /* _SAMG55_FLEXCOM7_INSTANCE_ */ |
| 157 | + .pfnFLEXCOM0_Handler = (void*) FLEXCOM0_Handler, /* 8 FLEXCOM 0 */ |
| 158 | + .pfnFLEXCOM1_Handler = (void*) FLEXCOM1_Handler, /* 9 FLEXCOM 1 */ |
| 159 | + .pvReserved10 = (void*) (0UL), /* 10 Reserved */ |
| 160 | + .pfnPIOA_Handler = (void*) PIOA_Handler, /* 11 Parallel I/O Controller A */ |
| 161 | + .pfnPIOB_Handler = (void*) PIOB_Handler, /* 12 Parallel I/O Controller B */ |
| 162 | + .pfnPDMIC0_Handler = (void*) PDMIC0_Handler, /* 13 PDM 0 */ |
| 163 | + .pfnFLEXCOM2_Handler = (void*) FLEXCOM2_Handler, /* 14 FLEXCOM2 */ |
| 164 | + .pfnMEM2MEM_Handler = (void*) MEM2MEM_Handler, /* 15 MEM2MEM */ |
| 165 | + .pfnI2SC0_Handler = (void*) I2SC0_Handler, /* 16 I2SC0 */ |
| 166 | + .pfnI2SC1_Handler = (void*) I2SC1_Handler, /* 17 I2SC1 */ |
| 167 | + .pfnPDMIC1_Handler = (void*) PDMIC1_Handler, /* 18 PDM 1 */ |
| 168 | + .pfnFLEXCOM3_Handler = (void*) FLEXCOM3_Handler, /* 19 FLEXCOM3 */ |
| 169 | + .pfnFLEXCOM4_Handler = (void*) FLEXCOM4_Handler, /* 20 FLEXCOM4 */ |
| 170 | + .pfnFLEXCOM5_Handler = (void*) FLEXCOM5_Handler, /* 21 FLEXCOM5 */ |
| 171 | + .pfnFLEXCOM6_Handler = (void*) FLEXCOM6_Handler, /* 22 FLEXCOM6 */ |
| 172 | + .pfnTC0_Handler = (void*) TC0_Handler, /* 23 Timer/Counter 0 */ |
| 173 | + .pfnTC1_Handler = (void*) TC1_Handler, /* 24 Timer/Counter 1 */ |
| 174 | + .pfnTC2_Handler = (void*) TC2_Handler, /* 25 Timer/Counter 2 */ |
| 175 | + .pfnTC3_Handler = (void*) TC3_Handler, /* 26 Timer/Counter 3 */ |
| 176 | + .pfnTC4_Handler = (void*) TC4_Handler, /* 27 Timer/Counter 4 */ |
| 177 | + .pfnTC5_Handler = (void*) TC5_Handler, /* 28 Timer/Counter 5 */ |
| 178 | + .pfnADC_Handler = (void*) ADC_Handler, /* 29 Analog To Digital Converter */ |
| 179 | + .pfnARM_Handler = (void*) ARM_Handler, /* 30 FPU */ |
| 180 | + .pvReserved31 = (void*) (0UL), /* 31 Reserved */ |
| 181 | + .pvReserved32 = (void*) (0UL), /* 32 Reserved */ |
| 182 | + .pvReserved33 = (void*) (0UL), /* 33 Reserved */ |
| 183 | + .pvReserved34 = (void*) (0UL), /* 34 Reserved */ |
| 184 | + .pvReserved35 = (void*) (0UL), /* 35 Reserved */ |
| 185 | + .pvReserved36 = (void*) (0UL), /* 36 Reserved */ |
| 186 | + .pvReserved37 = (void*) (0UL), /* 37 Reserved */ |
| 187 | + .pvReserved38 = (void*) (0UL), /* 38 Reserved */ |
| 188 | + .pvReserved39 = (void*) (0UL), /* 39 Reserved */ |
| 189 | + .pvReserved40 = (void*) (0UL), /* 40 Reserved */ |
| 190 | + .pvReserved41 = (void*) (0UL), /* 41 Reserved */ |
| 191 | + .pvReserved42 = (void*) (0UL), /* 42 Reserved */ |
| 192 | + .pvReserved43 = (void*) (0UL), /* 43 Reserved */ |
| 193 | + .pvReserved44 = (void*) (0UL), /* 44 Reserved */ |
| 194 | + .pvReserved45 = (void*) (0UL), /* 45 Reserved */ |
| 195 | + .pvReserved46 = (void*) (0UL), /* 46 Reserved */ |
| 196 | + .pfnUHP_Handler = (void*) UHP_Handler, /* 47 USB OHCI */ |
| 197 | + .pfnUDP_Handler = (void*) UDP_Handler, /* 48 USB Device FS */ |
| 198 | + .pfnCRCCU_Handler = (void*) CRCCU_Handler /* 49 CRCCU */ |
| 199 | +}; |
| 200 | + |
| 201 | +/* TEMPORARY PATCH FOR SCB */ |
| 202 | +#define SCB_VTOR_TBLBASE_Pos 29 /*!< SCB VTOR: TBLBASE Position */ |
| 203 | +#define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */ |
| 204 | + |
| 205 | +/** |
| 206 | + * \brief This is the code that gets called on processor reset. |
| 207 | + * To initialize the device, and call the main() routine. |
| 208 | + */ |
| 209 | +void Reset_Handler(void) |
| 210 | +{ |
| 211 | + uint32_t *pSrc, *pDest; |
| 212 | + |
| 213 | + /* Initialize the relocate segment */ |
| 214 | + pSrc = &_etext; |
| 215 | + pDest = &_srelocate; |
| 216 | + |
| 217 | + if (pSrc != pDest) { |
| 218 | + for (; pDest < &_erelocate;) { |
| 219 | + *pDest++ = *pSrc++; |
| 220 | + } |
| 221 | + } |
| 222 | + |
| 223 | + /* Clear the zero segment */ |
| 224 | + for (pDest = &_szero; pDest < &_ezero;) { |
| 225 | + *pDest++ = 0; |
| 226 | + } |
| 227 | + |
| 228 | + /* Set the vector table base address */ |
| 229 | + pSrc = (uint32_t *) & _sfixed; |
| 230 | + SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk); |
| 231 | + |
| 232 | +#if __FPU_USED |
| 233 | + fpu_enable(); |
| 234 | +#endif |
| 235 | + |
| 236 | + if (((uint32_t) pSrc >= IRAM_ADDR) && ((uint32_t) pSrc < IRAM_ADDR + IRAM_SIZE)) { |
| 237 | + SCB->VTOR |= 1 << SCB_VTOR_TBLBASE_Pos; |
| 238 | + } |
| 239 | + |
| 240 | + /* Initialize the C library */ |
| 241 | + __libc_init_array(); |
| 242 | + |
| 243 | + /* Branch to main function */ |
| 244 | + main(); |
| 245 | + |
| 246 | + /* Infinite loop */ |
| 247 | + while (1); |
| 248 | +} |
| 249 | + |
| 250 | +/** |
| 251 | + * \brief Default interrupt handler for unused IRQs. |
| 252 | + */ |
| 253 | +void Dummy_Handler(void) |
| 254 | +{ |
| 255 | + while (1) { |
| 256 | + } |
| 257 | +} |
0 commit comments