This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Porting KEIL project to GCC compiler(Startup file)

Hi,

 I need help rewriting the startup file in KEIL to the GCC compiler (MPLAB) startup file. Either it will be helpful to get valuable resources or guides by which I can conversion.

The following is my startup code that I need to convert

     IMPORT  __main
        IMPORT  SystemInit
        IMPORT  main
        

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

Stack_Size      EQU     0x00001000

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


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

Heap_Size       EQU     0x00000400 

                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, ALIGN=7
                EXPORT  __Vectors
                EXPORT  __Vectors_End
                EXPORT  __Vectors_Size

__Vectors       DCD     __initial_sp              ; Top of Stack
                DCD     Reset_Handler             ; Reset Handler
                DCD     NMI_Handler               ; NMI Handler
                DCD     HardFault_Handler         ; Hard Fault Handler
                DCD     MemManage_Handler         ; MPU Fault Handler
                DCD     BusFault_Handler          ; Bus Fault Handler
                DCD     UsageFault_Handler        ; Usage Fault Handler
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     SVC_Handler               ; SVCall Handler
                DCD     DebugMon_Handler          ; Debug Monitor Handler
                DCD     0                         ; Reserved
                DCD     PendSV_Handler            ; PendSV Handler
                DCD     SysTick_Handler           ; SysTick Handler

                ; MEC2016 External Interrupts
                                                   ; Table offset: NVIC Num 
				DCD    NVIC_IRQ00_Handler			;  40h: 0, GIRQ08              		   ; EVERGLADES;  NVIC_Handler_GIRQ08         
               	DCD    NVIC_IRQ01_Handler 			;  44h: 1, GIRQ09                      ; EVERGLADES;  NVIC_Handler_GIRQ09         
                DCD    NVIC_IRQ02_Handler 			;  48h: 2, GIRQ10                      ; EVERGLADES;  NVIC_Handler_GIRQ10         
                DCD    NVIC_IRQ03_Handler 			;  4Ch: 3, GIRQ11                      ; EVERGLADES;  NVIC_Handler_GIRQ11         
                DCD    NVIC_IRQ04_Handler 			;  50h: 4, GIRQ12                      ; EVERGLADES;  NVIC_Handler_GIRQ12         
                DCD    NVIC_IRQ05_Handler 			;  54h: 5, GIRQ13                      ; EVERGLADES;  NVIC_Handler_GIRQ13         
                DCD    NVIC_IRQ06_Handler 			;  58h: 6, GIRQ14                      ; EVERGLADES;  NVIC_Handler_GIRQ14         
                DCD    NVIC_IRQ07_Handler 			;  5Ch: 7, GIRQ15                      ; EVERGLADES;  NVIC_Handler_GIRQ15         
                DCD    NVIC_IRQ08_Handler			;  60h: 8, GIRQ16                      ; EVERGLADES;  NVIC_Handler_GIRQ16         
                DCD    NVIC_IRQ09_Handler 			;  64h: 9, GIRQ17                      ; EVERGLADES;  NVIC_Handler_GIRQ17         
                DCD    NVIC_IRQ10_Handler 			;  68h: 10, GIRQ18                     ; EVERGLADES;  NVIC_Handler_GIRQ18         
                DCD    NVIC_IRQ11_Handler 			;  6Ch: 11, GIRQ19                     ; EVERGLADES;  NVIC_Handler_GIRQ19         
                DCD    NVIC_IRQ12_Handler 			;  70h: 12, GIRQ20                     ; EVERGLADES;  NVIC_Handler_GIRQ20         
                DCD    NVIC_IRQ13_Handler 			;  74h: 13, GIRQ21                     ; EVERGLADES;  NVIC_Handler_GIRQ21         
                DCD    NVIC_IRQ14_Handler 			;  78h: 14, GIRQ23                     ; EVERGLADES;  NVIC_Handler_GIRQ23         
                DCD    NVIC_IRQ15_Handler 			;  7Ch: 15, GIRQ24                     ; EVERGLADES;  NVIC_Handler_GIRQ24         
                DCD    NVIC_IRQ16_Handler 			;  80h: 16, GIRQ25                     ; EVERGLADES;  NVIC_Handler_GIRQ25         

__Vectors_End

__Vectors_Size  EQU     __Vectors_End - __Vectors

;
; Reset Handler
;
;;                AREA    |.text|, CODE, READONLY
;; Name code section containing reset handler in such a way 
;; the linker will place it first
                AREA    |!!!!AENTRY|, CODE, READONLY
                THUMB


Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]

                CPSID    i
               
; Remap vector table
                LDR     R0, =__Vectors
                LDR     R1, =0xE000ED08
                STR     R0,  [R1]
                NOP
                
;; Application code must enable FPU.
                IF      {CPU} = "Cortex-M4.fp"
                LDR     R0, =0xE000ED88           ; Enable CP10,CP11
                LDR     R1,[R0]
                ORR     R1,R1,#(0xF << 20)
                STR     R1,[R0]
                ENDIF

;; Load stack pointer 
                LDR     SP, =__initial_sp
				
				;this does nothing meaningful
				;this causes issues on mixed mode execution where some code resides in SRAM and some in flash
				;issue is trying to execute code at SRAM before the scatter loading is completed
                ;LDR     R0, =SystemInit
                ;BLX     R0

                ;LDR     SP, =__initial_sp
                
                ; Enter Keil startup code which calls our main
                LDR     R0, =__main
                BX      R0
                ENDP


                AREA    |.text|, CODE, READONLY
;                
; Dummy Exception Handlers (infinite loops which can be modified)
;

NMI_Handler     PROC
                EXPORT  NMI_Handler               [WEAK]
                MOV R7,#1
                B       .
                ENDP
HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler         [WEAK]
                MOV R7,#2
                B       .
                ENDP
MemManage_Handler\
                PROC
                EXPORT  MemManage_Handler         [WEAK]
                MOV R7,#3
                B       .
                ENDP
BusFault_Handler\
                PROC
                EXPORT  BusFault_Handler          [WEAK]
                MOV R7,#4
                B       .
                ENDP
UsageFault_Handler\
                PROC
                EXPORT  UsageFault_Handler        [WEAK]
                MOV R7,#5
                B       .
                ENDP
SVC_Handler     PROC
                EXPORT  SVC_Handler               [WEAK]
                MOV R7,#6
                B       .
                ENDP
DebugMon_Handler\
                PROC
                EXPORT  DebugMon_Handler          [WEAK]
                MOV R7,#7
                B       .
                ENDP
PendSV_Handler  PROC
                EXPORT  PendSV_Handler            [WEAK]
                MOV R7,#8
                B       .
                ENDP
SysTick_Handler PROC
                EXPORT  SysTick_Handler           [WEAK]
                MOV R7,#9
                B       .
                ENDP

Default_Handler PROC

        ; External MEC2016 NVIC Interrupt Inputs
			EXPORT    NVIC_IRQ00_Handler		[WEAK] 
			EXPORT    NVIC_IRQ01_Handler		[WEAK] 
			EXPORT    NVIC_IRQ02_Handler		[WEAK] 
			EXPORT    NVIC_IRQ03_Handler		[WEAK] 
			EXPORT    NVIC_IRQ04_Handler		[WEAK] 
			EXPORT    NVIC_IRQ05_Handler		[WEAK] 
			EXPORT    NVIC_IRQ06_Handler		[WEAK] 
			EXPORT    NVIC_IRQ07_Handler		[WEAK] 
			EXPORT    NVIC_IRQ08_Handler		[WEAK] 
			EXPORT    NVIC_IRQ09_Handler		[WEAK] 
			EXPORT    NVIC_IRQ10_Handler		[WEAK] 
			EXPORT    NVIC_IRQ11_Handler		[WEAK] 
			EXPORT    NVIC_IRQ12_Handler		[WEAK] 
			EXPORT    NVIC_IRQ13_Handler		[WEAK] 
			EXPORT    NVIC_IRQ14_Handler		[WEAK] 
			EXPORT    NVIC_IRQ15_Handler		[WEAK] 
			EXPORT    NVIC_IRQ16_Handler		[WEAK]


				
NVIC_IRQ00_Handler		
NVIC_IRQ01_Handler		
NVIC_IRQ02_Handler		
NVIC_IRQ03_Handler		
NVIC_IRQ04_Handler		
NVIC_IRQ05_Handler		
NVIC_IRQ06_Handler		
NVIC_IRQ07_Handler		
NVIC_IRQ08_Handler		
NVIC_IRQ09_Handler		
NVIC_IRQ10_Handler		
NVIC_IRQ11_Handler		
NVIC_IRQ12_Handler		
NVIC_IRQ13_Handler		
NVIC_IRQ14_Handler		
NVIC_IRQ15_Handler		
NVIC_IRQ16_Handler

				B       .

                ENDP


                ALIGN


; User Initial Stack & Heap

                IF      :DEF:__MICROLIB
                
                EXPORT  __initial_sp
                EXPORT  __heap_base
                EXPORT  __heap_limit
                EXPORT  __stack_bottom

                ELSE
                
                IMPORT  __use_two_region_memory
                EXPORT  __user_initial_stackheap

__user_initial_stackheap PROC
                LDR     R0, =  Heap_Mem
                LDR     R1, =(Stack_Mem + Stack_Size)
                LDR     R2, = (Heap_Mem +  Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR
                ENDP

                ALIGN

                ENDIF