新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > IAR的stm32f10x_vector.c文件的定義

IAR的stm32f10x_vector.c文件的定義

作者: 時(shí)間:2016-11-10 來(lái)源:網(wǎng)絡(luò) 收藏
  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name : stm32f10x_vector.c
  3. * Author : MCD Application Team
  4. * Version : V2.0.3
  5. * Date : 09/22/2008
  6. * Description : STM32F10x vector table for EWARM5.x toolchain.
  7. * This module performs:
  8. * - Set the initial SP
  9. * - Set the initial PC == __iar_program_start,
  10. * - Set the vector table entries with the exceptions ISR address,
  11. * - Configure external SRAM mounted on STM3210E-EVAL board
  12. * to be used as data memory (optional, to be enabled by user)
  13. * After Reset the Cortex-M3 processor is in Thread mode,
  14. * priority is Privileged, and the Stack is set to Main.
  15. ********************************************************************************
  16. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  17. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  18. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  19. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  20. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  21. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  22. *******************************************************************************/
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32f10x_lib.h"
  25. #include "stm32f10x_it.h"
  26. /* Private typedef -----------------------------------------------------------*/
  27. typedef void( *intfunc )( void );
  28. typedef union { intfunc __fun; void * __ptr; } intvec_elem;
  29. /* Private define ------------------------------------------------------------*/
  30. /* Uncomment the following line if you need to use external SRAM mounted on
  31. STM3210E-EVAL board as data memory */
  32. /* #define DATA_IN_ExtSRAM */
  33. /* Private macro -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private function prototypes -----------------------------------------------*/
  36. /* Private functions ---------------------------------------------------------*/
  37. #pragma language=extended
  38. #pragma segment="CSTACK"
  39. void __iar_program_start( void );
  40. #pragma location = ".intvec"
  41. /* STM32F10x Vector Table entries */
  42. const intvec_elem __vector_table[] =
  43. {
  44. { .__ptr = __sfe( "CSTACK" ) },
  45. __iar_program_start,
  46. NMIException,
  47. HardFaultException,
  48. MemManageException,
  49. BusFaultException,
  50. UsageFaultException,
  51. 0, 0, 0, 0, /* Reserved */
  52. SVCHandler,
  53. DebugMonitor,
  54. 0, /* Reserved */
  55. PendSVC,
  56. SysTickHandler,
  57. WWDG_IRQHandler,
  58. PVD_IRQHandler,
  59. TAMPER_IRQHandler,
  60. RTC_IRQHandler,
  61. FLASH_IRQHandler,
  62. RCC_IRQHandler,
  63. EXTI0_IRQHandler,
  64. EXTI1_IRQHandler,
  65. EXTI2_IRQHandler,
  66. EXTI3_IRQHandler,
  67. EXTI4_IRQHandler,
  68. DMA1_Channel1_IRQHandler,
  69. DMA1_Channel2_IRQHandler,
  70. DMA1_Channel3_IRQHandler,
  71. DMA1_Channel4_IRQHandler,
  72. DMA1_Channel5_IRQHandler,
  73. DMA1_Channel6_IRQHandler,
  74. DMA1_Channel7_IRQHandler,
  75. ADC1_2_IRQHandler,
  76. USB_HP_CAN_TX_IRQHandler,
  77. USB_LP_CAN_RX0_IRQHandler,
  78. CAN_RX1_IRQHandler,
  79. CAN_SCE_IRQHandler,
  80. EXTI9_5_IRQHandler,
  81. TIM1_BRK_IRQHandler,
  82. TIM1_UP_IRQHandler,
  83. TIM1_TRG_COM_IRQHandler,
  84. TIM1_CC_IRQHandler,
  85. TIM2_IRQHandler,
  86. TIM3_IRQHandler,
  87. TIM4_IRQHandler,
  88. I2C1_EV_IRQHandler,
  89. I2C1_ER_IRQHandler,
  90. I2C2_EV_IRQHandler,
  91. I2C2_ER_IRQHandler,
  92. SPI1_IRQHandler,
  93. SPI2_IRQHandler,
  94. USART1_IRQHandler,
  95. USART2_IRQHandler,
  96. USART3_IRQHandler,
  97. EXTI15_10_IRQHandler,
  98. RTCAlarm_IRQHandler,
  99. USBWakeUp_IRQHandler,
  100. TIM8_BRK_IRQHandler,
  101. TIM8_UP_IRQHandler,
  102. TIM8_TRG_COM_IRQHandler,
  103. TIM8_CC_IRQHandler,
  104. ADC3_IRQHandler,
  105. FSMC_IRQHandler,
  106. SDIO_IRQHandler,
  107. TIM5_IRQHandler,
  108. SPI3_IRQHandler,
  109. UART4_IRQHandler,
  110. UART5_IRQHandler,
  111. TIM6_IRQHandler,
  112. TIM7_IRQHandler,
  113. DMA2_Channel1_IRQHandler,
  114. DMA2_Channel2_IRQHandler,
  115. DMA2_Channel3_IRQHandler,
  116. DMA2_Channel4_5_IRQHandler,
  117. };
  118. #ifdef DATA_IN_ExtSRAM
  119. #pragma language=extended
  120. __interwork int __low_level_init(void);
  121. #pragma location="ICODE"
  122. __interwork int __low_level_init(void)
  123. {
  124. /* FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
  125. required, then adjust the Register Addresses*/
  126. /* Enable FSMC clock */
  127. *(vu32 *)0x40021014 = 0x00000114;
  128. /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
  129. *(vu32 *)0x40021018 = 0x000001E0;
  130. /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
  131. /*---------------- SRAM Address lines configuration -------------------------*/
  132. /*---------------- NOE and NWE configuration --------------------------------*/
  133. /*---------------- NE3 configuration ----------------------------------------*/
  134. /*---------------- NBL0, NBL1 configuration ---------------------------------*/
  135. *(vu32 *)0x40011400 = 0x44BB44BB;
  136. *(vu32 *)0x40011404 = 0xBBBBBBBB;
  137. *(vu32 *)0x40011800 = 0xB44444BB;
  138. *(vu32 *)0x40011804 = 0xBBBBBBBB;
  139. *(vu32 *)0x40011C00 = 0x44BBBBBB;
  140. *(vu32 *)0x40011C04 = 0xBBBB4444;
  141. *(vu32 *)0x40012000 = 0x44BBBBBB;
  142. *(vu32 *)0x40012004 = 0x44444B44;
  143. /*---------------- FSMC Configuration ---------------------------------------*/
  144. /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
  145. *(vu32 *)0xA0000010 = 0x00001011;
  146. *(vu32 *)0xA0000014 = 0x00000200;
  147. return (1);
  148. }
  149. #endif /*DATA_IN_ExtSRAM*/
  150. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
typedef void( *intfunc )( void );
定義一個(gè)新類(lèi)型,這個(gè)類(lèi)型是一個(gè)函數(shù)指針,指針指向的函數(shù)類(lèi)型是void (void)型,
符合標(biāo)準(zhǔn)C
typedef union { intfunc __fun; void * __ptr; } intvec_elem;
定義一個(gè)新類(lèi)型,這個(gè)類(lèi)型是一個(gè)聯(lián)合體,聯(lián)合體有兩個(gè)元素,一個(gè)元素類(lèi)型是intfunc,一個(gè)元素類(lèi)型是void *
符合標(biāo)準(zhǔn)C
#pragma language=extended
#pragma segment="CSTACK"
void __iar_program_start( void );
申明外部函數(shù),extern可以用,也可以不用
符合標(biāo)準(zhǔn)C
#pragma location = ".intvec" // 下面的變量存放在段 .intvec
//IAR擴(kuò)展
/* STM32F10x Vector Table entries */
const intvec_elem __vector_table[] =
{
{ .__ptr = __sfe( "CSTACK" ) },
// { .__ptr = 常量 },
// 數(shù)組元素是聯(lián)合體,聯(lián)合體有兩個(gè)元素,對(duì)聯(lián)合體元素__ptr賦初值
//符合標(biāo)準(zhǔn)C
//__sfe( "CSTACK" ) 是段CSTACK的尾地址,更準(zhǔn)確是段CSTACK下一個(gè)段的首地址(記憶中應(yīng)該是這樣)。
//IAR擴(kuò)展
__iar_program_start,
//數(shù)組元素是聯(lián)合體,聯(lián)合體有兩個(gè)元素,對(duì)聯(lián)合體第一個(gè)元素__fun賦初值
//完整的寫(xiě)法是 { .__fun= __iar_program_start },
//這里簡(jiǎn)寫(xiě)成__iar_program_start,是否符合標(biāo)準(zhǔn)C,有待考證
.....
}
}
補(bǔ)充:
對(duì)聯(lián)合體第一個(gè)元素賦初值,可以簡(jiǎn)寫(xiě)。
{ .__fun= __iar_program_start },
//__fun是聯(lián)合體第一個(gè)元素,可直接簡(jiǎn)寫(xiě)成__iar_program_start.
//符合標(biāo)準(zhǔn)C
__sfe是IAR的“段操作符”segment operator。表示取某個(gè)段的后一個(gè)字節(jié)的地址。
比如"CSTACK"定義為0x20001000~0x20001fff。那__sfe( "CSTACK" ) 就得到0x20002000這個(gè)值,剛好用來(lái)初始化msp堆棧指針
注意使用segment operator前,需要先定義段名如下:
#pragma segment="CSTACK"


關(guān)鍵詞: IARstm32f10xvector.c文

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉