Heap Allocation - Integrating MQX and PEG+

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

Heap Allocation - Integrating MQX and PEG+

Jump to solution
1,496 Views
OldNick
Contributor IV

Have ported the BSP to my platform (K20) and worked through many of the MQX examples, which all work fine.

 

Now trying to integrate PEG+ into the platform, I have got to the point of building my first GUI application.

 

But at the conclusion of the make I get a linker error telling me there is no heap allocated.

Warning[Lp012]: no sections with name HEAP included - special symbol HEAP$$Base (referenced from xgetmemchunk.o(dl7M_tln.a)) will  be zero.

 

When I run the code, it drops into MQX-idle at the first point where the new operator is called.

 

I am using the icf provided with the MQX examples, which (as supplied) has neither stack nor heap.  This confused me a bit, since C-stack is usually the first thing set up by the RTL.  Therefore I assume that MQX handles stack and heap on its own.?

 

Anyway, I modified the icf from within IAR IDE to give myself a 64k heap, but still got the same linker error.  modified icf attached

 

What I really want to do is put all the GUI volatile stuff into an offchip SRAM which I have put on the board, leaving the On-chip memory for application stuff.  But for now, anything that gives me a heap section would be helpful.

 

Can you suggest anything?  Which manuals should I read?

Tags (1)
0 Kudos
1 Solution
513 Views
OldNick
Contributor IV

OK...sorted now, got help from compiler tech support. :smileyhappy:

 

Did not need to define a heap...DID need to override the new operator so that it uses mqx "_mem_alloc"

 

(Have also been advised to watch out for exception handling, but that depends on level of C++ selected.)

View solution in original post

0 Kudos
4 Replies
513 Views
KJFPE
Contributor III

HI 

 

I had the same problem, try something like this changing the value 0x0800 dependent upon your needs

 

define block HEAP with size = 0x0800, alignment = 8{ };

place in RAM_region {block HEAP};

0 Kudos
514 Views
OldNick
Contributor IV

OK...sorted now, got help from compiler tech support. :smileyhappy:

 

Did not need to define a heap...DID need to override the new operator so that it uses mqx "_mem_alloc"

 

(Have also been advised to watch out for exception handling, but that depends on level of C++ selected.)

0 Kudos
513 Views
KJFPE
Contributor III

can I ask how you overode the new operator to use mqx "_mem_alloc" 

 

thanks

0 Kudos
513 Views
OldNick
Contributor IV

KJFPE wrote:

can I ask how you overode the new operator to use mqx "_mem_alloc" 

 

thanks


Somewhere in your cpp code, you need something like these two

void* operator new (unsigned int size)
{
    void *p = _mem_alloc_system(size);

    if (!p)
    {
//catch null response
    }   
    return(p);
}   

 

void operator delete(void *p)
{
   uint_32 result = _mem_free(p);
   if (result != MQX_OK)
   {
      _task_set_error(result);
   }
}  

And of course, you may need the array versions as well.

 

The functions are provided as part of the graphics library, so I have had to mangle them slightly for this post.  I hope that gves you enough to get the general idea.  If you are using PEG+ there is a define in mqxpeg.hpp (PEG_NEW_DELETE) which is commented out, and shouldn't be.  I think I have said all I ought to. :smileywink:

0 Kudos