startup_nrf51822.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 * ram_on_addr = (uint32_t *)0x40000524;
  41. uint32_t * ram_on_b_addr = (uint32_t *)0x40000554;
  42. // RAM on in on-mode
  43. *ram_on_addr = 3; // block 0 and 1
  44. *ram_on_b_addr = 3; // block 2 and 3
  45. #if 0
  46. // RAM on in off-mode
  47. ram_on_addr = 1 << 16;
  48. ram_on_b_addr = 1 << 17;
  49. #endif
  50. uint32_t * p_src = &_sidata;
  51. uint32_t * p_dest = &_sdata;
  52. while (p_dest < &_edata) {
  53. *p_dest++ = *p_src++;
  54. }
  55. uint32_t * p_bss = &_sbss;
  56. uint32_t * p_bss_end = &_ebss;
  57. while (p_bss < p_bss_end) {
  58. *p_bss++ = 0ul;
  59. }
  60. SystemInit();
  61. _start();
  62. }
  63. void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  64. void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  65. void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  66. void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  67. void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  68. void POWER_CLOCK_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  69. void RADIO_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  70. void UART0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  71. void SPI0_TWI0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  72. void SPI1_TWI1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  73. void GPIOTE_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  74. void ADC_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  75. void TIMER0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  76. void TIMER1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  77. void TIMER2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  78. void RTC0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  79. void TEMP_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  80. void RNG_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  81. void ECB_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  82. void CCM_AAR_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  83. void WDT_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  84. void RTC1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  85. void QDEC_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  86. void LPCOMP_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  87. void SWI0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  88. void SWI1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  89. void SWI2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  90. void SWI3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  91. void SWI4_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  92. void SWI5_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
  93. const func __Vectors[] __attribute__ ((section(".isr_vector"),used)) = {
  94. (func)&_estack,
  95. Reset_Handler,
  96. NMI_Handler,
  97. HardFault_Handler,
  98. 0,
  99. 0,
  100. 0,
  101. 0,
  102. 0,
  103. 0,
  104. 0,
  105. SVC_Handler,
  106. 0,
  107. 0,
  108. PendSV_Handler,
  109. SysTick_Handler,
  110. /* External Interrupts */
  111. POWER_CLOCK_IRQHandler,
  112. RADIO_IRQHandler,
  113. UART0_IRQHandler,
  114. SPI0_TWI0_IRQHandler,
  115. SPI1_TWI1_IRQHandler,
  116. 0,
  117. GPIOTE_IRQHandler,
  118. ADC_IRQHandler,
  119. TIMER0_IRQHandler,
  120. TIMER1_IRQHandler,
  121. TIMER2_IRQHandler,
  122. RTC0_IRQHandler,
  123. TEMP_IRQHandler,
  124. RNG_IRQHandler,
  125. ECB_IRQHandler,
  126. CCM_AAR_IRQHandler,
  127. WDT_IRQHandler,
  128. RTC1_IRQHandler,
  129. QDEC_IRQHandler,
  130. LPCOMP_IRQHandler,
  131. SWI0_IRQHandler,
  132. SWI1_IRQHandler,
  133. SWI2_IRQHandler,
  134. SWI3_IRQHandler,
  135. SWI4_IRQHandler,
  136. SWI5_IRQHandler
  137. };