Search code examples
embeddedheap-memorynuttx

Nuttx heap allocation failed: heap-size is zero


I'd like to allocate some memory on mm_heap, but its size is zero: debug mm_heap

This causes the memory allocation to fail. How can I debug this problem?

For reference, I'm using Nuttx on a STM32F765.


Solution

  • The heap size is zero because nothing was ever added to the heap. You can see this because the number of memory regions (mm_nregions) is also zero.

    Memory regions are added to heap by mm_addregion() in mm_initialize(); There is guaranteed to be called at least once to add at least one memory regions. If the number of memory regions is zero this function failed for some reason.

    The only way that the function can fail is it is passed bad parameters. The passing of the parameters is based one provided by the implementation of up_allocateheap() that you are using.

    So what you must to is look at up_allocateheap() to understand what is being passed. The perhaps put a breakpoint of mm_addregion() to see exactly what it is unhappy about.