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 .
Solved! Go to Solution.
__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.
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:
toolchain_startup function is toolchain dependent function which will:
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!
-----------------------------------------------------------------------------------------------------------------------
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.
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!
-----------------------------------------------------------------------------------------------------------------------
What are the modification to be done to the linker file.
And where exactly is the heap statically defined in the bare board code.
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:
__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.
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
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!
-----------------------------------------------------------------------------------------------------------------------
Can u be more specific ,where exactly in code is this RAM area initialized during MQX initialization.