NRF memory management and FreeRTOS coexistence

We use FreeRTOS with nRF SDK driver library. The driver library is working well because it doesn't dynamically allocate any memory. So I can simple take entire memory block from __HeapLimit below and let FreeRTOS heap to mamage the memory.

However, the NRF_LOG module uses nrf_memobj and nrf_balloc to dynamically allocate memory. And it appears to use memory below __HeapLimit.

Question is: How exactly does it work? How much memory shall I reserve for NRF_LOG and what memory block is safe for FreeRTOS to manage?

Thanks

Qingjun

Parents
  • You have a few options here:

    First, you can set FreeRTOS up so it only uses statically allocated memory, so there is no FreeRTOS heap and you can use the heap defined by your programming environment.

    Second, you can define pvPortMalloc() and vPortFree() to use the heap defined by your programming environment.  If you do that then make sure you make it thread safe, as shown here for heap_3.c, which uses the standard C library malloc() and free().

    Third, if possible, you can make the native programming environments memory allocation functions call pvPortMalloc() and vPortFree().

    All the options so far ensure there is only a single heap.  If you want to maintain separate FreeRTOS heap and native environment heap:

    Forth, you can dimension the FreeRTOS heap to be just big enough as needed, and set the native heap size however you would do that normally.  Then allocations made by FreeRTOS (if you don’t allocate everything statically) come from the FreeRTOS heap, and everything else comes form the native environment’s heap.

  • Thank you for your answer. It is exactly what I did.

    I guess I didn't ask the question clearly. The question should be: what is the boundary of NRF heap?

    Without NRF_LOG I don't use any heap. So the boundary is __HeapLimit address, which is the same as __bss_end__ because heap size is 0.

    But NRF_LOG uses dynamic heap allocation. And it can't be disabled even if I just want a non-deferred log. What API shall I call in order to get the end of the NRF heap?

Reply
  • Thank you for your answer. It is exactly what I did.

    I guess I didn't ask the question clearly. The question should be: what is the boundary of NRF heap?

    Without NRF_LOG I don't use any heap. So the boundary is __HeapLimit address, which is the same as __bss_end__ because heap size is 0.

    But NRF_LOG uses dynamic heap allocation. And it can't be disabled even if I just want a non-deferred log. What API shall I call in order to get the end of the NRF heap?

Children
Related