
;/*****************************************************************************/
;/*  Startup for ARM                                                          */
;/*  Version     V1.0                                                         */
;/*  Date        2024-02-26                                                   */
;/*  Target-mcu  {MCU_PN_H}                                                   */
;/*****************************************************************************/

; Stack Configuration
; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>

Stack_Size      EQU     0x00000400

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


; Heap Configuration
;  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>

Heap_Size       EQU     0x00000200

                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
                EXPORT  __Vectors_End
                EXPORT  __Vectors_Size

__Vectors                       
                DCD     __initial_sp              ; Top of Stack
                DCD     Reset_Handler             ;< -15 Reset Vector, invoked on Power up and warm reset
                DCD     NMI_Handler               ;< -14 Non maskable Interrupt, cannot be stopped or preempted
                DCD     HardFault_Handler         ;< -13 Hard Fault, all classes of Fault
                DCD     0                         ;< -12 Reserved
                DCD     0                         ;< -11 Reserved
                DCD     0                         ;< -10 Reserved
                DCD     0                         ;< -9 Reserved
                DCD     0                         ;< -8 Reserved
                DCD     0                         ;< -7 Reserved
                DCD     0                         ;< -6 Reserved
                DCD     SVC_Handler               ;< -5 System Service Call via SVC instruction
                DCD     0                         ;< -4 Reserved
                DCD     0                         ;< -3 Reserved
                DCD     PendSV_Handler            ;< -2 Pendable request for system service
                DCD     SysTick_Handler           ;< -1 System Tick Timer

                DCD     WDT_IRQHandler            ;< 0 Watch Dog Timer Interrupt Handler
                DCD     LVD_IRQHandler            ;< 1 Low Voltage Detect Interrupt Handler
                DCD     RTC_IRQHandler            ;< 2 RTC Interrupt Handler
                DCD     FLASHRAM_IRQHandler       ;< 3 Flash/RAM Interrupt Handler
                DCD     SYSCTRL_IRQHandler        ;< 4 SysCtrl Interupt Handler
                DCD     GPIOA_IRQHandler          ;< 5 GPIOA Interrupt Handler
                DCD     GPIOB_IRQHandler          ;< 6 GPIOB Interrupt Handler
                DCD     GPIOC_IRQHandler          ;< 7 GPIOC Interrupt Handler
                DCD     GPIOF_IRQHandler          ;< 8 GPIOF Interrupt Handler
                DCD     DMACH12_IRQHandler        ;< 9 DMA CH1 and CH2 Interrupt Handler
                DCD     DMACH34_IRQHandler        ;< 10 DMA CH3 and CH4 Interrupt Handler
                DCD     CORDIC_IRQHandler         ;< 11 CORDIC Interrupt Handler
                DCD     ADC1_IRQHandler           ;< 12 ADC1 Interrupt Handler
                DCD     ATIM_IRQHandler           ;< 13 Advanced Timer Interrupt Handler
                DCD     VC13_IRQHandler           ;< 14 Voltage Comparator 1 and Comparator 3 Interrupt Handler
                DCD     VC24_IRQHandler           ;< 15 Voltage Comparator 2 and Comparator 4 Interrupt Handler
                DCD     GTIM1_IRQHandler          ;< 16 General Timer1 Interrupt Handler
                DCD     GTIM2_IRQHandler          ;< 17 General Timer2 Interrupt Handler
                DCD     GTIM34_IRQHandler         ;< 18 General Timer3 and General Timer4 Interrupt Handler
                DCD     LPTIM_IRQHandler          ;< 19 LPTIM Interrupt Handle
                DCD     BTIM1_IRQHandler          ;< 20 BTIM1 Interrupt Handler
                DCD     BTIM2_IRQHandler          ;< 21 BTIM2 Interrupt Handler
                DCD     BTIM3_HALLTIM_IRQHandler  ;< 22 BTIM3 and Hall timer Interrupt Handler
                DCD     I2C1_IRQHandler           ;< 23 I2C1 Interrupt Handler
                DCD     I2C2_IRQHandler           ;< 24 I2C2 Interrupt Handler
                DCD     SPI1_IRQHandler           ;< 25 SPI1 Interrupt Handler
                DCD     SPI23_IRQHandler          ;< 26 SPI2 and SPI3 Interrupt Handler
                DCD     UART1_IRQHandler          ;< 27 UART1 Interrupt Handler
                DCD     UART2_IRQHandler          ;< 28 UART2 Interrupt Handler
                DCD     UART3_IRQHandler          ;< 29 UART3 Interrupt Handler
                DCD     ADC2_DAC_IRQHandler       ;< 30 ADC2 and DAC Interrupt Handler
                DCD     CLKFAULT_IRQHandler       ;< 31 CLKFAULT Interrupt Handler

                

__Vectors_End

__Vectors_Size 	EQU     __Vectors_End - __Vectors

                AREA    |.text|, CODE, READONLY


; Reset Handler

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  SystemInit
                IMPORT  __main
                    
                LDR     R1, =0x0
                LDR     R0, [R1]
                MOV     SP, R0
               
                LDR     R0, =SystemInit
                BLX     R0
                LDR     R0, =__main
                BX      R0
                ENDP


; Dummy Exception Handlers (infinite loops which can be modified)

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  WDT_IRQHandler            [WEAK]
                EXPORT  LVD_IRQHandler            [WEAK]
                EXPORT  RTC_IRQHandler            [WEAK]
                EXPORT  FLASHRAM_IRQHandler       [WEAK]
                EXPORT  SYSCTRL_IRQHandler        [WEAK]
                EXPORT  GPIOA_IRQHandler          [WEAK]
                EXPORT  GPIOB_IRQHandler          [WEAK]
                EXPORT  GPIOC_IRQHandler          [WEAK]
                EXPORT  GPIOF_IRQHandler          [WEAK]
                EXPORT  DMACH12_IRQHandler        [WEAK]
                EXPORT  DMACH34_IRQHandler        [WEAK]
                EXPORT  CORDIC_IRQHandler         [WEAK]
                EXPORT  ADC1_IRQHandler           [WEAK]
                EXPORT  ATIM_IRQHandler           [WEAK]
                EXPORT  VC13_IRQHandler           [WEAK]
                EXPORT  VC24_IRQHandler           [WEAK]
                EXPORT  GTIM1_IRQHandler          [WEAK]
                EXPORT  GTIM2_IRQHandler          [WEAK]
                EXPORT  GTIM34_IRQHandler         [WEAK]
                EXPORT  LPTIM_IRQHandler          [WEAK]
                EXPORT  BTIM1_IRQHandler          [WEAK]
                EXPORT  BTIM2_IRQHandler          [WEAK]
                EXPORT  BTIM3_HALLTIM_IRQHandler  [WEAK]
                EXPORT  I2C1_IRQHandler           [WEAK]
                EXPORT  I2C2_IRQHandler           [WEAK]
                EXPORT  SPI1_IRQHandler           [WEAK]
                EXPORT  SPI23_IRQHandler          [WEAK]
                EXPORT  UART1_IRQHandler          [WEAK]
                EXPORT  UART2_IRQHandler          [WEAK]
                EXPORT  UART3_IRQHandler          [WEAK]
                EXPORT  ADC2_DAC_IRQHandler       [WEAK]
                EXPORT  CLKFAULT_IRQHandler       [WEAK]

WDT_IRQHandler          
LVD_IRQHandler          
RTC_IRQHandler          
FLASHRAM_IRQHandler     
SYSCTRL_IRQHandler      
GPIOA_IRQHandler        
GPIOB_IRQHandler        
GPIOC_IRQHandler        
GPIOF_IRQHandler        
DMACH12_IRQHandler      
DMACH34_IRQHandler      
CORDIC_IRQHandler       
ADC1_IRQHandler         
ATIM_IRQHandler         
VC13_IRQHandler         
VC24_IRQHandler         
GTIM1_IRQHandler        
GTIM2_IRQHandler        
GTIM34_IRQHandler       
LPTIM_IRQHandler    
BTIM1_IRQHandler        
BTIM2_IRQHandler        
BTIM3_HALLTIM_IRQHandler
I2C1_IRQHandler         
I2C2_IRQHandler         
SPI1_IRQHandler         
SPI23_IRQHandler        
UART1_IRQHandler        
UART2_IRQHandler        
UART3_IRQHandler        
ADC2_DAC_IRQHandler     
CLKFAULT_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
