- /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
- * File Name : stm32f10x_vector.c
- * Author : MCD Application Team
- * Version : V2.0.3
- * Date : 09/22/2008
- * Description : STM32F10x vector table for EWARM5.x toolchain.
- * This module performs:
- * - Set the initial SP
- * - Set the initial PC == __iar_program_start,
- * - Set the vector table entries with the exceptions ISR address,
- * - Configure external SRAM mounted on STM3210E-EVAL board
- * to be used as data memory (optional, to be enabled by user)
- * After Reset the Cortex-M3 processor is in Thread mode,
- * priority is Privileged, and the Stack is set to Main.
- ********************************************************************************
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
- * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
- * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
- * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
- * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *******************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x_lib.h"
- #include "stm32f10x_it.h"
- /* Private typedef -----------------------------------------------------------*/
- typedef void( *intfunc )( void );
- typedef union { intfunc __fun; void * __ptr; } intvec_elem;
- /* Private define ------------------------------------------------------------*/
- /* Uncomment the following line if you need to use external SRAM mounted on
- STM3210E-EVAL board as data memory */
- /* #define DATA_IN_ExtSRAM */
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- #pragma language=extended
- #pragma segment="CSTACK"
- void __iar_program_start( void );
- #pragma location = ".intvec"
- /* STM32F10x Vector Table entries */
- const intvec_elem __vector_table[] =
- {
- { .__ptr = __sfe( "CSTACK" ) },
- __iar_program_start,
- NMIException,
- HardFaultException,
- MemManageException,
- BusFaultException,
- UsageFaultException,
- 0, 0, 0, 0, /* Reserved */
- SVCHandler,
- DebugMonitor,
- 0, /* Reserved */
- PendSVC,
- SysTickHandler,
- WWDG_IRQHandler,
- PVD_IRQHandler,
- TAMPER_IRQHandler,
- RTC_IRQHandler,
- FLASH_IRQHandler,
- RCC_IRQHandler,
- EXTI0_IRQHandler,
- EXTI1_IRQHandler,
- EXTI2_IRQHandler,
- EXTI3_IRQHandler,
- EXTI4_IRQHandler,
- DMA1_Channel1_IRQHandler,
- DMA1_Channel2_IRQHandler,
- DMA1_Channel3_IRQHandler,
- DMA1_Channel4_IRQHandler,
- DMA1_Channel5_IRQHandler,
- DMA1_Channel6_IRQHandler,
- DMA1_Channel7_IRQHandler,
- ADC1_2_IRQHandler,
- USB_HP_CAN_TX_IRQHandler,
- USB_LP_CAN_RX0_IRQHandler,
- CAN_RX1_IRQHandler,
- CAN_SCE_IRQHandler,
- EXTI9_5_IRQHandler,
- TIM1_BRK_IRQHandler,
- TIM1_UP_IRQHandler,
- TIM1_TRG_COM_IRQHandler,
- TIM1_CC_IRQHandler,
- TIM2_IRQHandler,
- TIM3_IRQHandler,
- TIM4_IRQHandler,
- I2C1_EV_IRQHandler,
- I2C1_ER_IRQHandler,
- I2C2_EV_IRQHandler,
- I2C2_ER_IRQHandler,
- SPI1_IRQHandler,
- SPI2_IRQHandler,
- USART1_IRQHandler,
- USART2_IRQHandler,
- USART3_IRQHandler,
- EXTI15_10_IRQHandler,
- RTCAlarm_IRQHandler,
- USBWakeUp_IRQHandler,
- TIM8_BRK_IRQHandler,
- TIM8_UP_IRQHandler,
- TIM8_TRG_COM_IRQHandler,
- TIM8_CC_IRQHandler,
- ADC3_IRQHandler,
- FSMC_IRQHandler,
- SDIO_IRQHandler,
- TIM5_IRQHandler,
- SPI3_IRQHandler,
- UART4_IRQHandler,
- UART5_IRQHandler,
- TIM6_IRQHandler,
- TIM7_IRQHandler,
- DMA2_Channel1_IRQHandler,
- DMA2_Channel2_IRQHandler,
- DMA2_Channel3_IRQHandler,
- DMA2_Channel4_5_IRQHandler,
- };
- #ifdef DATA_IN_ExtSRAM
- #pragma language=extended
- __interwork int __low_level_init(void);
- #pragma location="ICODE"
- __interwork int __low_level_init(void)
- {
-
- /* FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
- required, then adjust the Register Addresses*/
- /* Enable FSMC clock */
- *(vu32 *)0x40021014 = 0x00000114;
-
- /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
- *(vu32 *)0x40021018 = 0x000001E0;
-
- /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
- /*---------------- SRAM Address lines configuration -------------------------*/
- /*---------------- NOE and NWE configuration --------------------------------*/
- /*---------------- NE3 configuration ----------------------------------------*/
- /*---------------- NBL0, NBL1 configuration ---------------------------------*/
-
- *(vu32 *)0x40011400 = 0x44BB44BB;
- *(vu32 *)0x40011404 = 0xBBBBBBBB;
-
- *(vu32 *)0x40011800 = 0xB44444BB;
- *(vu32 *)0x40011804 = 0xBBBBBBBB;
-
- *(vu32 *)0x40011C00 = 0x44BBBBBB;
- *(vu32 *)0x40011C04 = 0xBBBB4444;
- *(vu32 *)0x40012000 = 0x44BBBBBB;
- *(vu32 *)0x40012004 = 0x44444B44;
-
- /*---------------- FSMC Configuration ---------------------------------------*/
- /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
-
- *(vu32 *)0xA0000010 = 0x00001011;
- *(vu32 *)0xA0000014 = 0x00000200;
-
- return (1);
- }
- #endif /*DATA_IN_ExtSRAM*/
- /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
typedef void( *intfunc )( void );
定义一个新类型,这个类型是一个函数指针,指针指向的函数类型是void (void)型,
符合标准C
typedef union { intfunc __fun; void * __ptr; } intvec_elem;
定义一个新类型,这个类型是一个联合体,联合体有两个元素,一个元素类型是intfunc,一个元素类型是void *
符合标准C
#pragma language=extended
#pragma segment="CSTACK"
void __iar_program_start( void );
申明外部函数,extern可以用,也可以不用
符合标准C
#pragma location = ".intvec" // 下面的变量存放在段 .intvec
//IAR扩展
/* STM32F10x Vector Table entries */
const intvec_elem __vector_table[] =
{
{ .__ptr = __sfe( "CSTACK" ) },
// { .__ptr = 常量 },
// 数组元素是联合体,联合体有两个元素,对联合体元素__ptr赋初值
//符合标准C
//__sfe( "CSTACK" ) 是段CSTACK的尾地址,更准确是段CSTACK下一个段的首地址(记忆中应该是这样)。
//IAR扩展
__iar_program_start,
//数组元素是联合体,联合体有两个元素,对联合体第一个元素__fun赋初值
//完整的写法是 { .__fun= __iar_program_start },
//这里简写成__iar_program_start,是否符合标准C,有待考证
.....
}
}
补充:
对联合体第一个元素赋初值,可以简写。
{ .__fun= __iar_program_start },
//__fun是联合体第一个元素,可直接简写成__iar_program_start.
//符合标准C
__sfe是IAR的“段操作符”segment operator。表示取某个段的后一个字节的地址。
比如"CSTACK"定义为0x20001000~0x20001fff。那__sfe( "CSTACK" ) 就得到0x20002000这个值,刚好用来初始化msp堆栈指针。
注意使用segment operator前,需要先定义段名如下:
#pragma segment="CSTACK"
阅读(8238) | 评论(0) | 转发(3) |