|
在IAR开发环境可以找到连接,仿真和flashloader文件, 但大多数设备无启动文件。
很多时候需要找芯片原厂或自己修改启动文件。
如果把汇编的启动文件改成C文件来编译有什么缺点?
这是中微MCU的一个汇编启动文件startup_cms32m5xxx_iar.s
;/*******************************************************************************
;* Copyright (C) 2019 China Micro Semiconductor Limited Company. All Rights Reserved.
;*
;* This software is owned and published by:
;* CMS LLC, No 2609-10, Taurus Plaza, TaoyuanRoad, NanshanDistrict, Shenzhen, China.
;*
;* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
;* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
;*
;* This software contains source code for use with CMS
;* components. This software is licensed by CMS to be adapted only
;* for use in systems utilizing cms components. CMS shall not be
;* responsible for misuse or illegal use of this software for devices not
;* supported herein. CMS is providing this software "AS IS" and will
;* not be responsible for issues arising from incorrect user implementation
;* of the software.
;*
;* This software may be replicated in part or whole for the licensed use,
;* with the restriction that this Disclaimer and Copyright notice must be
;* included with each copy of this software, whether used in part or whole,
;* at all times.
;*/
;/*****************************************************************************/
;/* Startup for IAR */
;/* Version V1.0 */
;/* Date 2018-04-15 */
;/* Target-mcu M0+ Device */
;/*****************************************************************************/
MODULE ?cstartup
;; Forward declaration of sections.
SECTION CSTACK ATA:NOROOT(3)
EXTERN __iar_program_start
EXTERN SystemInit
PUBLIC __vector_table
SECTION .intvec:CODE:ROOT(8)
DATA
__vector_table DCD sfe(CSTACK)
DCD Reset_Handler
DCD NMI_Handler ; NMI
DCD HardFault_Handler ; Hard Fault
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall
DCD 0 ; Debug Monitor
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV
DCD SysTick_Handler ; SysTick
; Numbered IRQ handler vectors
; Note: renaming to device dependent ISR function names are done in
DCD GPIO0_IRQHandler ; 0: GPIO P0 interrupt
DCD GPIO1_IRQHandler ; 1: GPIO P1 interrupt
DCD GPIO2_IRQHandler ; 2: GPIO P2 interrupt
DCD GPIO3_IRQHandler ; 3: GPIO P3 interrupt
DCD GPIO4_IRQHandler ; 4: GPIO P4 interrupt
DCD 0 ; 5: Reserved
DCD CCP_IRQHandler ; 6: Capture/PWM interrupt
DCD ADC0_IRQHandler ; 7: ADC 0 interrupt
DCD 0 ; 8: Reserved
DCD WWDT_IRQHandler ; 9: WWDT interrupt
DCD EPWM_IRQHandler ; 10: EPWM interrupt
DCD 0 ; 11: Reserved
DCD ADC1_IRQHandler ; 12: ADC 1 interrupt
DCD ACMP_IRQHandler ; 13: ACMP interrupt
DCD 0 ; 14: Reserved
DCD UART0_IRQHandler ; 15: UART 0 interrupt
DCD UART1_IRQHandler ; 16: UART 1 interrupt
DCD 0 ; 17: Reserved
DCD 0 ; 18: Reserved
DCD TMR0_IRQHandler ; 19: TIMER 0 interrupt
DCD TMR1_IRQHandler ; 20: TIMER 1 interrupt
DCD 0 ; 21: Reserved
DCD 0 ; 22: Reserved
DCD WDT_IRQHandler ; 23: WDT interrupt
DCD I2C_IRQHandler ; 24: I2C interrupt
DCD 0 ; 25: Reserved
DCD SPI_IRQHandler ; 26: SPI interrupt
DCD 0 ; 27: Reserved
DCD 0 ; 28: Reserved
DCD 0 ; 29: Reserved
DCD 0 ; 30: Reserved
DCD LVD_IRQHandler ; 31: LVD interrupt
THUMB
PUBWEAK Reset_Handler
SECTION .text:CODE:NOROOT:REORDER(2)
Reset_Handler
;reset NVIC if in rom debug
LDR R0, =SystemInit
BLX R0
LDR R0, =__iar_program_start
BX R0
PUBWEAK NMI_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
NMI_Handler
B NMI_Handler
PUBWEAK HardFault_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
HardFault_Handler
B HardFault_Handler
PUBWEAK SVC_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
SVC_Handler
B SVC_Handler
PUBWEAK PendSV_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
PendSV_Handler
B PendSV_Handler
PUBWEAK SysTick_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
SysTick_Handler
B SysTick_Handler
PUBWEAK GPIO0_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
GPIO0_IRQHandler
B GPIO0_IRQHandler
PUBWEAK GPIO1_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
GPIO1_IRQHandler
B GPIO1_IRQHandler
PUBWEAK GPIO2_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
GPIO2_IRQHandler
B GPIO2_IRQHandler
PUBWEAK GPIO3_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
GPIO3_IRQHandler
B GPIO3_IRQHandler
PUBWEAK GPIO4_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
GPIO4_IRQHandler
B GPIO4_IRQHandler
PUBWEAK CCP_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
CCP_IRQHandler
B CCP_IRQHandler
PUBWEAK ADC0_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
ADC0_IRQHandler
B ADC0_IRQHandler
PUBWEAK WWDT_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
WWDT_IRQHandler
B WWDT_IRQHandler
PUBWEAK EPWM_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
EPWM_IRQHandler
B EPWM_IRQHandler
PUBWEAK ADC1_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
ADC1_IRQHandler
B ADC1_IRQHandler
PUBWEAK ACMP_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
ACMP_IRQHandler
B ACMP_IRQHandler
PUBWEAK UART0_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
UART0_IRQHandler
B UART0_IRQHandler
PUBWEAK UART1_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
UART1_IRQHandler
B UART1_IRQHandler
PUBWEAK TMR0_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
TMR0_IRQHandler
B TMR0_IRQHandler
PUBWEAK TMR1_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
TMR1_IRQHandler
B TMR1_IRQHandler
PUBWEAK WDT_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
WDT_IRQHandler
B WDT_IRQHandler
PUBWEAK I2C_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
I2C_IRQHandler
B I2C_IRQHandler
PUBWEAK SPI_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
SPI_IRQHandler
B SPI_IRQHandler
PUBWEAK LVD_IRQHandler
SECTION .text:CODE:NOROOT:REORDER(1)
LVD_IRQHandler
B LVD_IRQHandler
END
下面是我改C文件形式的启动文件startup_cms32m5xxx_iar.c,为什么很多情况下芯片厂商和软件公司不使用C替代汇编启动呢?在GCC开发中就有很多是C文件形式的启动文件。
#include <stdint.h>
#define __STACK_TOP 0x20002000 // 与 ICF 中保持一致
/* 外部符号声明 */
extern int main(void);
extern void SystemInit ( void );
extern void __iar_program_start(void);
/* 主启动函数 */
void Reset_Handler(void)
{
SystemInit();
// 调用库初始化
__iar_program_start();
}
/* 弱定义默认中断处理 */
__attribute__((weak)) void NMI_Handler(void){ while(1); }
__attribute__((weak)) void HardFault_Handler(void){ while(1); }
__attribute__((weak)) void SVC_Handler(void){ while(1); } /* -5 SVCall */
__attribute__((weak)) void PendSV_Handler(void){ while(1); } /* -2 PendSV */
__attribute__((weak)) void SysTick_Handler(void){ while(1); } /* -1 SysTick */
__attribute__((weak)) void GPIO0_IRQHandler(void){ while(1); } /* 0: GPIO P0 interrupt */
__attribute__((weak)) void GPIO1_IRQHandler(void){ while(1); } /* 1: GPIO P1 interrupt */
__attribute__((weak)) void GPIO2_IRQHandler(void){ while(1); } /* 2: GPIO P2 interrupt */
__attribute__((weak)) void GPIO3_IRQHandler(void){ while(1); } /* 3: GPIO P3 interrupt */
__attribute__((weak)) void GPIO4_IRQHandler(void){ while(1); } /* 4: GPIO P4 interrupt */
__attribute__((weak)) void CCP_IRQHandler(void){ while(1); } /* 6: Capture/PWM interrupt */
__attribute__((weak)) void ADC0_IRQHandler(void){ while(1); } /* 7: ADC 0 interrupt */
__attribute__((weak)) void WWDT_IRQHandler(void){ while(1); } /* 9: WWDT interrupt */
__attribute__((weak)) void EPWM_IRQHandler(void){ while(1); } /* 10: EPWM interrupt */
__attribute__((weak)) void ADC1_IRQHandler(void){ while(1); } /* 12: ADC 1 interrupt */
__attribute__((weak)) void ACMP_IRQHandler(void){ while(1); } /* 13: ACMP interrupt */
__attribute__((weak)) void UART0_IRQHandler(void){ while(1); } /* 15: UART 0 interrupt */
__attribute__((weak)) void UART1_IRQHandler(void){ while(1); } /* 16: UART 1 interrupt */
__attribute__((weak)) void TMR0_IRQHandler(void){ while(1); } /* 19: TIMER 0 interrupt */
__attribute__((weak)) void TMR1_IRQHandler(void){ while(1); } /* 20: TIMER 1 interrupt */
__attribute__((weak)) void WDT_IRQHandler(void){ while(1); } /* 23: WDT interrupt */
__attribute__((weak)) void I2C_IRQHandler(void){ while(1); } /* 24: I2C interrupt */
__attribute__((weak)) void SPI_IRQHandler(void){ while(1); } /* 26: SPI interrupt */
__attribute__((weak)) void LVD_IRQHandler(void){ while(1); } /* 31: LVD interrupt */
/* 向量表定义 */
__attribute__((section(".intvec")))
__root const uint32_t __vector_table[] =
{
(uint32_t)__STACK_TOP, /* -16 初始栈指针 */
(uint32_t) Reset_Handler, /* -15 复位处理函数 */
(uint32_t) NMI_Handler, /* -14 NMI */
(uint32_t) HardFault_Handler, /* -13 Hard Fault */
0, /* -12 Reserved */
0, /* -11 Reserved */
0, /* -10 Reserved */
0, /* -9 Reserved */
0, /* -8 Reserved */
0, /* -7 Reserved */
0, /* -6 Reserved */
(uint32_t) SVC_Handler, /* -5 SVCall */
0, /* -4 Debug Monitor */
0, /* -3 Reserved */
(uint32_t) PendSV_Handler, /* -2 PendSV */
(uint32_t) SysTick_Handler, /* -1 SysTick */
(uint32_t) GPIO0_IRQHandler, /* 0: GPIO P0 interrupt */
(uint32_t) GPIO1_IRQHandler, /* 1: GPIO P1 interrupt */
(uint32_t) GPIO2_IRQHandler, /* 2: GPIO P2 interrupt */
(uint32_t) GPIO3_IRQHandler, /* 3: GPIO P3 interrupt */
(uint32_t) GPIO4_IRQHandler, /* 4: GPIO P4 interrupt */
0, /* 5: Reserved */
(uint32_t) CCP_IRQHandler, /* 6: Capture/PWM interrupt */
(uint32_t) ADC0_IRQHandler, /* 7: ADC 0 interrupt */
0, /* 8: Reserved */
(uint32_t) WWDT_IRQHandler, /* 9: WWDT interrupt */
(uint32_t) EPWM_IRQHandler, /* 10: EPWM interrupt */
0, /* 11: Reserved */
(uint32_t) ADC1_IRQHandler, /* 12: ADC 1 interrupt */
(uint32_t) ACMP_IRQHandler, /* 13: ACMP interrupt */
0, /* 14: Reserved */
(uint32_t) UART0_IRQHandler, /* 15: UART 0 interrupt */
(uint32_t) UART1_IRQHandler, /* 16: UART 1 interrupt */
0, /* 17: Reserved */
0, /* 18: Reserved */
(uint32_t) TMR0_IRQHandler, /* 19: TIMER 0 interrupt */
(uint32_t) TMR1_IRQHandler, /* 20: TIMER 1 interrupt */
0, /* 21: Reserved */
0, /* 22: Reserved */
(uint32_t) WDT_IRQHandler, /* 23: WDT interrupt */
(uint32_t) I2C_IRQHandler, /* 24: I2C interrupt */
0, /* 25: Reserved */
(uint32_t) SPI_IRQHandler, /* 26: SPI interrupt */
0, /* 27: Reserved */
0, /* 28: Reserved */
0, /* 29: Reserved */
0, /* 30: Reserved */
(uint32_t) LVD_IRQHandler, /* 31: LVD interrupt */
};
|
|