memory allocation before MQX starts

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

memory allocation before MQX starts

Jump to solution
738 Views
michaelhuslig
Contributor IV

I want to keep some data of variable size in an area of RAM between the end of the MQX kernal data and top of RAM.  Since the size is variable, I can't just modify the .lcf linker file.  Is there an easy way to tell MQX to set its own data somewhere else?  Or is there a better place to put this block of RAM.  What I want to do is be able to upload new code to the K40 and reset without affecting this memory.

0 Kudos
1 Solution
352 Views
michaelhuslig
Contributor IV

Sorry for taking so long; I had hoped to have a final solution before now.

 

I copied the MQX initialization structure to main.c and removed the const keyword so that the structure would end up in RAM:

 

MQX_INITIALIZATION_STRUCT  MQX_init_struct =

{

/* PROCESSOR_NUMBER                */  BSP_DEFAULT_PROCESSOR_NUMBER,

/* START_OF_KERNEL_MEMORY          */  BSP_DEFAULT_START_OF_KERNEL_MEMORY,

/* END_OF_KERNEL_MEMORY            */  BSP_DEFAULT_END_OF_KERNEL_MEMORY,

/* INTERRUPT_STACK_SIZE            */  BSP_DEFAULT_INTERRUPT_STACK_SIZE,

....

 

This allows me to change the default end of kernel memory in the beginning of main.c before I start MQX with

 

_mqx( (MQX_INITIALIZATION_STRUCT_PTR) &MQX_init_struct );

 

But since the original linker .lcf file had the boot stack located near the end of the original MQX space, I had to delete the original bstack segment and add my own stack before the beginning of the MQX space:

 

    .main_application_bss :

    {

        . =

ALIGN(0x10);

        __START_SBSS = .;

        *(.sbss)

        *(SCOMMON)

        __END_SBSS = .;

 

        __START_BSS = .;

        *(.bss)

        *(COMMON)

        __END_BSS = .;

        . =

ALIGN(16);

        _stack_end = .;

        .=.+0x200;

        _stack_addr = .;

        __SP_INIT    = .;

        __BOOT_STACK_ADDRESS = .;

    } >> ram

 

    .kernel_data :

#AT(ADDR(.main_application_bss) + SIZEOF(.main_application_bss))

    {

        __KERNEL_DATA_START =

ALIGN(0x10);

    }

   

...

 

I had tried to put the boot stack at the beginning of the MQX space, but when MQX starts it continues to use the boot stack for a while before setting up its own stack;  in the process of setting up its space, MQX was apparently overwriting the boot stack.

 

I will eventually look into putting the boot stack at beginning of the MQX space, adjust the end of the MQX space as above, and then set the stack pointer to the end of the shortened MQX space just before starting MQX;  that way I will not have wasted RAM space on a boot stack that is never used after MQX starts.

View solution in original post

0 Kudos
3 Replies
352 Views
michaelhuslig
Contributor IV

Figured it out. Can I remove the initial post?

0 Kudos
352 Views
c0170
Senior Contributor III

Hi michael husling,

 

great you figure it out therefore it would be appriciated if you can post your solution. Thanks!

 

Regards,

MartinK

0 Kudos
353 Views
michaelhuslig
Contributor IV

Sorry for taking so long; I had hoped to have a final solution before now.

 

I copied the MQX initialization structure to main.c and removed the const keyword so that the structure would end up in RAM:

 

MQX_INITIALIZATION_STRUCT  MQX_init_struct =

{

/* PROCESSOR_NUMBER                */  BSP_DEFAULT_PROCESSOR_NUMBER,

/* START_OF_KERNEL_MEMORY          */  BSP_DEFAULT_START_OF_KERNEL_MEMORY,

/* END_OF_KERNEL_MEMORY            */  BSP_DEFAULT_END_OF_KERNEL_MEMORY,

/* INTERRUPT_STACK_SIZE            */  BSP_DEFAULT_INTERRUPT_STACK_SIZE,

....

 

This allows me to change the default end of kernel memory in the beginning of main.c before I start MQX with

 

_mqx( (MQX_INITIALIZATION_STRUCT_PTR) &MQX_init_struct );

 

But since the original linker .lcf file had the boot stack located near the end of the original MQX space, I had to delete the original bstack segment and add my own stack before the beginning of the MQX space:

 

    .main_application_bss :

    {

        . =

ALIGN(0x10);

        __START_SBSS = .;

        *(.sbss)

        *(SCOMMON)

        __END_SBSS = .;

 

        __START_BSS = .;

        *(.bss)

        *(COMMON)

        __END_BSS = .;

        . =

ALIGN(16);

        _stack_end = .;

        .=.+0x200;

        _stack_addr = .;

        __SP_INIT    = .;

        __BOOT_STACK_ADDRESS = .;

    } >> ram

 

    .kernel_data :

#AT(ADDR(.main_application_bss) + SIZEOF(.main_application_bss))

    {

        __KERNEL_DATA_START =

ALIGN(0x10);

    }

   

...

 

I had tried to put the boot stack at the beginning of the MQX space, but when MQX starts it continues to use the boot stack for a while before setting up its own stack;  in the process of setting up its space, MQX was apparently overwriting the boot stack.

 

I will eventually look into putting the boot stack at beginning of the MQX space, adjust the end of the MQX space as above, and then set the stack pointer to the end of the shortened MQX space just before starting MQX;  that way I will not have wasted RAM space on a boot stack that is never used after MQX starts.

0 Kudos