|  | 
|  | 1 | +#include "samd21.h" | 
|  | 2 | + | 
|  | 3 | +/* Initialize segments */ | 
|  | 4 | +extern uint32_t _sfixed; | 
|  | 5 | +extern uint32_t _efixed; | 
|  | 6 | +extern uint32_t _etext; | 
|  | 7 | +extern uint32_t _srelocate; | 
|  | 8 | +extern uint32_t _erelocate; | 
|  | 9 | +extern uint32_t _szero; | 
|  | 10 | +extern uint32_t _ezero; | 
|  | 11 | +extern uint32_t _sstack; | 
|  | 12 | +extern uint32_t _estack; | 
|  | 13 | + | 
|  | 14 | +/** \cond DOXYGEN_SHOULD_SKIP_THIS */ | 
|  | 15 | +int main(void); | 
|  | 16 | +/** \endcond */ | 
|  | 17 | + | 
|  | 18 | +void __libc_init_array(void); | 
|  | 19 | + | 
|  | 20 | +/* Default empty handler */ | 
|  | 21 | +void Dummy_Handler(void); | 
|  | 22 | + | 
|  | 23 | +/* Cortex-M0+ core handlers */ | 
|  | 24 | +void NMI_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 25 | +void HardFault_Handler       ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 26 | +void SVC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 27 | +void PendSV_Handler          ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 28 | +void SysTick_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 29 | + | 
|  | 30 | +/* Peripherals handlers */ | 
|  | 31 | +void PM_Handler              ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 32 | +void SYSCTRL_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 33 | +void WDT_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 34 | +void RTC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 35 | +void EIC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 36 | +void NVMCTRL_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 37 | +void DMAC_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 38 | +void USB_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 39 | +void EVSYS_Handler           ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 40 | +void SERCOM0_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 41 | +void SERCOM1_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 42 | +void SERCOM2_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 43 | +void SERCOM3_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 44 | +void SERCOM4_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 45 | +void SERCOM5_Handler         ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 46 | +void TCC0_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 47 | +void TCC1_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 48 | +void TCC2_Handler            ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 49 | +void TC3_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 50 | +void TC4_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 51 | +void TC5_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 52 | +void TC6_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 53 | +void TC7_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 54 | +void ADC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 55 | +void AC_Handler              ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 56 | +void DAC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 57 | +void PTC_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 58 | +void I2S_Handler             ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); | 
|  | 59 | + | 
|  | 60 | +/* Exception Table */ | 
|  | 61 | +__attribute__ ((section(".vectors"))) | 
|  | 62 | +const DeviceVectors exception_table = { | 
|  | 63 | + | 
|  | 64 | +    /* Configure Initial Stack Pointer, using linker-generated symbols */ | 
|  | 65 | +    (void*) (&_estack), | 
|  | 66 | + | 
|  | 67 | +    (void*) Reset_Handler, | 
|  | 68 | +    (void*) NMI_Handler, | 
|  | 69 | +    (void*) HardFault_Handler, | 
|  | 70 | +    (void*) (0UL), /* Reserved */ | 
|  | 71 | +    (void*) (0UL), /* Reserved */ | 
|  | 72 | +    (void*) (0UL), /* Reserved */ | 
|  | 73 | +    (void*) (0UL), /* Reserved */ | 
|  | 74 | +    (void*) (0UL), /* Reserved */ | 
|  | 75 | +    (void*) (0UL), /* Reserved */ | 
|  | 76 | +    (void*) (0UL), /* Reserved */ | 
|  | 77 | +    (void*) SVC_Handler, | 
|  | 78 | +    (void*) (0UL), /* Reserved */ | 
|  | 79 | +    (void*) (0UL), /* Reserved */ | 
|  | 80 | +    (void*) PendSV_Handler, | 
|  | 81 | +    (void*) SysTick_Handler, | 
|  | 82 | + | 
|  | 83 | +    /* Configurable interrupts */ | 
|  | 84 | +    (void*) PM_Handler,             /*  0 Power Manager */ | 
|  | 85 | +    (void*) SYSCTRL_Handler,        /*  1 System Control */ | 
|  | 86 | +    (void*) WDT_Handler,            /*  2 Watchdog Timer */ | 
|  | 87 | +    (void*) RTC_Handler,            /*  3 Real-Time Counter */ | 
|  | 88 | +    (void*) EIC_Handler,            /*  4 External Interrupt Controller */ | 
|  | 89 | +    (void*) NVMCTRL_Handler,        /*  5 Non-Volatile Memory Controller */ | 
|  | 90 | +    (void*) DMAC_Handler,           /*  6 Direct Memory Access Controller */ | 
|  | 91 | +    (void*) USB_Handler,            /*  7 Universal Serial Bus */ | 
|  | 92 | +    (void*) EVSYS_Handler,          /*  8 Event System Interface */ | 
|  | 93 | +    (void*) SERCOM0_Handler,        /*  9 Serial Communication Interface 0 */ | 
|  | 94 | +    (void*) SERCOM1_Handler,        /* 10 Serial Communication Interface 1 */ | 
|  | 95 | +    (void*) SERCOM2_Handler,        /* 11 Serial Communication Interface 2 */ | 
|  | 96 | +    (void*) SERCOM3_Handler,        /* 12 Serial Communication Interface 3 */ | 
|  | 97 | +    (void*) SERCOM4_Handler,        /* 13 Serial Communication Interface 4 */ | 
|  | 98 | +    (void*) SERCOM5_Handler,        /* 14 Serial Communication Interface 5 */ | 
|  | 99 | +    (void*) TCC0_Handler,           /* 15 Timer Counter Control 0 */ | 
|  | 100 | +    (void*) TCC1_Handler,           /* 16 Timer Counter Control 1 */ | 
|  | 101 | +    (void*) TCC2_Handler,           /* 17 Timer Counter Control 2 */ | 
|  | 102 | +    (void*) TC3_Handler,            /* 18 Basic Timer Counter 0 */ | 
|  | 103 | +    (void*) TC4_Handler,            /* 19 Basic Timer Counter 1 */ | 
|  | 104 | +    (void*) TC5_Handler,            /* 20 Basic Timer Counter 2 */ | 
|  | 105 | +    (void*) TC6_Handler,            /* 21 Basic Timer Counter 3 */ | 
|  | 106 | +    (void*) TC7_Handler,            /* 22 Basic Timer Counter 4 */ | 
|  | 107 | +    (void*) ADC_Handler,            /* 23 Analog Digital Converter */ | 
|  | 108 | +    (void*) AC_Handler,             /* 24 Analog Comparators */ | 
|  | 109 | +    (void*) DAC_Handler,            /* 25 Digital Analog Converter */ | 
|  | 110 | +    (void*) PTC_Handler,            /* 26 Peripheral Touch Controller */ | 
|  | 111 | +    (void*) I2S_Handler             /* 27 Inter-IC Sound Interface */ | 
|  | 112 | +}; | 
|  | 113 | + | 
|  | 114 | +/** | 
|  | 115 | + * \brief This is the code that gets called on processor reset. | 
|  | 116 | + * To initialize the device, and call the main() routine. | 
|  | 117 | + */ | 
|  | 118 | +void Reset_Handler(void) | 
|  | 119 | +{ | 
|  | 120 | +    uint32_t *pSrc, *pDest; | 
|  | 121 | + | 
|  | 122 | +    /* Initialize the relocate segment */ | 
|  | 123 | +    pSrc = &_etext; | 
|  | 124 | +    pDest = &_srelocate; | 
|  | 125 | + | 
|  | 126 | +    if (pSrc != pDest) { | 
|  | 127 | +        for (; pDest < &_erelocate;) { | 
|  | 128 | +            *pDest++ = *pSrc++; | 
|  | 129 | +        } | 
|  | 130 | +    } | 
|  | 131 | + | 
|  | 132 | +    /* Clear the zero segment */ | 
|  | 133 | +    for (pDest = &_szero; pDest < &_ezero;) { | 
|  | 134 | +        *pDest++ = 0; | 
|  | 135 | +    } | 
|  | 136 | + | 
|  | 137 | +    /* Set the vector table base address */ | 
|  | 138 | +    pSrc = (uint32_t *) & _sfixed; | 
|  | 139 | +    SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk); | 
|  | 140 | + | 
|  | 141 | +    /* Initialize the C library */ | 
|  | 142 | +    __libc_init_array(); | 
|  | 143 | + | 
|  | 144 | +    /* Branch to main function */  // expected to be done by MBED OS | 
|  | 145 | +    main(); | 
|  | 146 | + | 
|  | 147 | +    /* Infinite loop */ | 
|  | 148 | +    while (1); | 
|  | 149 | +} | 
|  | 150 | + | 
|  | 151 | +/** | 
|  | 152 | + * \brief Default interrupt handler for unused IRQs. | 
|  | 153 | + */ | 
|  | 154 | +void Dummy_Handler(void) | 
|  | 155 | +{ | 
|  | 156 | +    while (1) { | 
|  | 157 | +    } | 
|  | 158 | +} | 
0 commit comments