K64F, MQX RTOS, and trying to configure the memory map.

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

K64F, MQX RTOS, and trying to configure the memory map.

806 Views
xxx
Contributor I

Hello, I am running the K64F, MQX RTOS, and am trying to configure the memory map. I can run my application using the default linker directive file. However, in order to maximize the available SRAM, I want to put the .bss and Stack in the lower SRAM (64K section) and the .data and Heap in the upper SRAM (192K section). I been able to move the segments around, but the behavior seems somewhat erratic, such as the heap needing to take up all remaining space in the second data region. Has anyone attempted such a non-standard memory layout? Are there limitations as to what segments can be placed in certain sections of the SRAM? Also, it looks like there is code in MQX that is expecting the memory map to be layed out in the traditional order.

0 Kudos
3 Replies

457 Views
xxx
Contributor I

Hi Carlos,

Thank you for replying. Please see below for the linker directive file that I have modified to meet my needs. I also included the kinetis.h file, as I had to make some modifications to the __HEAP_START and __HEAP_END defines because of the non-standard configuration. How much heap is typically needed for a program running on the Kinetis board? It seems that the application I am running requires a great deal, as I have many classes I am newing at start-up.

----------------------------------------Linker Directive File ---------------------------

/* Entry Point */

ENTRY(Reset_Handler)

HEAP_SIZE  = DEFINED(__heap_size__)  ? __heap_size__  : 0x00;

STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;

/* Specify the memory areas */

MEMORY {

  m_interrupts          (RX)  : ORIGIN = 0x00000000, LENGTH = 0x00000400

  m_flash_config        (RX)  : ORIGIN = 0x00000400, LENGTH = 0x00000010

  m_interrupts_ram      (RW)  : ORIGIN = 0x1FFF0000, LENGTH = 0x00000400

  m_text                (RX)  : ORIGIN = 0x00000410, LENGTH = 0x000FFBF0

  m_data                (RW)  : ORIGIN = 0x1FFF0400, LENGTH = 0x0000FC00

  m_data_2              (RW)  : ORIGIN = 0x20000000, LENGTH = 0x00030000

}

/* Define output sections */

SECTIONS

{

  /* The startup code goes first into INTERNAL_FLASH */

  .interrupts :

  {

    __VECTOR_TABLE = .;

    . = ALIGN(4);

    KEEP(*(.isr_vector))     /* Startup code */

    . = ALIGN(4);

  } > m_interrupts

  __VECTOR_RAM = ORIGIN(m_interrupts_ram);

  .flash_config :

  {

    . = ALIGN(4);

    KEEP(*(.FlashConfig))    /* Flash Configuration Field (FCF) */

    . = ALIGN(4);

  } > m_flash_config

  /* The program code and other data goes into INTERNAL_FLASH */

  .text :

  {

    . = ALIGN(4);

    *(.text)                 /* .text sections (code) */

    *(.text*)                /* .text* sections (code) */

    *(.rodata)               /* .rodata sections (constants, strings, etc.) */

    *(.rodata*)              /* .rodata* sections (constants, strings, etc.) */

    *(.glue_7)               /* glue arm to thumb code */

    *(.glue_7t)              /* glue thumb to arm code */

    *(.eh_frame)

    KEEP (*(.init))

    KEEP (*(.fini))

    . = ALIGN(4);

  } > m_text

  .ARM.extab :

  {

    *(.ARM.extab* .gnu.linkonce.armextab.*)

  } > m_text

  .ARM :

  {

    __exidx_start = .;

    *(.ARM.exidx*)

    __exidx_end = .;

  } > m_text

.ctors :

  {

    __CTOR_LIST__ = .;

    /* gcc uses crtbegin.o to find the start of

       the constructors, so we make sure it is

       first.  Because this is a wildcard, it

       doesn't matter if the user does not

       actually link against crtbegin.o; the

       linker won't look for a file to match a

       wildcard.  The wildcard also means that it

       doesn't matter which directory crtbegin.o

       is in.  */

    KEEP (*crtbegin.o(.ctors))

    KEEP (*crtbegin?.o(.ctors))

    /* We don't want to include the .ctor section from

       from the crtend.o file until after the sorted ctors.

       The .ctor section from the crtend file contains the

       end of ctors marker and it must be last */

    KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors))

    KEEP (*(SORT(.ctors.*)))

    KEEP (*(.ctors))

    __CTOR_END__ = .;

  } > m_text

  .dtors :

  {

    __DTOR_LIST__ = .;

    KEEP (*crtbegin.o(.dtors))

    KEEP (*crtbegin?.o(.dtors))

    KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors))

    KEEP (*(SORT(.dtors.*)))

    KEEP (*(.dtors))

    __DTOR_END__ = .;

  } > m_text

  .preinit_array :

  {

    PROVIDE_HIDDEN (__preinit_array_start = .);

    KEEP (*(.preinit_array*))

    PROVIDE_HIDDEN (__preinit_array_end = .);

  } > m_text

  .init_array :

  {

    PROVIDE_HIDDEN (__init_array_start = .);

    KEEP (*(SORT(.init_array.*)))

    KEEP (*(.init_array*))

    PROVIDE_HIDDEN (__init_array_end = .);

  } > m_text

  .fini_array :

  {

    PROVIDE_HIDDEN (__fini_array_start = .);

    KEEP (*(SORT(.fini_array.*)))

    KEEP (*(.fini_array*))

    PROVIDE_HIDDEN (__fini_array_end = .);

  } > m_text

  __etext = .;    /* define a global symbol at end of code */

  __DATA_ROM = .; /* Symbol is used by startup for data initialization */

  .data : AT(__DATA_ROM)

  {

    . = ALIGN(4);

    __DATA_RAM = .;

    __data_start__ = .;      /* create a global symbol at data start */

    *(.data)                 /* .data sections */

    *(.data*)                /* .data* sections */

    KEEP(*(.jcr*))

    . = ALIGN(4);

    __data_end__ = .;        /* define a global symbol at data end */

  } > m_data_2

 

  /* Symbol is used by startup for data initialization */

  __DATA_END = __DATA_ROM + (__data_end__ - __data_start__);

  __m_interrupts_ram_ROMStart = __DATA_ROM + SIZEOF(.data);

  .m_interrupts_ram : AT(__m_interrupts_ram_ROMStart)

  {

     . = ALIGN(4);

     __m_interrupts_ram_RAMStart = .;

     *(.m_interrupts_ram)    /* This is an User defined section */

    . += 0x0400;

     __m_interrupts_ram_RAMEnd = .;

     . = ALIGN(4);

  } > m_interrupts_ram

  __m_interrupts_ram_ROMSize = __m_interrupts_ram_RAMEnd - __m_interrupts_ram_RAMStart;         

  __RAM_VECTOR_TABLE_SIZE_BYTES = __m_interrupts_ram_RAMEnd - __m_interrupts_ram_RAMStart;

  __m_data_2_ROMStart = __m_interrupts_ram_ROMStart + SIZEOF(.m_interrupts_ram);

  .m_data_2 : AT(__m_data_2_ROMStart)

  {

     . = ALIGN(4);

     __m_data_2_RAMStart = .;

     *(.m_data_2)            /* This is an User defined section */

     __m_data_2_RAMEnd = .;

     . = ALIGN(4);

  } > m_data_2

  __m_data_2_ROMSize = __m_data_2_RAMEnd - __m_data_2_RAMStart;         

  /* Uninitialized data section */

  .bss :

  {

    /* This is used by the startup in order to initialize the .bss section */

    . = ALIGN(4);

    __START_BSS = .;

    __bss_start__ = .;

    *(.bss)

    *(.bss*)

    *(COMMON)

    . = ALIGN(4);

    __bss_end__ = .;

    __END_BSS = .;

  } > m_data

 

  .heap :

  {

    . = ALIGN(8);

    __end__ = .;

    PROVIDE(end = .);

    __HeapBase = .;

    . += HEAP_SIZE;

    __HeapLimit = .;

  } > m_data_2

  .stack :

  {

    . = ALIGN(8);

    . += STACK_SIZE;

  } > m_data

  __StackTop   = ORIGIN(m_data) + LENGTH(m_data);

  __StackLimit = __StackTop - STACK_SIZE;

  __heap_start = __data_end__ ;

  __heap_end = __data_end__ + HEAP_SIZE;

  PROVIDE(__stack = __StackTop);

  .ARM.attributes 0 : { *(.ARM.attributes) }

}

---------------------------------------- Kinetis File ---------------------------

* See license agreement file for full license terms including other

* restrictions.

*****************************************************************************

*

* Comments:

*

*   This file contains the type definitions for the Kinetis microcontrollers.

*

*

*END************************************************************************/

#ifndef __kinetis_h__

#define __kinetis_h__

#ifndef __ASM__

    #include <mqx.h>

/* Include FSK device registers from Platform SDK */

    #include "fsl_device_registers.h"

    #include "nvic.h"

    #include "kinetis_mpu.h"

#endif /* __ASM__ */

#ifdef __cplusplus

extern "C" {

#endif

/*

*******************************************************************************

**

**                 LINKER SYMBOLS ACCESS

**

*******************************************************************************

*/

/* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */

#if defined(__CC_ARM) /* Keil MDK */

    extern uint32_t Image$$ARM_LIB_HEAP$$Base[];

    extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];

    extern uint32_t Image$$VECTOR_ROM$$Base[];

    extern uint32_t Image$$VECTOR_RAM$$Base[];

    #define __VECTOR_TABLE Image$$VECTOR_ROM$$Base

    #define __VECTOR_RAM Image$$VECTOR_RAM$$Base

    #define __HEAP_START Image$$ARM_LIB_HEAP$$Base

    #define __HEAP_END Image$$ARM_LIB_STACK$$ZI$$Base  /* Segment is defined in opposite way (from higher address to lower) than usually!!!  */

#elif defined(__ICCARM__) /* IAR */

    #pragma section = "ZI"

    #define __ZI_END  (__section_end("ZI"))

    #pragma section = "RW"

    #define __RW_END  (__section_end("RW"))

    #pragma section = "HEAP"

    #define __HEAP_START  (__section_begin("HEAP"))

    #pragma section = "CSTACK"

    #define __HEAP_END  (__section_begin("CSTACK"))

    extern uint32_t __VECTOR_TABLE[NUMBER_OF_INT_VECTORS * sizeof(uint32_t)];

    extern uint32_t __VECTOR_RAM[NUMBER_OF_INT_VECTORS * sizeof(uint32_t)];

#elif defined(__GNUC__) /* GCC */

    //extern uint32_t __bss_end__[];

    //extern uint32_t __StackLimit[];

    extern uint32_t __heap_start[];

    extern uint32_t __heap_end[];

    #define __HEAP_START __heap_start

    #define __HEAP_END  __heap_end

    extern uint32_t __VECTOR_TABLE[NUMBER_OF_INT_VECTORS * sizeof(uint32_t)];

    extern uint32_t __VECTOR_RAM[NUMBER_OF_INT_VECTORS * sizeof(uint32_t)];

#else

    #error Unsupported tool

#endif

<Extra lines removed>

0 Kudos

457 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi X X,

I am very sorry I have not answered. What MQX version are you using? I find strange that you are using a generic linker file.

Regards,

Carlos

0 Kudos

457 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi X X,

it is definitely possible, if you attach the linker file with the edits you made I can take a look to it.

Regards,

Carlos

0 Kudos