what is the differance in steps( from reset vector to mqx initialisation in case of mqx project and reset vector to main in case of bare board project )for code warrior project with K20D72M

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

what is the differance in steps( from reset vector to mqx initialisation in case of mqx project and reset vector to main in case of bare board project )for code warrior project with K20D72M

Jump to solution
1,076 Views
josephxavier
Contributor III

I am using CodeWarrior for K20D72M board , I just want to know the difference between steps from reset vector to MQX initialization (in case of MQX 4.0 project ) and reset vector to main function in case of bare board project .

1 Solution
804 Views
RadekS
NXP Employee
NXP Employee

__SP_INIT = . + 0x00004000; # set stack to 16kb

__heap_addr = __SP_INIT; # heap grows opposite stack direction

__heap_size = 0x00004000; # set heap to 16kb

} # end SECTIONS segment

More details about lcf file structure you can find in c:\Freescale\CW MCU v10.6\MCU\Help\PDF\MCU_Kinetis_Compiler.pdf document.

GCC compiler use *.ld files with slightly different syntax. - Therefore I mention .heap section.

IAR compiler use *.icf files.

...

I hope it helps you.

View solution in original post

10 Replies
804 Views
RadekS
NXP Employee
NXP Employee

In “classic” MQX:

Reset vector at address 0x00 contains address of __boot function and stack pointer (filled by linker). They will be loaded automatically during reset sequence.

__boot function in boot.s contains code for these steps:

  1. Disable interrupts and clear pending flags
  2. Setup and switch to process stack
  3. If MCU has FPU and we enable it, code will initialize FPU module
  4. Call toolchain_startup function

toolchain_startup function is toolchain dependent function which will:

  1. initialize necessary hardware (clocks, ddr, watchdog, ...)
  2. initialize data - copy static variables from flash to RAM and clear zero sections
  3. Call main() function

Main() function in mqx_main.c file call MQX (function _mqx()).

The bareboard startup does almost the same with exception of process stack – this is not necessary for bareboard project.

In CW bareboard project __thumb_startup() function in __arm_start.c file will initialize stack, hardware, FPU unit (if necessary), initialize data in RAM and call main() function. Some of init functions are located in __arm_eabi_init.c file

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
804 Views
josephxavier
Contributor III

Thanks for your advice , I am able to use malloc in the bare board project ,but I am not able to use malloc before the mqx_init in a mqx 4.0 project .

What is the reason for this ? I am using freescale tool chain.

0 Kudos
804 Views
RadekS
NXP Employee
NXP Employee

Thank you for more specify question.

This behavior is most probably caused by missing user heap in MQX linker file.

In bare metal code, you have statically defined heap where you can allocate memory by malloc() function (and de-allocate by free() function).

Since MQX use all remaining RAM memory as MQX heap, this RAM area is initialized during MQX initialization. In MQX you have integrated allocators, therefore statically allocated heap presents wasting of RAM resources in most of cases.

So, If you want use malloc() and free() functions prior you run MQX, you have to modify linker file…

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

804 Views
josephxavier
Contributor III

What are the modification to be done to the linker file.

And where exactly is the heap statically defined in the bare board code.

0 Kudos
804 Views
RadekS
NXP Employee
NXP Employee

I suppose that you have to add .heap section and specify heap_size.

However I never do it.

Linker file format depends on your toolchain.

I found nice description of GCC linker file for example here:

http://hertaville.com/2012/06/29/a-sample-linker-script/

804 Views
josephxavier
Contributor III

I am attaching my linker file please specify where exactly is the heap statically defined I am not so familiar with linker scripts

0 Kudos
805 Views
RadekS
NXP Employee
NXP Employee

__SP_INIT = . + 0x00004000; # set stack to 16kb

__heap_addr = __SP_INIT; # heap grows opposite stack direction

__heap_size = 0x00004000; # set heap to 16kb

} # end SECTIONS segment

More details about lcf file structure you can find in c:\Freescale\CW MCU v10.6\MCU\Help\PDF\MCU_Kinetis_Compiler.pdf document.

GCC compiler use *.ld files with slightly different syntax. - Therefore I mention .heap section.

IAR compiler use *.icf files.

...

I hope it helps you.

804 Views
josephxavier
Contributor III

Since MQX use all remaining RAM memory as MQX heap, this RAM area is initialized during MQX initialization. In MQX you have integrated allocators,

Thanks for ur advice , it was said that MQX uses integrated allocators for heap, where is it done in MQX 4.0 projects

0 Kudos
804 Views
RadekS
NXP Employee
NXP Employee

MQX 4.0 could use MEM or LWMEM allocators.

LWMEM allocators are used in default. MCUs with cache like MK70, Vybrid, CF54418 use MEM allocators instead of LWMEM (due to additional code for cached memory).

For allocating please use _mem_alloc() function. Appropriate allocator (MEM or LWMEM) will be selected on base of MQX_USE_LWMEM_ALLOCATOR macro.

There are several versions of _mem_alloc() function with specific behavior like _mem_alloc_zero(), _mem_alloc_align(),_mem_alloc_at() or _mem_alloc_system(), …. For more details please look at MQX reference manual:

c:\Freescale\Freescale_MQX_4_0\doc\mqx\MQXRM.pdf

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
804 Views
josephxavier
Contributor III

Can u be more specific ,where exactly in code is this RAM area initialized during MQX initialization.

0 Kudos