Memory allocation failed hook

ntremble
Posts: 4
Joined: Wed Jun 03, 2020 3:43 am

Memory allocation failed hook

Postby ntremble » Wed Jun 03, 2020 4:07 am

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

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Memory allocation failed hook

Postby WiFive » Wed Jun 03, 2020 2:26 pm

Looks like you are just missing some includes?

ESP_ulipe
Posts: 7
Joined: Fri Mar 27, 2020 8:13 pm
Location: Campinas, SP - Brazil

Re: Memory allocation failed hook

Postby ESP_ulipe » Wed Jun 03, 2020 6:48 pm

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.

ntremble
Posts: 4
Joined: Wed Jun 03, 2020 3:43 am

Re: Memory allocation failed hook

Postby ntremble » Wed Jul 01, 2020 11:50 pm

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

Who is online

Users browsing this forum: Gaston1980 and 105 guests