Hello,
I have created a new project for FRDM-K22F (KDS 3.0.0, PEx without SDK) and I have modified the following source code files
I have switched off the generating of the linker command file and I have modified the file Project_Settings/Linker_Files/ProcessorExpert.ld by the following way:
. . .
MEMORY {
m_interrupts (RX) : ORIGIN = 0x00001000, LENGTH = 0x00000198
m_text (RX) : ORIGIN = 0x00001410, LENGTH = 0x0007EBF0
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
m_data_20000000 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000
m_stack_reset (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000008
m_cfmprotrom (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into INTERNAL_FLASH */
.interrupts :
{
__vector_table = .;
. = ALIGN(4);
KEEP(*(.vectortable)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
/* The startup code goes first into INTERNAL_FLASH */
.stack_reset :
{
__stack_reset = .;
. = ALIGN(4);
KEEP(*(.stack_reset)) /* Startup code */
. = ALIGN(4);
} > m_stack_reset
. . .
The vector table is placed at the address 0x1000 and therefore we must add stack pointer and reset vector at address 0x0 and 0x4.
I have modified the static source code file Static_Code/System/Vectors.c. I have added the following code (for GCC compiler):
typedef struct {
void * __ptr;
tIsrFunc *__fun;
} tStackReset;
__attribute__ ((section (".stack_reset"))) const tStackReset __stack_reset = { /* Stack and reset table */
/* ISR address No. Name */
VECTOR_SP_MAIN, /* 0x00 ivINT_Initial_Stack_Pointer */
VECTOR_1 /* 0x01 ivINT_Initial_Program_Counter */
};
This code ensure that the stack pointer and reset vector is placed at address 0x0 and the application starts properly.
See also the map file that contains the __stack_reset object at address 0x0 (size 0x8):
.stack_reset 0x00000000 0x8
0x00000000 __stack_reset = .
0x00000000 . = ALIGN (0x4)
*(.stack_reset)
.stack_reset 0x00000000 0x8 ./Static_Code/System/Vectors.o
0x00000008 . = ALIGN (0x4)
I have also attached the project.
Please note, that the SCB_VTOR is initialized properly according to the value of the __vector_table (pointer) in the __init_hardware() function in the startup.c source code file (there is not need to modify this function).
Best Regards,
Marek Neuzil