Hi,
The FreeRTOS documentation suggest to use the pvPortMalloc() / pvPortFree() and vApplicationMallocFailedHook() when handling memory allocation. The ESP-IDF documentation points to heap_caps_malloc() / heap_caps_free() and heap_caps_register_failed_alloc_callback() for the same memory handeling procedures.
So, what would be the correct way of using these functions in a ESP-IDF/FreeRTOS application or maybe the question should be, what memory allocation/handling is included in the ESP-IDF FreeRTOS port?
ESP-IDF vs FreeRTOS heap allocation
Re: ESP-IDF vs FreeRTOS heap allocation
If you need to allocate some general object (e.g., some buffer), you can just use C stdlib malloc. This will just allocate memory with default capabilities. If you need to allocate memory with a specific capability (e.g., DMA capable), then you'll need to call heap_caps_malloc() and specify the capability. FreeRTOS uses heap_caps_malloc() because task stacks must be placed in internal RAM.NRollo wrote: Hi,
The FreeRTOS documentation suggest to use the pvPortMalloc() / pvPortFree() and vApplicationMallocFailedHook() when handling memory allocation. The ESP-IDF documentation points to heap_caps_malloc() / heap_caps_free() and heap_caps_register_failed_alloc_callback() for the same memory handeling procedures.
So, what would be the correct way of using these functions in a ESP-IDF/FreeRTOS application or maybe the question should be, what memory allocation/handling is included in the ESP-IDF FreeRTOS port?
Re: ESP-IDF vs FreeRTOS heap allocation
Thanks for the reply!
So does FreeRTOS pvPortMalloc() also use heap_caps_malloc()? What about the malloc hook/callback functions, which one should be used if you want to cover all "bases"?
So does FreeRTOS pvPortMalloc() also use heap_caps_malloc()? What about the malloc hook/callback functions, which one should be used if you want to cover all "bases"?
Re: ESP-IDF vs FreeRTOS heap allocation
No, because pvPortMalloc() itself is never called. Based on the enabled FreeRTOS configs, pvPortMallocTcbMem() and pvPortMallocStackMem() are called instead. All of these macros are defined in port_macro.hNRollo wrote: So does FreeRTOS pvPortMalloc() also use heap_caps_malloc()?
Do you mean GNU C malloc hooks?NRollo wrote: What about the malloc hook/callback functions, which one should be used if you want to cover all "bases"?
Re: ESP-IDF vs FreeRTOS heap allocation
I am thinking of the FreeRTOS vApplicationMallocFailedHook() and the ESP-IDF heap_caps_register_failed_alloc_callback().
Who is online
Users browsing this forum: ESP_Roland and 262 guests