Relocate memery on KDS3.0

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Relocate memery on KDS3.0

616 Views
Fan_xy
Contributor III

Hello everyone,

 

I create a simple project on KDS3.0 - PE , about frdm-k22 board, it can work well .

While i relocate the memory flash start from 0x1000:

75410_75410.pngpastedImage_0.png

while , when i download it , it show this error

:

75411_75411.pngpastedImage_1.png

And it can not run .

The attachment is my project .

Thank  very much !

Labels (1)
0 Kudos
3 Replies

379 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

In case of the CPU reset the Stack pointer is loaded from the address 0x0000_0000 and the Program Counter is loaded from the address 0x0000_0004. The stack pointer and startup function addresses are located in the generated vector table by default. Therefore the reallocation of the interrupt vector table in the linker command file only cause the failure of the application.

If you want to move the vector table in memory you must ensure that address 0x0000_0000 contains the stack pointer, the address 0x0000_0004 contains the reset vector (startup function) and the SCB_VTOR register (in System Control Block) is initialized properly (it contains the offset of the vector table).

If you have a Processor Expert project (without KSDK) in KDS 3.0.0 the SCB_VTOR register is initialized in the CPU_Init.c (PEX_ENTRYPOINT_FUNCTION()). The startup rotuine (__thumb_startup(void)) is defined in the Project_Settings/Startup_Code/startup.c source code file.

Best Regards,

Marek Neuzil

0 Kudos

379 Views
Fan_xy
Contributor III

Hello Merek,

Thank for your help !

And i change the code here :

void __attribute__ ((weak)) __init_hardware(void)

{

    SCB_VTOR = (uint32_t)__vector_table; /* Set the interrupt vector table position */

}

While it still can not work, could you please help me to change my project . KDS3.0 , PE without SDK .

Thank !

0 Kudos

379 Views
marek_neuzil
NXP Employee
NXP Employee

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

0 Kudos