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

Problem with my own linker script

Hi everyone
I have problem with my linker script, i want to setup position of my own vector table, stack and heap by myself using C++. Everything seems to be ok until program invoke fun.blink() function and try to heck value of pin_state variable, when this is happen program immediately jump to HardFault_Handler_IRQ.

Im using ARM v6.12 compiler

compiler control string:
-xc -std=c99 --target=arm-arm-none-eabi -mcpu=cortex-m3 -c
-fno-rtti -funsigned-char -fshort-enums -fshort-wchar
-D__EVAL -gdwarf-3 -O0 -ffunction-sections -Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes -Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command -Wno-documentation -Wno-license-management -Wno-parentheses-equality -I .
-I./RTE/_STM32F103VB
-IC:/Keil_v5/ARM/PACK/Keil/STM32F1xx_DFP/2.3.0/Device/Include
-IC:/Keil_v5/ARM/CMSIS/Include
-D__UVISION_VERSION="526" -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD
-o ./Objects/*.o -MD

linker control string:
--cpu Cortex-M3 *.o
--strict --scatter ".\linker_script.sct"
--summary_stderr --info summarysizes --map --load_addr_map_info --xref --callgraph --symbols
--info sizes --info totals --info unused --info veneers
--list ".\Listings\TEST_03.map"
-o .\Objects\TEST_03.axf

main.cpp
---------------
class fun{
    public:
        fun(uint8_t _pin):pin{_pin},pin_state{0}{

    }
    void blink(void){
        if(pin_state) {pin_state=0;GPIOB->ODR |=(1<<pin);}
        else {pin_state=1;GPIOB->ODR &=~(1<<pin);}
    };
uint8_t pin;
bool pin_state;
};


fun fun_1(8);

int main(void){
        RCC_Config();
        GPIO_Config();
        NVIC_Config();
        volatile unsigned long int i;
        while(1){
                 for(i=0;i< 0x250000ul;i++);
                fun_1.blink();
         };
}


void Reset_Handler_IRQ(void){
   __ASM(
    "LDR     R0, =  0x20000000             ;"
    "LDR     R1, =  0x20000400     +0x200  ;"
    "LDR     R2, = (0x20000000 + 0x200)    ;"
    "LDR     R3, = (0x20000400);"
    );
    main();
}

void NMI_Handler_IRQ(void){};
void HardFault_Handler_IRQ(void){};
void MemManage_Handler_IRQ(void){};
void BusFault_Handler_IRQ(void){};
void UsageFault_Handler_IRQ(void){};
void SVC_Handler_IRQ(void){};
void DebugMon_Handler_IRQ(void){};
void PendSV_Handler_IRQ(void){};
void SysTick_Handler_IRQ(void){};

const uint32_t __initial_sp=0x20000400;
const uint32_t Reset_Handler=(uint32_t)Reset_Handler_IRQ;
const uint32_t NMI_Handler=(uint32_t)NMI_Handler_IRQ;
const uint32_t HardFault_Handler=(uint32_t)HardFault_Handler_IRQ;
const uint32_t MemManage_Handler=(uint32_t)MemManage_Handler_IRQ;
const uint32_t BusFault_Handler=(uint32_t)BusFault_Handler_IRQ;
const uint32_t UsageFault_Handler=(uint32_t)UsageFault_Handler_IRQ;
const uint32_t SVC_Handler=(uint32_t)SVC_Handler_IRQ;
const uint32_t DebugMon_Handler=(uint32_t)DebugMon_Handler_IRQ;
const uint32_t PendSV_Handler=(uint32_t)PendSV_Handler_IRQ;
const uint32_t SysTick_Handler=(uint32_t)SysTick_Handler_IRQ;

extern "C" const uint32_t vector_table[16] __attribute__((section("vectors")))={
__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
};
linker_script.sct
--------------
LR_IROM2   0x08000000 0x00001000  {    ; load region size_region
        VECT 0x08000000 0x00000040{
                *.o (vectors, +First)
        }
        ER_IROM1 +0 0x00001000  {  ; load address = execution address
                *.o
                *(InRoot$$Sections)
                .ANY (+RO)
                .ANY (+XO)
                .ANY (+ZI)
        }
        ARM_LIB_STACK 0x20000400 EMPTY -0x200  ; Stack region growing down
                { }
        ARM_LIB_HEAP  0x20000000 EMPTY  0x200 ; Heap region growing up
                { }
}