cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMx, FreeRTOS, LwIP and MBEDTLS - mbedtls_calloc fails to allocate - what to check?

bully
Senior

Hello,

I've generated simple SSL Client example from CubeMX using FreeRTOS, MBED TLS and LwIP components. I'd like to connect to SSL server (test server present in CubeF4 package).

I have pretty similar default settings for these components from CubeMX. Obviously I don't have memory available, or maybe something is wrong with settings and dynamic allocation is not possible.

This part of code fails (it tries to allocate 935 bytes for certificate parsing :

if( ( buf = mbedtls_calloc( 1, len ) ) == NULL )
        return( MBEDTLS_ERR_PEM_ALLOC_FAILED );

Can anyone please help, what settings to check or how to analyze this problem correctly to get to the solution ?

Thanks in advance,

regards,

Bully.

2 REPLIES 2
bully
Senior

In such combination of components it seems that default settings for dynamic allocation of objects in MBEDTLS are not working out of the box.

You need to decide and setup a proper dynamic allocation strategy. I've solved this problem by using MBEDTLS_MEMORY_BUFFER_ALLOC_C way.

Could you elaborate on the solution you found?

Is MBEDTLS_MEMORY_BUFFER_ALLOC_C set-able from the STM32CubeIde? If so, I haven't been able to find it.

or do I have to set it manually in a header file?

What else do I have to do to make this work?