Skip to main content
Barbie
Associate III
February 12, 2013
Question

malloc not work on size more then 500 bytes in STM32

  • February 12, 2013
  • 3 replies
  • 930 views
Posted on February 12, 2013 at 13:25

I try to enter malloc for some area at my program

I use IAR 6.4 with STM32F205ZC.

first i annunce the buffer pointer

uint16_t * ADC3ConvertedValue; 

and then I call the function

ADC3ConvertedValue = (uint16_t*) malloc (500 );

free(ADC3ConvertedValue);

I have a lot of free RAM space (use only 18K of 96K) but even I put this function at the beginning of the program it return NULL if I ask more then 500 bytes(even 511). 

Is there more setting i need to do or it is the compiler or the MCU limitation?

Regards

Bar.
    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    February 12, 2013
    Posted on February 12, 2013 at 14:11

    A heap setting?

    Using dynamic memory is usually avoided on embedded systems as the heap is prone to fragment, and allocations fail.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Barbie
    BarbieAuthor
    Associate III
    February 13, 2013
    Posted on February 13, 2013 at 08:21

    So if I increase my heap space can it help?

    Bar.

    Tesla DeLorean
    Guru
    February 13, 2013
    Posted on February 13, 2013 at 08:57

    So if I increase my heap space can it help?

    It will address the near term issue. Where this is done in IAR I'm not sure, but you should be able to define a reasonably large chunk if you choose too. Long term you have to understand your memory usage, if you can use the stack for some of the transient requirements, or if you need to allocate from a fixed pool. What needs static allocation, and can that overlap with other mutually exclusive uses.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..