SAMD21_Startup.s 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*****************************************************************************
  2. * SEGGER Microcontroller GmbH & Co. KG *
  3. * Solutions for real time microcontroller applications *
  4. *****************************************************************************
  5. * *
  6. * (c) 2017 SEGGER Microcontroller GmbH & Co. KG *
  7. * *
  8. * Internet: www.segger.com Support: support@segger.com *
  9. * *
  10. *****************************************************************************/
  11. /*****************************************************************************
  12. * Preprocessor Definitions *
  13. * ------------------------ *
  14. * NO_STACK_INIT *
  15. * *
  16. * If defined, the stack pointer will not be initialised. *
  17. * *
  18. * NO_SYSTEM_INIT *
  19. * *
  20. * If defined, the SystemInit() function will not be called. By default *
  21. * SystemInit() is called after reset to enable the clocks and memories to *
  22. * be initialised prior to any C startup initialisation. *
  23. * *
  24. * NO_VTOR_CONFIG *
  25. * *
  26. * If defined, the vector table offset register will not be configured. *
  27. * *
  28. * MEMORY_INIT *
  29. * *
  30. * If defined, the MemoryInit() function will be called. By default *
  31. * MemoryInit() is called after SystemInit() to enable an external memory *
  32. * controller. *
  33. * *
  34. * STACK_INIT_VAL *
  35. * *
  36. * If defined, specifies the initial stack pointer value. If undefined, *
  37. * the stack pointer will be initialised to point to the end of the *
  38. * RAM segment. *
  39. * *
  40. * VECTORS_IN_RAM *
  41. * *
  42. * If defined, the exception vectors will be copied from Flash to RAM. *
  43. * *
  44. *****************************************************************************/
  45. .syntax unified
  46. .global Reset_Handler
  47. .extern _vectors
  48. .section .init, "ax"
  49. .thumb_func
  50. .equ VTOR_REG, 0xE000ED08
  51. #ifndef STACK_INIT_VAL
  52. #define STACK_INIT_VAL __RAM_segment_end__
  53. #endif
  54. Reset_Handler:
  55. #ifndef NO_STACK_INIT
  56. /* Initialise main stack */
  57. ldr r0, =STACK_INIT_VAL
  58. ldr r1, =0x7
  59. bics r0, r1
  60. mov sp, r0
  61. #endif
  62. #ifndef NO_SYSTEM_INIT
  63. /* Initialise system */
  64. ldr r0, =SystemInit
  65. blx r0
  66. .pushsection .init_array, "aw", %init_array
  67. .word SystemCoreClockUpdate
  68. .popsection
  69. #endif
  70. #ifdef MEMORY_INIT
  71. ldr r0, =MemoryInit
  72. blx r0
  73. #endif
  74. #ifdef VECTORS_IN_RAM
  75. /* Copy exception vectors into RAM */
  76. ldr r0, =__vectors_start__
  77. ldr r1, =__vectors_end__
  78. ldr r2, =__vectors_ram_start__
  79. 1:
  80. cmp r0, r1
  81. beq 2f
  82. ldr r3, [r0]
  83. str r3, [r2]
  84. adds r0, r0, #4
  85. adds r2, r2, #4
  86. b 1b
  87. 2:
  88. #endif
  89. #ifndef NO_VTOR_CONFIG
  90. /* Configure vector table offset register */
  91. ldr r0, =VTOR_REG
  92. #ifdef VECTORS_IN_RAM
  93. ldr r1, =_vectors_ram
  94. #else
  95. ldr r1, =_vectors
  96. #endif
  97. str r1, [r0]
  98. #endif
  99. /* Jump to program start */
  100. b _start