;/*****************************************************************************
; * @file:    startup_CM0.s
; * @purpose: CMSIS Cortex-M0 Core Device Startup File 
; *           for the ARM 'Microcontroller Prototyping System' 
; * @version: V1.0
; * @date:    
; *
; *****************************************************************************/
Stack_Size      EQU     0x00000400
Heap_Size       EQU     0x00000000
;__initial_sp    EQU    0x20003000	   ;手动定义SP值

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit

                PRESERVE8
                THUMB

; Vector Table Mapped to Address 0 at Reset

                AREA    RESET, DATA, READONLY
                EXPORT __Vectors

__Vectors       
				DCD     __initial_sp				; Top of Stack
                DCD     Reset_Handler               ; Reset Handler
                DCD     NMI_Handler                 ; NMI Handler
                DCD     HardFault_Handler           ; Hard Fault Handler
                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 Handler ，相当于SWI
                DCD     0                           ; Reserved
                DCD     0                           ; Reserved
                DCD     PendSV_Handler              ; PendSV Handler
                DCD     SysTick_Handler             ; SysTick Handler，系统滴答定时器，即周期性溢出的时基定时器

                ; External Interrupts
                DCD     GPIO_PA_IRQHandler			; 0:  GPIO_PA_IRQHandler    
                DCD     GPIO_PB_IRQHandler			; 1:  GPIO_PB_IRQHandler 
                DCD     GPIO_PC_IRQHandler			; 2:  GPIO_PC_IRQHandler 
                DCD     GPIO_PD_IRQHandler			; 3:  GPIO_PD_IRQHandler 
                DCD     DMA_IRQHandler          	; 4:  DMA_IRQHandler
                DCD     LPTIMER1_IRQHandler         ; 5:  LPTIMER1_IRQHandler
                DCD     UART0_IRQHandler            ; 6:  UART0_IRQHandler
                DCD     LPUART_IRQHandler	        ; 7:  LPUART_IRQHandler
                DCD     UART1_IRQHandler	        ; 8:  UART1_IRQHandler
                DCD     I2C_IRQHandler	          	; 9:  I2C_IRQHandler
                DCD     SPI0_IRQHandler           	; 10: SPI0_IRQHandler
                DCD     SPI1_IRQHandler				; 11: SPI1_IRQHandler  
                DCD    	CAN_IRQHandler				; 12: CAN_IRQHandler
                DCD     VREF_IRQHandler				; 13: VREF_IRQHandler
                DCD     GTIMER0_IRQHandler			; 14: GTIMER0_IRQHandler
                DCD     GTIMER1_IRQHandler			; 15: GTIMER1_IRQHandler
                DCD     GTIMER2_IRQHandler			; 16: GTIMER2_IRQHandler
                DCD     QSPI_IRQHandler          	; 17: QSPI_IRQHandler
                DCD     LPTIMER0_IRQHandler         ; 18: LPTIMER0_IRQHandler
                DCD     COMP0_IRQHandler		    ; 19: COMP0_IRQHandler
                DCD     GPIO_PE_IRQHandler          ; 20: GPIO_PE_IRQHandler
                DCD     COMP1_IRQHandler            ; 21: COMP1_IRQHandler
                DCD     WDT_IRQHandler           	; 22: WDT_IRQHandler
                DCD     RTC_IRQHandler              ; 23: RTC_IRQHandler
                DCD     ADC_IRQHandler              ; 24: ADC_IRQHandler
                DCD     LPTIMER2_IRQHandler         ; 25: LPTIMER2_IRQHandler
                DCD     COMP2_IRQHandler            ; 26: COMP2_IRQHandler
                DCD     WWDT_IRQHandler            	; 27: WWDT_IRQHandler
                DCD     VDT_IRQHandler              ; 28: VDT_IRQHandler 
                DCD     OPA_IRQHandler              ; 29: OPA_IRQHandler
                DCD     FLASH_IRQHandler            ; 30: FLASH_IRQHandler
                DCD     0                           ; 31: Reserved

                AREA    |.text|, CODE, READONLY

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  __main

                ;IMPORT  __set_CONTROL
				;MOVS     R0, #0x01		  ;用户级，Thread和handler模式共享同一个堆栈MSP
				;BL 	    __set_CONTROL	  ;转入用户级线程模式


                LDR     R0, =__main
                BX      R0	              ;BX:跳转到由寄存器给出的地址,	B:跳转到标号处对应的地址
                ENDP


NMI_Handler     PROC
                EXPORT  NMI_Handler               [WEAK]
                B       .
                ENDP
HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler         [WEAK]
                B       .
                ENDP
SVC_Handler     PROC
                EXPORT  SVC_Handler               [WEAK]
                B       .
                ENDP
PendSV_Handler  PROC
                EXPORT  PendSV_Handler            [WEAK]
                B       .
                ENDP
SysTick_Handler PROC
                EXPORT  SysTick_Handler           [WEAK]
                B       .
                ENDP

Default_Handler PROC
				EXPORT   GPIO_PA_IRQHandler	  	  [WEAK]
              	EXPORT   GPIO_PB_IRQHandler	 	  [WEAK]
               	EXPORT   GPIO_PC_IRQHandler	 	  [WEAK]
               	EXPORT   GPIO_PD_IRQHandler	      [WEAK]
				EXPORT   DMA_IRQHandler	      	  [WEAK]					
               	EXPORT   LPTIMER1_IRQHandler      [WEAK]
				EXPORT   UART0_IRQHandler      	  [WEAK]	
                EXPORT   LPUART_IRQHandler        [WEAK]
				EXPORT   UART1_IRQHandler    	  [WEAK]
				EXPORT   I2C_IRQHandler    	      [WEAK]
                EXPORT   SPI0_IRQHandler       	  [WEAK] 
				EXPORT   SPI1_IRQHandler       	  [WEAK]
				EXPORT   CAN_IRQHandler           [WEAK]
				EXPORT	 VREF_IRQHandler		  [WEAK]
                EXPORT   GTIMER0_IRQHandler	      [WEAK]
                EXPORT   GTIMER1_IRQHandler	      [WEAK]
                EXPORT   GTIMER2_IRQHandler	      [WEAK]
                EXPORT   QSPI_IRQHandler          [WEAK]
                EXPORT   LPTIMER0_IRQHandler	  [WEAK]	
				EXPORT   COMP0_IRQHandler	  	  [WEAK]
				EXPORT   GPIO_PE_IRQHandler	      [WEAK]	
				EXPORT   COMP1_IRQHandler	      [WEAK]		
                EXPORT   WDT_IRQHandler		      [WEAK]
                EXPORT   RTC_IRQHandler		      [WEAK]
                EXPORT   ADC_IRQHandler		      [WEAK]
				EXPORT   LPTIMER2_IRQHandler      [WEAK]
				EXPORT   COMP2_IRQHandler      	  [WEAK]
				EXPORT   WWDT_IRQHandler          [WEAK]	
                EXPORT   VDT_IRQHandler		      [WEAK]
				EXPORT   OPA_IRQHandler		      [WEAK]				
                EXPORT   FLASH_IRQHandler		  [WEAK]										
GPIO_PA_IRQHandler	
GPIO_PB_IRQHandler	
GPIO_PC_IRQHandler	
GPIO_PD_IRQHandler	
DMA_IRQHandler	    
LPTIMER1_IRQHandler
UART0_IRQHandler   
LPUART_IRQHandler  
UART1_IRQHandler   
I2C_IRQHandler    	
SPI0_IRQHandler    
SPI1_IRQHandler    
CAN_IRQHandler     
VREF_IRQHandler	
GTIMER0_IRQHandler	
GTIMER1_IRQHandler	
GTIMER2_IRQHandler	
QSPI_IRQHandler    
LPTIMER0_IRQHandler
COMP0_IRQHandler	
GPIO_PE_IRQHandler	
COMP1_IRQHandler	
WDT_IRQHandler		
RTC_IRQHandler		
ADC_IRQHandler		
LPTIMER2_IRQHandler
COMP2_IRQHandler   
WWDT_IRQHandler    
VDT_IRQHandler		
OPA_IRQHandler		
FLASH_IRQHandler	

                B       .
                ENDP								 								 
                 
                ALIGN
                                 
; User Initial Stack & Heap
                 
                IF      :DEF:__MICROLIB
                 
                EXPORT  __initial_sp
                EXPORT  __heap_base
                EXPORT  __heap_limit
                 
                ELSE
                 
                IMPORT  __use_two_region_memory
                EXPORT  __user_initial_stackheap
__user_initial_stackheap
                 
                LDR     R0, =  Heap_Mem
                LDR     R1, =(Stack_Mem + Stack_Size)
                LDR     R2, = (Heap_Mem +  Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR

                ALIGN

                ENDIF

                END
