Page 1 of 1

Memory allocation failed hook

Posted: Wed Jun 03, 2020 4:07 am
by ntremble
Hello,

I am one of a team developing a commercial product based on the ESP_WROVER module. Up until now we have been using IDF v3.3, but are now moving to IDF v4, specifically I am currently using: ESP-IDF v4.2-dev-1320-g1aebfdf6a.

I have been seeing some malloc failures, so I thought I would implement the malloc failure hook as described in the IDF documentation:
https://docs.espressif.com/projects/esp ... ailed-hook
https://docs.espressif.com/projects/esp ... allocation
but when I attempt to compile this various errors are generated, two of which are:
error: implicit declaration of function 'heap_caps_register_failed_alloc_callback' [-Werror=implicit-function-declaration]
error: 'TaskHandle_t' does not name a type; did you mean 'xTaskHandle'?
It seems that the heap tracing code has not been ported to the new IDF properly as yet. Is this correct, and are there any plans to do so?

Regards,
Neil

Re: Memory allocation failed hook

Posted: Wed Jun 03, 2020 2:26 pm
by WiFive
Looks like you are just missing some includes?

Re: Memory allocation failed hook

Posted: Wed Jun 03, 2020 6:48 pm
by ESP_ulipe
Hi Neil, thanks for reporting these errors.

Are you adding the

Code: Select all

esp_heap_caps.h
as a include in the file that calls the

Code: Select all

heap_caps_register_failed_alloc_callback
?

In the same way, are the files

Code: Select all

FreeRTOS.h
and

Code: Select all

task.h
being included as well?

As mentioned above, if this file inclusion is missing, the implicit function declaration warning will be triggered, since the warnings are treated as errors, you will see the errors above.

If possible, could you please post the code that is trying to use these features from heap component?

Cheers.

Re: Memory allocation failed hook

Posted: Wed Jul 01, 2020 11:50 pm
by ntremble
Hello,

Thank you for replying and I am sorry I did not get back to you sooner, but I have been distracted by other things :-(

Anyway, I was indeed including the correct headers. This morning I grabbed the latest ESP-IDF and recompiled to find that worked ok with no changes to my code, so I compared old and new and found the following had been added to heap/include/esp_heap_caps.h:

Code: Select all

/**
 * @brief callback called when a allocation operation fails, if registered
 * @param size in bytes of failed allocation
 * @param caps capabillites requested of failed allocation
 * @param function_name function which generated the failure
 */ 
typedef void (*esp_alloc_failed_hook_t) (size_t size, uint32_t caps, const char * function_name);

/**
 * @brief registers a callback function to be invoked if a memory allocation operation fails
 * @param callback caller defined callback to be invoked
 * @return ESP_OK if callback was registered.
 */  
esp_err_t heap_caps_register_failed_alloc_callback(esp_alloc_failed_hook_t callback);
The versions concerned were v4.2-dev-1320-g1aebfdf6a and v4.2-dev-1905-g625bd5eb1.

So the version of the IDF I was using was incomplete in this area as I suspected. All good now.

Regards,
Neil