#include "stdint.h" #define Stack_Size 0x00000800U #define Heap_Size 0x00000400U uint8_t Stack_Mem[Stack_Size] __attribute__ ((section ("STACK"))); uint32_t* const __initial_sp = (uint32_t*)&Stack_Mem[Stack_Size]; uint8_t Heap_Mem[Heap_Size] __attribute__ ((section ("HEAP"))); uint32_t* const __heap_base = (uint32_t*)&Heap_Mem[0]; uint32_t* const __heap_limit = (uint32_t*)&Heap_Mem[Stack_Size]; extern void NMI_Handler(void) __attribute__((weak)); extern void HardFault_Handler(void) __attribute__((weak)); extern void MemManage_Handler(void) __attribute__((weak)); extern void BusFault_Handler(void) __attribute__((weak)); extern void UsageFault_Handler(void) __attribute__((weak)); extern void SVC_Handler(void) __attribute__((weak)); extern void DebugMon_Handler(void) __attribute__((weak)); extern void PendSV_Handler(void) __attribute__((weak)); extern void SysTick_Handler(void) __attribute__((weak)); extern void WWDGT_IRQHandler(void) __attribute__((weak)); extern void LVD_IRQHandler(void) __attribute__((weak)); extern void RTC_IRQHandler(void) __attribute__((weak)); extern void FMC_IRQHandler(void) __attribute__((weak)); extern void RCU_IRQHandler(void) __attribute__((weak)); extern void EXTI0_IRQHandler(void) __attribute__((weak)); extern void EXTI1_IRQHandler(void) __attribute__((weak)); extern void EXTI2_IRQHandler(void) __attribute__((weak)); extern void EXTI3_IRQHandler(void) __attribute__((weak)); extern void EXTI4_IRQHandler(void) __attribute__((weak)); extern void DMA0_Channel0_IRQHandler(void) __attribute__((weak)); extern void DMA0_Channel1_IRQHandler(void) __attribute__((weak)); extern void DMA0_Channel2_IRQHandler(void) __attribute__((weak)); extern void DMA0_Channel3_IRQHandler(void) __attribute__((weak)); extern void DMA0_Channel4_IRQHandler(void) __attribute__((weak)); extern void DMA0_Channel5_IRQHandler(void) __attribute__((weak)); extern void DMA0_Channel6_IRQHandler(void) __attribute__((weak)); extern void ADC0_1_IRQHandler(void) __attribute__((weak)); extern void CAN0_Message_IRQHandler(void) __attribute__((weak)); extern void CAN0_Busoff_IRQHandler(void) __attribute__((weak)); extern void CAN0_Error_IRQHandler(void) __attribute__((weak)); extern void CAN0_FastError_IRQHandler(void) __attribute__((weak)); extern void CAN0_TEC_IRQHandler(void) __attribute__((weak)); extern void CAN0_REC_IRQHandler(void) __attribute__((weak)); extern void CAN0_WKUP_IRQHandler(void) __attribute__((weak)); extern void TIMER0_BRK_UP_TRG_CMT_IRQHandler(void) __attribute__((weak)); extern void TIMER0_Channel_IRQHandler(void) __attribute__((weak)); extern void TIMER1_IRQHandler(void) __attribute__((weak)); extern void TIMER19_BRK_UP_TRG_CMT_IRQHandler(void) __attribute__((weak)); extern void TIMER19_Channel_IRQHandler(void) __attribute__((weak)); extern void I2C0_EV_IRQHandler(void) __attribute__((weak)); extern void I2C0_ER_IRQHandler(void) __attribute__((weak)); extern void I2C1_EV_IRQHandler(void) __attribute__((weak)); extern void I2C1_ER_IRQHandler(void) __attribute__((weak)); extern void SPI0_IRQHandler(void) __attribute__((weak)); extern void SPI1_IRQHandler(void) __attribute__((weak)); extern void USART0_IRQHandler(void) __attribute__((weak)); extern void USART1_IRQHandler(void) __attribute__((weak)); extern void USART2_IRQHandler(void) __attribute__((weak)); extern void EXTI10_15_IRQHandler(void) __attribute__((weak)); extern void EXTI5_9_IRQHandler(void) __attribute__((weak)); extern void TAMPER_IRQHandler(void) __attribute__((weak)); extern void TIMER20_BRK_UP_TRG_CMT_IRQHandler(void) __attribute__((weak)); extern void TIMER20_Channel_IRQHandler(void) __attribute__((weak)); extern void TIMER7_BRK_UP_TRG_CMT_IRQHandler(void) __attribute__((weak)); extern void TIMER7_Channel_IRQHandler(void) __attribute__((weak)); extern void DMAMUX_IRQHandler(void) __attribute__((weak)); extern void SRAMC_ECCSE_IRQHandler(void) __attribute__((weak)); extern void CMP_IRQHandler(void) __attribute__((weak)); extern void OVD_IRQHandler(void) __attribute__((weak)); extern void TIMER5_DAC_IRQHandler(void) __attribute__((weak)); extern void TIMER6_IRQHandler(void) __attribute__((weak)); extern void DMA1_Channel0_IRQHandler(void) __attribute__((weak)); extern void DMA1_Channel1_IRQHandler(void) __attribute__((weak)); extern void DMA1_Channel2_IRQHandler(void) __attribute__((weak)); extern void DMA1_Channel3_IRQHandler(void) __attribute__((weak)); extern void DMA1_Channel4_IRQHandler(void) __attribute__((weak)); extern void CAN1_WKUP_IRQHandler(void) __attribute__((weak)); extern void CAN1_Message_IRQHandler(void) __attribute__((weak)); extern void CAN1_Busoff_IRQHandler(void) __attribute__((weak)); extern void CAN1_Error_IRQHandler(void) __attribute__((weak)); extern void CAN1_FastError_IRQHandler(void) __attribute__((weak)); extern void CAN1_TEC_IRQHandler(void) __attribute__((weak)); extern void CAN1_REC_IRQHandler(void) __attribute__((weak)); extern void FPU_IRQHandler(void) __attribute__((weak)); extern void MFCOM_IRQHandler(void) __attribute__((weak)); extern void __main(void); extern void SystemInit(void); extern void __user_initial_stackheap( uint32_t **pHeap_Mem, uint32_t **pStack_Mem_end , uint32_t **pHeap_Mem_end, uint32_t **pStack_Mem); #define REG_SRAM_DENSITY 0x1FFFF7E0U #define SRAM_DENSITY_MASK 0xFFFF0000U #define SRAM_START_ADDR 0x20000000U //#define SRAM_FILL_VALUE 0x00000000U #define SRAM_FILL_VALUE 0xAAAAAAAAU //must optimize level using -O1 __attribute__((noreturn)) void Reset_Handler(void) { register uint32_t * pRAMSize = (uint32_t *)REG_SRAM_DENSITY; register uint32_t RAMSize = (*pRAMSize)&SRAM_DENSITY_MASK; RAMSize = RAMSize>>16U; RAMSize = RAMSize<<10U; register uint32_t* PtrRAM = (uint32_t*)SRAM_START_ADDR; do { *PtrRAM++ = SRAM_FILL_VALUE; RAMSize-=4; } while(RAMSize>0); SystemInit(); __main(); } typedef void (*pFunc)(void) ; const pFunc __Vectors[] __attribute__ ((section ("RESET"))) = { (pFunc)__initial_sp, // Top of Stack Reset_Handler ,// Reset Handler NMI_Handler ,// NMI Handler HardFault_Handler ,// Hard Fault Handler MemManage_Handler ,// MPU Fault Handler BusFault_Handler ,// Bus Fault Handler UsageFault_Handler ,// Usage Fault Handler 0 ,// Reserved 0 ,// Reserved 0 ,// Reserved 0 ,// Reserved SVC_Handler ,// SVCall Handler DebugMon_Handler ,// Debug Monitor Handler 0 ,// Reserved PendSV_Handler ,// PendSV Handler SysTick_Handler ,// SysTick Handler /* external interrupts handler */ WWDGT_IRQHandler ,// 16:Window Watchdog Timer LVD_IRQHandler ,// 17:LVD through EXTI Line detect 0 ,// 18:Reserved RTC_IRQHandler ,// 19:RTC FMC_IRQHandler ,// 20:FMC RCU_IRQHandler ,// 21:RCU EXTI0_IRQHandler ,// 22:EXTI Line 0 EXTI1_IRQHandler ,// 23:EXTI Line 1 EXTI2_IRQHandler ,// 24:EXTI Line 2 EXTI3_IRQHandler ,// 25:EXTI Line 3 EXTI4_IRQHandler ,// 26:EXTI Line 4 DMA0_Channel0_IRQHandler ,// 27:DMA0 Channel0 DMA0_Channel1_IRQHandler ,// 28:DMA0 Channel1 DMA0_Channel2_IRQHandler ,// 29:DMA0 Channel2 DMA0_Channel3_IRQHandler ,// 30:DMA0 Channel3 DMA0_Channel4_IRQHandler ,// 31:DMA0 Channel4 DMA0_Channel5_IRQHandler ,// 32:DMA0 Channel5 DMA0_Channel6_IRQHandler ,// 33:DMA0 Channel6 ADC0_1_IRQHandler ,// 34:ADC0 and ADC1 CAN0_Message_IRQHandler ,// 35:CAN0 Interrupt for message buffer CAN0_Busoff_IRQHandler ,// 36:CAN0 Interrupt for bus off/bus off done CAN0_Error_IRQHandler ,// 37:CAN0 Interrupt for error CAN0_FastError_IRQHandler ,// 38:CAN0 Interrupt for error in fast transmission CAN0_TEC_IRQHandler ,// 39:CAN0 Interrupt for transmit warning CAN0_REC_IRQHandler ,// 40:CAN0 Interrupt for receive warning CAN0_WKUP_IRQHandler ,// 41:CAN0 wakeup through EXTI Line detection interrupt TIMER0_BRK_UP_TRG_CMT_IRQHandler ,// 42:TIMER0 Break Update Trigger and Commutation TIMER0_Channel_IRQHandler ,// 43:TIMER0 Channel Capture Compare TIMER1_IRQHandler ,// 44:TIMER1 TIMER19_BRK_UP_TRG_CMT_IRQHandler ,// 45:TIMER19 Break Update Trigger and Commutation TIMER19_Channel_IRQHandler ,// 46:TIMER19 Channel Capture Compare I2C0_EV_IRQHandler ,// 47:I2C0 Event I2C0_ER_IRQHandler ,// 48:I2C0 Error I2C1_EV_IRQHandler ,// 49:I2C1 Event I2C1_ER_IRQHandler ,// 50:I2C1 Error SPI0_IRQHandler ,// 51:SPI0 SPI1_IRQHandler ,// 52:SPI1 USART0_IRQHandler ,// 53:USART0 USART1_IRQHandler ,// 54:USART1 USART2_IRQHandler ,// 55:USART2 EXTI10_15_IRQHandler ,// 56:EXTI Line10-15 EXTI5_9_IRQHandler ,// 57:EXTI Line5-9 TAMPER_IRQHandler ,// 58:BKP Tamper TIMER20_BRK_UP_TRG_CMT_IRQHandler ,// 59:TIMER20 Break Update Trigger and Commutation TIMER20_Channel_IRQHandler ,// 60:TIMER20 Channel Capture Compare TIMER7_BRK_UP_TRG_CMT_IRQHandler ,// 61:TIMER7 Break Update Trigger and Commutation TIMER7_Channel_IRQHandler ,// 62:TIMER7 Channel Capture Compare DMAMUX_IRQHandler ,// 63:DMANUX SRAMC_ECCSE_IRQHandler ,// 64:Syscfg interrupt(sramc eccse) CMP_IRQHandler ,// 65:CMP through EXTI Line 0 ,// 66:Reserved OVD_IRQHandler ,// 67:OVD 0 ,// 68:Reserved 0 ,// 69:Reserved TIMER5_DAC_IRQHandler ,// 70:TIMER5 and DAC TIMER6_IRQHandler ,// 71:TIMER6 DMA1_Channel0_IRQHandler ,// 72:DMA1 Channel0 DMA1_Channel1_IRQHandler ,// 73:DMA1 Channel1 DMA1_Channel2_IRQHandler ,// 74:DMA1 Channel2 DMA1_Channel3_IRQHandler ,// 75:DMA1 Channel3 DMA1_Channel4_IRQHandler ,// 76:DMA1 Channel4 0 ,// 77:Reserved CAN1_WKUP_IRQHandler ,// 78:CAN1 wakeup through EXTI Line detection interrupt CAN1_Message_IRQHandler ,// 79:CAN1 Interrupt for message buffer CAN1_Busoff_IRQHandler ,// 80:CAN1 Interrupt for bus off/bus off done CAN1_Error_IRQHandler ,// 81:CAN1 Interrupt for error CAN1_FastError_IRQHandler ,// 82:CAN1 Interrupt for error in fast transmission CAN1_TEC_IRQHandler ,// 83:CAN1 Interrupt for transmit warning CAN1_REC_IRQHandler ,// 84:CAN1 Interrupt for receive warning FPU_IRQHandler ,// 85:FPU MFCOM_IRQHandler , // 86:MFCOM }; uint32_t* const __Vectors_End = (uint32_t*)&__Vectors[sizeof(__Vectors)/sizeof(pFunc)]; uint32_t __Vectors_Size =sizeof(__Vectors)/sizeof(pFunc); #ifdef __MICROLIB extern uint32_t* const __initial_sp; extern uint32_t* const __heap_base; extern uint32_t* const __heap_limit; #else /* __attribute__((noinline)) void __user_initial_stackheap1( uint32_t **pHeap_Mem, uint32_t **pStack_Mem_end , uint32_t **pHeap_Mem_end, uint32_t **pStack_Mem) { *pHeap_Mem = (uint32_t *) &Heap_Mem[0]; *pStack_Mem_end = (uint32_t *)((uint8_t*)&Stack_Mem[0]+ Stack_Size); *pHeap_Mem_end = (uint32_t *)((uint8_t*)&Heap_Mem[0]+ Heap_Size); *pStack_Mem = (uint32_t *)&Stack_Mem[0]; } */ __attribute__((naked)) void __user_initial_stackheap( uint32_t **pHeap_Mem, uint32_t **pStack_Mem_end , uint32_t **pHeap_Mem_end, uint32_t **pStack_Mem) { // __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); __asm volatile ("MOV r0,%0" :: "r" (&Heap_Mem[0])); __asm volatile ("MOV r1,%0" :: "r" ((uint8_t*)&Stack_Mem[0]+ Stack_Size)); __asm volatile ("MOV r2,%0" :: "r" ((uint8_t*)&Heap_Mem[0]+ Heap_Size)); __asm volatile ("MOV r3,%0" :: "r" (&Stack_Mem[0])); } #endif
标签:__,keil,attribute,void,startup,IRQHandler,编译器,weak,extern From: https://www.cnblogs.com/CChild/p/18666940