startup_nrf52840.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2017 Glenn Ruben Bakke
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include <stdint.h>
  27. extern uint32_t _estack;
  28. extern uint32_t _sidata;
  29. extern uint32_t _sdata;
  30. extern uint32_t _edata;
  31. extern uint32_t _sbss;
  32. extern uint32_t _ebss;
  33. typedef void (*func)(void);
  34. extern void _start(void) __attribute__((noreturn));
  35. extern void SystemInit(void);
  36. void Default_Handler(void) {
  37. while (1);
  38. }
  39. void Reset_Handler(void) {
  40. uint32_t * p_src = &_sidata;
  41. uint32_t * p_dest = &_sdata;
  42. while (p_dest < &_edata) {
  43. *p_dest++ = *p_src++;
  44. }
  45. uint32_t * p_bss = &_sbss;
  46. uint32_t * p_bss_end = &_ebss;
  47. while (p_bss < p_bss_end) {
  48. *p_bss++ = 0ul;
  49. }
  50. SystemInit();
  51. _start();
  52. }
  53. void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  54. void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  55. void MemoryManagement_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  56. void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  57. void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  58. void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  59. void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  60. void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  61. void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  62. void POWER_CLOCK_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  63. void RADIO_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  64. void UARTE0_UART0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  65. void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  66. void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  67. void NFCT_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  68. void GPIOTE_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  69. void SAADC_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  70. void TIMER0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  71. void TIMER1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  72. void TIMER2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  73. void RTC0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  74. void TEMP_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  75. void RNG_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  76. void ECB_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  77. void CCM_AAR_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  78. void WDT_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  79. void RTC1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  80. void QDEC_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  81. void COMP_LPCOMP_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  82. void SWI0_EGU0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  83. void SWI1_EGU1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  84. void SWI2_EGU2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  85. void SWI3_EGU3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  86. void SWI4_EGU4_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  87. void SWI5_EGU5_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  88. void TIMER3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  89. void TIMER4_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  90. void PWM0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  91. void PDM_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  92. void MWU_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  93. void PWM1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  94. void PWM2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  95. void SPIM2_SPIS2_SPI2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  96. void RTC2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  97. void I2S_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  98. void FPU_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  99. void USBD_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  100. void UARTE1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  101. void QSPI_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  102. void CRYPTOCELL_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  103. void SPIM3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  104. void PWM3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  105. const func __Vectors[] __attribute__ ((section(".isr_vector"),used)) = {
  106. (func)&_estack,
  107. Reset_Handler,
  108. NMI_Handler,
  109. HardFault_Handler,
  110. MemoryManagement_Handler,
  111. BusFault_Handler,
  112. UsageFault_Handler,
  113. 0,
  114. 0,
  115. 0,
  116. 0,
  117. SVC_Handler,
  118. DebugMon_Handler,
  119. 0,
  120. PendSV_Handler,
  121. SysTick_Handler,
  122. /* External Interrupts */
  123. POWER_CLOCK_IRQHandler,
  124. RADIO_IRQHandler,
  125. UARTE0_UART0_IRQHandler,
  126. SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler,
  127. SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler,
  128. NFCT_IRQHandler,
  129. GPIOTE_IRQHandler,
  130. SAADC_IRQHandler,
  131. TIMER0_IRQHandler,
  132. TIMER1_IRQHandler,
  133. TIMER2_IRQHandler,
  134. RTC0_IRQHandler,
  135. TEMP_IRQHandler,
  136. RNG_IRQHandler,
  137. ECB_IRQHandler,
  138. CCM_AAR_IRQHandler,
  139. WDT_IRQHandler,
  140. RTC1_IRQHandler,
  141. QDEC_IRQHandler,
  142. COMP_LPCOMP_IRQHandler,
  143. SWI0_EGU0_IRQHandler,
  144. SWI1_EGU1_IRQHandler,
  145. SWI2_EGU2_IRQHandler,
  146. SWI3_EGU3_IRQHandler,
  147. SWI4_EGU4_IRQHandler,
  148. SWI5_EGU5_IRQHandler,
  149. TIMER3_IRQHandler,
  150. TIMER4_IRQHandler,
  151. PWM0_IRQHandler,
  152. PDM_IRQHandler,
  153. 0,
  154. 0,
  155. MWU_IRQHandler,
  156. PWM1_IRQHandler,
  157. PWM2_IRQHandler,
  158. SPIM2_SPIS2_SPI2_IRQHandler,
  159. RTC2_IRQHandler,
  160. I2S_IRQHandler,
  161. FPU_IRQHandler,
  162. USBD_IRQHandler,
  163. UARTE1_IRQHandler,
  164. QSPI_IRQHandler,
  165. CRYPTOCELL_IRQHandler,
  166. SPIM3_IRQHandler,
  167. 0,
  168. PWM3_IRQHandler,
  169. };