alloc task stack in mqx

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

alloc task stack in mqx

Jump to solution
1,183 Views
master_szumi
Contributor III

when i'm using _mem_alloc(size)

mqx allocates memory over tasks stacks

 

I want allocate memory from secify task stack (task with _mem_alloc execute). Is it possible?

 

How check how many free ram memory left in IAR using MQX TAD plugin?

 

 

0 Kudos
1 Solution
584 Views
DavidS
NXP Employee
NXP Employee

Hi Master_szumi,

Declaring the variable within the task will use the task stack.

Using the _mem_alloc() get memory from the heap.

Declaring a variable "static" will place it in the BSS space.

 

Note that the Kinetis family with 128KB SRAM actually has that memory in two 64KB blocks.  The architecture doesn't let you allocate variable across the 0x2000_0000 boundary.  So to declare a 64KB or larger memory block needs to be parsed/divided into smaller blocks.  I've attached ".gif" to show the heap used for two big buffers.  I've also attached the source file I used to play around on the TWRK60.

 

Hope this helps.

Regards,

David

View solution in original post

0 Kudos
5 Replies
584 Views
PhilH
Contributor II

_mem_alloc() should not alloc over your task stacks.  One possibility is that the task that is calling _mem_alloc() to allocate the memory for the task stacks might be exiting.  The MQX behavior on a task exiting is to free all memory it has allocated.  Find out what task is initializing your other tasks and make sure it is not exiting.

0 Kudos
584 Views
master_szumi
Contributor III

my task is very simply:

 

void Easy_Task(uint_32 dummy)

{

  void * mem = _mem_alloc(32);
  _mem_free(mem);

}

 

In stack usage I see that stack for this task is from 0x...d490 ti 0x...d590 (256 bytes)

and my local variable address is 0x...d5ac so its over stack!

 

 

 

0 Kudos
584 Views
DavidS
NXP Employee
NXP Employee

Hi Master_szumi,

The _mem_alloc() function call is getting space from the system heap and not from the task stack.

Hope this helps.

Regards,

David

 

0 Kudos
584 Views
master_szumi
Contributor III

Ok.

 

But is any chance (method) to get it from task stack?

 

 

Other problem:

 

Im using k60n512 with 128kB ram. I'm using _mem_alloc() to alloc memory but when I try alloc more than 64kB function gives me NULL (so mqx can not allocate) - I dont know why? I think that simple task can not takes other 64kb! Where problem is?

 

 

0 Kudos
585 Views
DavidS
NXP Employee
NXP Employee

Hi Master_szumi,

Declaring the variable within the task will use the task stack.

Using the _mem_alloc() get memory from the heap.

Declaring a variable "static" will place it in the BSS space.

 

Note that the Kinetis family with 128KB SRAM actually has that memory in two 64KB blocks.  The architecture doesn't let you allocate variable across the 0x2000_0000 boundary.  So to declare a 64KB or larger memory block needs to be parsed/divided into smaller blocks.  I've attached ".gif" to show the heap used for two big buffers.  I've also attached the source file I used to play around on the TWRK60.

 

Hope this helps.

Regards,

David

0 Kudos