Defining location for task stacks?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Defining location for task stacks?

跳至解决方案
1,702 次查看
dave408
Senior Contributor II

I was running some tests today with MQX to see how the .bss section grew with changes to the task stack.  While the results are generally predictable (at least I thought so), I was surprised when I adjusted the stack size of one of my tasks, and then I ended up with this error:

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: KDS3_RobotAxis.elf section `.bss' will not fit in region `m_data'

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: region `m_data' overflowed by 784 bytes

A quick search led me to BlackNight​'s post FreeRTOS Heap with Segmented Kinetis K SRAM | MCU on Eclipse .  After looking at the various Kinetis reference manuals, all three of the chips I'm using have the split memory architecture.  I guess I had been lucky up until now to not even realize this is how the processors are designed.  :smileyhappy:

Well, now I'm going to need to get above the 8K lower limit of the MK22FN128FLL10.  Erich had modified his FreeRTOS component to allow the specification of the location of the heap.  I'm using the PEx MQX component, and as far as I can tell, it does not have such an option.  Looking at the linker file, I see that there is an m_data and m_data_2 defined.

How can I make the necessary changes to MQX so that my task stacks are allocated in m_data_2?  Also, are there any issues with tasks accessing data (maybe a global variable) that is defined in m_data?  I apologize for the dumb question, but this is the first time I've dealt with a split memory architecture that doesn't have the details of crossing the boundary abstracted from the user.

1 解答
873 次查看
soledad
NXP Employee
NXP Employee

Hello Dave,

Please check the below thread and let me know if this helps!!

Relocating Code and Data Using the KDS GCC Linker File for Kinetis


Have a great day,
Sol

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

在原帖中查看解决方案

5 回复数
873 次查看
dave408
Senior Contributor II

Here's the actual implementation that I have used with success in my projects.

The thing you might want to do is create a new header file that is #included in os_tasks.h.  I called mine mqxutil.h.  It looks like this:

/*

* mqxutil.h

*

*  Created on: Feb 11, 2016

*      Author: Dave

*/

#ifndef SHARED_MQXUTIL_H_

#define SHARED_MQXUTIL_H_

/*

* This macro is hijacked from the KSDK and modified to put a task's stack into the m_data_2 section

*/

#define OSA_TASK_DEFINE2(task, stackSize) \

    __attribute__((section(".m_data_2"))) task_stack_t task##_stack[MQX_REQUIRED_STACK_SIZE(stackSize)/sizeof(task_stack_t)+1]; \

    task_handler_t task##_task_handler;

#endif /* SHARED_MQXUTIL_H_ */

Now in your Generated_Code folder, in each of the .c files that corresponds to your tasks, just replace "OSA_TASK_DEFINE" with "OSA_TASK_DEFINE2".  This will relocate your task's stack into the m_data_2 segment.

You'll need to disable code generation for your task, or the macro change will get reverted the next time you click the Generate Code button.

Hope this helps someone out!

0 项奖励
873 次查看
dave408
Senior Contributor II

And another really helpful link from FSL technical support: MQX memory usage

874 次查看
soledad
NXP Employee
NXP Employee

Hello Dave,

Please check the below thread and let me know if this helps!!

Relocating Code and Data Using the KDS GCC Linker File for Kinetis


Have a great day,
Sol

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

873 次查看
dave408
Senior Contributor II

soledad As a quick hack, I decided to swap the memory locations for m_data and m_data_2 until I have time to understand the proper method.  While swapping works fine, modifying ProcessorExpert.ld is not a great solution because the file is always overwritten.  This means that I'd have to make the modifications every time I generate code.  I don't see an option to disable code generation for the linker file.  Is there a different way I'm supposed to specify the memory locations?

0 项奖励
873 次查看
dave408
Senior Contributor II

Thanks, Sol, I'm checking it out now!

0 项奖励