malloc

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

uglyoldbob
Posts: 11
Joined: Fri Feb 24, 2012 7:36 pm

malloc

Fri Mar 23, 2012 3:37 am

I'm using a modified version of some of the example code available from Atmel for my project, but I need to use the malloc function now.

What is the best way of getting this implemented on the AT91SAM3U4?
przemekbary
Posts: 68
Joined: Fri Mar 09, 2012 1:34 pm

Re: malloc

Fri Mar 23, 2012 10:16 am

Hi!
Isn't it declared in stdlib.h? Remeber to reserve memory in the heap by an appropriate entry in the scatter file.

...
ARM_LIB_HEAP 0x76FFD000 EMPTY 0x20000 {
}

ARM_LIB_STACK 0x76000000 EMPTY -0x2000 {
}
...
Best regards
Przemyslaw Baranski
uglyoldbob
Posts: 11
Joined: Fri Feb 24, 2012 7:36 pm

Re: malloc

Sat Mar 24, 2012 6:55 am

The problem I get from compiling is that _sbrk is undefined.
przemekbary
Posts: 68
Joined: Fri Mar 09, 2012 1:34 pm

Re: malloc

Sat Mar 24, 2012 10:21 am

Hi!
I haven't experienced the problem. Could you have a look at:
http://embdev.net/topic/129753
http://embdev.net/topic/152798
That the only thing I can help you
Best regards
Przemyslaw Baranski
frame
Posts: 17
Joined: Mon Apr 23, 2012 10:32 am

Re: malloc

Tue Apr 24, 2012 11:28 am

The _sbrk() function is a system call, which enlarges an already allocated memory block.

You should really think long and hard before pulling in these OS stuff. The whole malloc() idea (or new in C++) originates from larger systems with virtual memory and MMU. This is an environment were you assumed not to know anything of actual addresses - things which are essential in this kind of embedded systems.

Are you ready to handle out-of-memory events at runtime on your Cortex M3 application ?

If you can get away with a roll-your-own, static memory allocation, you probably spare yourself a lot of hassle.

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests