Malloc problems

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

Malloc problems

2,046 Views
Ardoster
Contributor III

Hi

 

I'm having big problems with malloc instructions. My code works correctly, but when I add support for rtcs module (http and ftp server), the http server and ftp server stop working. Although the board still responds to ping commands. In the other hand, if I disable some tasks, the rtcs module runs correctly.

 

I'm guessing the problem is in malloc functions of rtcs module, because I obtain errors in these functions when using all my tasks. So, what can I do? How must I do to increment the memory pool? Is there some other solution?

 

Thanks in advance

 

Regards

Eduardo

0 Kudos
8 Replies

496 Views
c0170
Senior Contributor III

Hello ardoster,

 

are you certain you are out of memory? What errors do you get? Do you use TAD?

 

If you are really out of memory, there's one advice to extend your memory. On the other hand, you can also test to decrease memory consuption. Like task stack sizes,etc.

 

Regards,

MartinK

0 Kudos

496 Views
Ardoster
Contributor III

Well. I think I'm having memory problems because when my rtcs module stops working correctly, the problem is the malloc functions (like for example HTTPD_MALLOC) returns error. Right now, I'm making some test, modifying the stack size of every task, or limiting the maximum number of sockets. I'm also making this tests using all the opmization options. Anyway, I'm really very surprised about these memory problems. In this moment is when I would like be able to use the advanced MQX OS debugging tools, but I don't have that license.

 

When I get some conclusion, I'll publish here. The problem is today I'll leave on holidays :-p

 

What is TAD?

 

Thanks you

Regards,

Eduardo

0 Kudos

496 Views
DavidS
NXP Employee
NXP Employee

Hi Eduardo,

TAD (task aware debugging) is a capability of the debugger to look at the RTOS and RTCS capabilities in the GUI but is only supported with the professional version of CW10.x but is part of IAR and I think Keil debuggers.

You can use a tad.c routine in the PSP to look at your stack usage from a command prompt.

Reference: psp_twrk60n512->PSP Generic->tad->tad.c _tad_stack_usage().

 

For Kinetis devices with 128Kbytes SRAM I've had webserver, telnet, and ftp running OK.  But if you target a device with less than 128Kbytes SRAM, then you need to only enble one of the Ethernet applications at a time.

Regards,

David

0 Kudos

496 Views
Ardoster
Contributor III

Hello

Your help has been very useful. I'm currently using the tad.c routine you commented, and at least I'm able to know how percentage of memory I'm using of stack in every task. I've checked every task is in their limits. So no overflow.

But I'm still having the malloc problems. How can I know how many RAM memory I'm using???

The problem I'm having is very curious: when i'm just running the http server (no more tasks, even ftp server or my application tasks) I'm able to do simultaneous http petitions: Through http, i can download an image of about 500K with no problems. While this image is being downloaded, I can make a second http petition. And when the first image has been downloaded, the second one (second petition) is started to be downloaded. This is the correct behaviour.

But when I have running the other application's tasks. The second petition is never processed because a malloc problem in ta_init.c -> _task_init_internal(). And after this error, no more http petitions are being processed.

This is a memory problem. What can I do to fix this problem??? Any suggestion?

Thanks you in advance.

Regards,

Eduardo

0 Kudos

496 Views
Ardoster
Contributor III

Hi again

How I could know how big is my heap pool? How I could increase the heap???

I think I'm not having very clear these concepts... so all help would be very useful.

Thanks you in advance. Regards,

Eduardo

0 Kudos

496 Views
DavidS
NXP Employee
NXP Employee


Hi Eduardo,

Hope the vacation was good!

The heap is defined in the linker file.  The MQX RTOs actually only uses a few hundred bytes of SRAM and the remaining SRAM space is dedicated to the heap which the RTOS then maintains with alloc/dealloc functions.  The MCF52259 is limited with 64Kbytes so having lots of Ethernet applications (i.e. http sever, telnet, ftp) is a no no because you run out of memory to alloc.

Adding external memory to have an additional memory pool can work.

Several other posts to review:

https://community.freescale.com/thread/300442

https://community.freescale.com/thread/56690

For code size you can look at the following path in the MQX folder:

C:\Freescale\Freescale MQX 3.8\mqx\examples\benchmrk\codesize\results\m52259evb_cwcf7_report.html

Regards,

David

0 Kudos

496 Views
Ardoster
Contributor III

Thanks you. I'll think about it. Although for now I can't modify the hw...

:smileysad:

Regards,

Eduardo

On Fri, Sep 21, 2012 at 4:49 PM, David E Seymour <

0 Kudos

496 Views
Ardoster
Contributor III

Hello David

Sorry the delay to reply you, but I've been on holidays. This is my first day at work after 3 weeks... :-(

Well, we don't have the TAD license, although it would be really very useful at this moment. I guess that this module is mandatory to use the tad.c routine you are refering, isn't it?

Anyway, I forgot to say that my device is a Coldfire MCF52259, so I have 512KB Flash, but just 64KB RAM. How can I know more about the memory requisites of every module/option of the RTCS package??? You must understand I need to be sure there's nothing to do at sw level before changing my hardware.

Thanks you a lot of for your reply

Regards,

Eduardo

0 Kudos