2
0

startup.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* startup.c
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL 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; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* Startup routines for STM32L596G bare-metal example */
  22. extern unsigned int _stored_data;
  23. extern unsigned int _start_data;
  24. extern unsigned int _end_data;
  25. extern unsigned int _start_bss;
  26. extern unsigned int _end_bss;
  27. extern unsigned int _end_stack;
  28. extern unsigned int _start_heap;
  29. //#define STACK_PAINTING
  30. static volatile unsigned int avail_mem = 0;
  31. #ifdef STACK_PAINTING
  32. static unsigned int stack_ptr;
  33. #endif
  34. extern void isr_usart1(void);
  35. extern void main(void);
  36. void isr_reset(void) {
  37. register unsigned int *src, *dst;
  38. src = (unsigned int *) &_stored_data;
  39. dst = (unsigned int *) &_start_data;
  40. /* Copy the .data section from flash to RAM. */
  41. while (dst < (unsigned int *)&_end_data) {
  42. *dst = *src;
  43. dst++;
  44. src++;
  45. }
  46. /* Initialize the BSS section to 0 */
  47. dst = &_start_bss;
  48. while (dst < (unsigned int *)&_end_bss) {
  49. *dst = 0U;
  50. dst++;
  51. }
  52. /* Paint the stack. */
  53. avail_mem = &_end_stack - &_start_heap;
  54. #ifdef STACK_PAINTING
  55. {
  56. asm volatile("mrs %0, msp" : "=r"(stack_ptr));
  57. dst = ((unsigned int *)(&_end_stack)) - (8192 / sizeof(unsigned int)); ;
  58. while ((unsigned int)dst < stack_ptr) {
  59. *dst = 0xDEADC0DE;
  60. dst++;
  61. }
  62. }
  63. #endif
  64. /* Run the program! */
  65. main();
  66. }
  67. void isr_fault(void)
  68. {
  69. /* Panic. */
  70. while(1) ;;
  71. }
  72. void isr_memfault(void)
  73. {
  74. /* Panic. */
  75. while(1) ;;
  76. }
  77. void isr_busfault(void)
  78. {
  79. /* Panic. */
  80. while(1) ;;
  81. }
  82. void isr_usagefault(void)
  83. {
  84. /* Panic. */
  85. while(1) ;;
  86. }
  87. void isr_empty(void)
  88. {
  89. /* Ignore the event and continue */
  90. }
  91. volatile unsigned jiffies = 0;
  92. void isr_systick(void)
  93. {
  94. jiffies++;
  95. }
  96. __attribute__ ((section(".isr_vector")))
  97. void (* const IV[])(void) =
  98. {
  99. (void (*)(void))(&_end_stack),
  100. isr_reset, // Reset
  101. isr_fault, // NMI
  102. isr_fault, // HardFault
  103. isr_memfault, // MemFault
  104. isr_busfault, // BusFault
  105. isr_usagefault, // UsageFault
  106. 0, 0, 0, 0, // 4x reserved
  107. isr_empty, // SVC
  108. isr_empty, // DebugMonitor
  109. 0, // reserved
  110. isr_empty, // PendSV
  111. isr_systick, // SysTick
  112. isr_empty, // NVIC_WWDG_IRQ 0
  113. isr_empty, // PVD_IRQ 1
  114. isr_empty, // TAMP_STAMP_IRQ 2
  115. isr_empty, // RTC_WKUP_IRQ 3
  116. isr_empty, // FLASH_IRQ 4
  117. isr_empty, // RCC_IRQ 5
  118. isr_empty, // EXTI0_IRQ 6
  119. isr_empty, // EXTI1_IRQ 7
  120. isr_empty, // EXTI2_IRQ 8
  121. isr_empty, // EXTI3_IRQ 9
  122. isr_empty, // EXTI4_IRQ 10
  123. isr_empty, // DMA1_STREAM0_IRQ 11
  124. isr_empty, // DMA1_STREAM1_IRQ 12
  125. isr_empty, // DMA1_STREAM2_IRQ 13
  126. isr_empty, // DMA1_STREAM3_IRQ 14
  127. isr_empty, // DMA1_STREAM4_IRQ 15
  128. isr_empty, // DMA1_STREAM5_IRQ 16
  129. isr_empty, // DMA1_STREAM6_IRQ 17
  130. isr_empty, // ADC_IRQ 18
  131. isr_empty, // CAN1_TX_IRQ 19
  132. isr_empty, // CAN1_RX0_IRQ 20
  133. isr_empty, // CAN1_RX1_IRQ 21
  134. isr_empty, // CAN1_SCE_IRQ 22
  135. isr_empty, // EXTI9_5_IRQ 23
  136. isr_empty, // TIM1_BRK_TIM9_IRQ 24
  137. isr_empty, // TIM1_UP_TIM10_IRQ 25
  138. isr_empty, // TIM1_TRG_COM_TIM11_IRQ 26
  139. isr_empty, // TIM1_CC_IRQ 27
  140. isr_empty, // TIM2_IRQ 28
  141. isr_empty, // TIM3_IRQ 29
  142. isr_empty, // TIM4_IRQ 30
  143. isr_empty, // I2C1_EV_IRQ 31
  144. isr_empty, // I2C1_ER_IRQ 32
  145. isr_empty, // I2C2_EV_IRQ 33
  146. isr_empty, // I2C2_ER_IRQ 34
  147. isr_empty, // SPI1_IRQ 35
  148. isr_empty, // SPI2_IRQ 36
  149. isr_usart1, // USART1_IRQ 37
  150. isr_empty, // USART2_IRQ 38
  151. isr_empty, // USART3_IRQ 39
  152. isr_empty, // EXTI15_10_IRQ 40
  153. isr_empty, // RTC_ALARM_IRQ 41
  154. isr_empty, // USB_FS_WKUP_IRQ 42
  155. isr_empty, // TIM8_BRK_TIM12_IRQ 43
  156. isr_empty, // TIM8_UP_TIM13_IRQ 44
  157. isr_empty, // TIM8_TRG_COM_TIM14_IRQ 45
  158. isr_empty, // TIM8_CC_IRQ 46
  159. isr_empty, // DMA1_STREAM7_IRQ 47
  160. isr_empty, // FSMC_IRQ
  161. isr_empty, // SDIO_IRQ
  162. isr_empty, // TIM5_IRQ
  163. isr_empty, // SPI3_IRQ
  164. isr_empty, // UART4_IRQ
  165. isr_empty, // UART5_IRQ
  166. isr_empty, // TIM6_DAC_IRQ
  167. isr_empty, // TIM7_IRQ
  168. isr_empty, // DMA2_STREAM0_IRQ
  169. isr_empty, // DMA2_STREAM1_IRQ
  170. isr_empty, // DMA2_STREAM2_IRQ
  171. isr_empty, // DMA2_STREAM3_IRQ
  172. isr_empty, // DMA2_STREAM4_IRQ
  173. isr_empty, // ETH_IRQ
  174. isr_empty, // ETH_WKUP_IRQ
  175. isr_empty, // CAN2_TX_IRQ
  176. isr_empty, // CAN2_RX0_IRQ
  177. isr_empty, // CAN2_RX1_IRQ
  178. isr_empty, // CAN2_SCE_IRQ
  179. isr_empty, // OTG_FS_IRQ
  180. isr_empty, // DMA2_STREAM5_IRQ
  181. isr_empty, // DMA2_STREAM6_IRQ
  182. isr_empty, // DMA2_STREAM7_IRQ
  183. isr_empty, // USART6_IRQ
  184. isr_empty, // I2C3_EV_IRQ
  185. isr_empty, // I2C3_ER_IRQ
  186. isr_empty, // OTG_HS_EP1_OUT_IRQ
  187. isr_empty, // OTG_HS_EP1_IN_IRQ
  188. isr_empty, // OTG_HS_WKUP_IRQ
  189. isr_empty, // OTG_HS_IRQ
  190. isr_empty, // DCMI_IRQ
  191. isr_empty, // CRYP_IRQ
  192. isr_empty, // HASH_RNG_IRQ
  193. isr_empty, // FPU_IRQ
  194. isr_empty, // UART7_IRQ
  195. isr_empty, // UART8_IRQ
  196. isr_empty, // SPI4_IRQ
  197. isr_empty, // SPI5_IRQ
  198. isr_empty, // SPI6_IRQ
  199. isr_empty, // SAI1_IRQ
  200. isr_empty, // LCD_TFT_IRQ
  201. isr_empty, // LCD_TFT_ERR_IRQ
  202. isr_empty, // DMA2D_IRQ
  203. };