startup_stm32f0xx.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * STM32F030 Linkerscript
  3. * Copyright (C) 2019 Stefan Strobel <stefan.strobel@shimatta.net>
  4. *
  5. * This file is part of 'STM32F0 code template'.
  6. *
  7. * It is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, version 2 of the License.
  10. *
  11. * This code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this template. If not, see <http://www.gnu.org/licenses/>.
  18. * ------------------------------------------------------------------------
  19. */
  20. /* C++ library init */
  21. # if defined(__cplusplus)
  22. extern "C" {
  23. extern void __libc_init_array(void);
  24. }
  25. #endif
  26. /* Defines for weak default handlers */
  27. #define WEAK __attribute__((weak))
  28. #define ALIAS(func) __attribute__ ((weak, alias (#func)))
  29. /* Define for section mapping */
  30. #define SECTION(sec) __attribute__((section(sec)))
  31. /* Handler prototypes */
  32. #if defined(_cplusplus)
  33. extern "C" {
  34. #endif
  35. /* Interrupt Defualt handler */
  36. WEAK void __int_default_handler(void);
  37. /* Core Interrupts */
  38. void Reset_Handler(void);
  39. void NMI_Handler(void) ALIAS(__int_default_handler);
  40. void HardFault_Handler(void) ALIAS(__int_default_handler);
  41. void SVCall_Handler(void) ALIAS(__int_default_handler);
  42. void PendSV_Handler(void) ALIAS(__int_default_handler);
  43. void SysTick_Handler(void) ALIAS(__int_default_handler);
  44. /* Peripheral Interrupts (by default mapped onto Default Handler) */
  45. void WWDG_IRQHandler(void) ALIAS(__int_default_handler);
  46. void PVD_VDDIO2_IRQHandler(void) ALIAS(__int_default_handler);
  47. void RTC_IRQHandler(void) ALIAS(__int_default_handler);
  48. void FLASH_IRQHandler(void) ALIAS(__int_default_handler);
  49. void RCC_CRS_IRQHandler(void) ALIAS(__int_default_handler);
  50. void EXTI0_1_IRQHandler(void) ALIAS(__int_default_handler);
  51. void EXTI2_3_IRQHandler(void) ALIAS(__int_default_handler);
  52. void EXTI4_15_IRQHandler(void) ALIAS(__int_default_handler);
  53. void TSC_IRWHandler(void) ALIAS(__int_default_handler);
  54. void DMA_CH1_IRQHandler(void) ALIAS(__int_default_handler);
  55. void DMA_CH2_3_DMA2_CH1_2_IRQHandler(void) ALIAS(__int_default_handler);
  56. void DMA_CH4_5_6_7_DMA2_CH3_4_5_IRQHandler(void) ALIAS(__int_default_handler);
  57. void ADC_COMP_IRQHandler(void) ALIAS(__int_default_handler);
  58. void TIM1_BRK_UP_TRG_COM_IRQHandler(void) ALIAS(__int_default_handler);
  59. void TIM1_CC_IRQHandler(void) ALIAS(__int_default_handler);
  60. void TIM2_IRQHandler(void) ALIAS(__int_default_handler);
  61. void TIM3_IRQHandler(void) ALIAS(__int_default_handler);
  62. void TIM6_DAC_IRQHandler(void) ALIAS(__int_default_handler);
  63. void TIM7_IRQHandler(void) ALIAS(__int_default_handler);
  64. void TIM14_IRQHandler(void) ALIAS(__int_default_handler);
  65. void TIM15_IRQHandler(void) ALIAS(__int_default_handler);
  66. void TIM16_IRQHandler(void) ALIAS(__int_default_handler);
  67. void TIM17_IRQHandler(void) ALIAS(__int_default_handler);
  68. void I2C1_IRQHandler(void) ALIAS(__int_default_handler);
  69. void I2C2_IRQHandler(void) ALIAS(__int_default_handler);
  70. void SPI1_IRQHandler(void) ALIAS(__int_default_handler);
  71. void SPI2_IRQHandler(void) ALIAS(__int_default_handler);
  72. void USART1_IRQHandler(void) ALIAS(__int_default_handler);
  73. void USART2_IRQHandler(void) ALIAS(__int_default_handler);
  74. void USART3_4_5_6_7_8_IRQHandler(void) ALIAS(__int_default_handler);
  75. void CEC_CAN_IRQHandler(void) ALIAS(__int_default_handler);
  76. void USB_IRQHandler(void) ALIAS(__int_default_handler);
  77. extern int main(void);
  78. extern void __system_init(void);
  79. extern void __ld_top_of_stack(void);
  80. #if defined(_cplusplus)
  81. extern "C" }
  82. #endif
  83. void (* const vector_table[])(void) SECTION(".vectors") = {
  84. &__ld_top_of_stack,
  85. /* Core Interrupts */
  86. Reset_Handler,
  87. NMI_Handler,
  88. HardFault_Handler,
  89. 0,
  90. 0,
  91. 0,
  92. 0,
  93. 0,
  94. 0,
  95. 0,
  96. SVCall_Handler,
  97. 0,
  98. 0,
  99. PendSV_Handler,
  100. SysTick_Handler,
  101. /* Peripheral Interrupts */
  102. WWDG_IRQHandler,
  103. PVD_VDDIO2_IRQHandler,
  104. RTC_IRQHandler,
  105. FLASH_IRQHandler,
  106. RCC_CRS_IRQHandler,
  107. EXTI0_1_IRQHandler,
  108. EXTI2_3_IRQHandler,
  109. EXTI4_15_IRQHandler,
  110. TSC_IRWHandler,
  111. DMA_CH1_IRQHandler,
  112. DMA_CH2_3_DMA2_CH1_2_IRQHandler,
  113. DMA_CH4_5_6_7_DMA2_CH3_4_5_IRQHandler,
  114. ADC_COMP_IRQHandler,
  115. TIM1_BRK_UP_TRG_COM_IRQHandler,
  116. TIM1_CC_IRQHandler,
  117. TIM2_IRQHandler,
  118. TIM3_IRQHandler,
  119. TIM6_DAC_IRQHandler,
  120. TIM7_IRQHandler,
  121. TIM14_IRQHandler,
  122. TIM15_IRQHandler,
  123. TIM16_IRQHandler,
  124. TIM17_IRQHandler,
  125. I2C1_IRQHandler,
  126. I2C2_IRQHandler,
  127. SPI1_IRQHandler,
  128. SPI2_IRQHandler,
  129. USART1_IRQHandler,
  130. USART2_IRQHandler,
  131. USART3_4_5_6_7_8_IRQHandler,
  132. CEC_CAN_IRQHandler,
  133. USB_IRQHandler,
  134. };
  135. static void __init_section(unsigned int *src_start, unsigned int *dest_start, unsigned int *dest_end) {
  136. unsigned int *get, *put;
  137. put = dest_start;
  138. get = src_start;
  139. while ((unsigned int)put < (unsigned int)dest_end) {
  140. *(put++) = *(get++);
  141. }
  142. }
  143. static void __fill_zero(unsigned int *start, unsigned int *end) {
  144. while ((unsigned int) start < (unsigned int)end) {
  145. *(start++) = 0x00000000;
  146. }
  147. }
  148. extern unsigned int __ld_load_data;
  149. extern unsigned int __ld_sitcm;
  150. extern unsigned int __ld_eitcm;
  151. extern unsigned int __ld_sdtcm;
  152. extern unsigned int __ld_edtcm;
  153. extern unsigned int __ld_sdata;
  154. extern unsigned int __ld_edata;
  155. extern unsigned int __ld_sbss;
  156. extern unsigned int __ld_ebss;
  157. extern unsigned int __ld_sheap;
  158. extern unsigned int __ld_eheap;
  159. void Reset_Handler(void) {
  160. /* Stack is already initilized by hardware */
  161. /* Copy .data section */
  162. __init_section(&__ld_load_data, &__ld_sdata, &__ld_edata);
  163. /* Fill bss with zero */
  164. __fill_zero(&__ld_sbss, &__ld_ebss);
  165. /* Fill Heap with zero */
  166. __fill_zero(&__ld_sheap, &__ld_eheap);
  167. /* Set clocks, waitstates, ART operation etc. */
  168. __system_init();
  169. /* C++ init function */
  170. #if defined(__cplusplus)
  171. __libc_init_array();
  172. #endif
  173. /* Call main */
  174. main();
  175. /* Catch return from main() */
  176. while(1);
  177. }
  178. WEAK void __int_default_handler(void)
  179. {
  180. while(1);
  181. }