cancel
Showing results for 
Search instead for 
Did you mean: 

MBEDTLS / STM32CubeMX Broken?

paulrbryson
Associate III

I am trying to implement an MBEDTLS client based on an ST example. The MBEDTLS code fails when it tries to allocate memory using calloc. Apparently, users have been experiencing this for over a year.

https://community.st.com/s/question/0D50X0000ArVXNhSQO/cubemx-freertos-lwip-and-mbedtls-mbedtlscalloc-fails-to-allocate-what-to-check

The MBEDTLS code uses dynamic memory allocation (calloc()) which apparently is incompatible with FreeRTOS.

  1. Is there an easy work around?
  2. Do I need to write my own memory allocation?
  3. Am I going to run into problems with LWIP stack?

I am not an experienced embedded programmer. I am willing to try to work around this problem; but, I don't want to keep running into road block after road block. I will soon have to consider moving to another platform.

3 REPLIES 3
paulrbryson
Associate III

I found a solution to the memory allocation issue. Although I do not yet have my application working.

In "mbedtls_config.h" uncomment these defines:

MBEDTLS_MEMORY_BUFFER_ALLOC_C 

MBEDTLS_PLATFORM_MEMORY 

MBEDTLS_PLATFORM_C

And then you must add a statically defined memory buffer for MBEDTLS.

Add these lines to application code (buffer may need to be larger):

unsigned char memory_buf[40000];
 
mbedtls_memory_buffer_alloc_init( memory_buf, sizeof(memory_buf) );

MBEDTLS does not work with FreeRTOS as is. STM32CubeMX should address these items automatically; probably with a config item for the size of the static bufffer.

alister
Lead

>MBEDTLS does not work with FreeRTOS as is. STM32CubeMX should address these items 

Each developer's circumstances may differ.

Mbed TLS' memory allocation options are well documented.

It's your code. You choose your allocation strategy. Don' task ST to do it as then you're lumped with having to work with it or around it.

Sorry, but the whole point of CubeMX is to produce WORKING code - otherwise why bother. Your assertion makes no sense, because either way, I can modify the code to match my requirements. Why not start with working code?