Using SPIRAM for mbedtls

If you are asking a question, please follow this template:

  1. My goal is: I’m trying to use SPIRAM for mbedtls calls, as suggested in this post https://github.com/espressif/esp-idf/issues/2184#issuecomment-408209411
  2. My actions are: In my mos.yml I’ve set CONFIG_MBEDTLS_PLATFORM_MEMORY=y in build_vars, and in main.c mgos_app_init I’ve called mbedtls_platform_set_calloc_free(my_calloc, my_free); (which is referenced in mbedtls platform.h.
  3. The result I see is: My app fails to build, with error implicit declaration of function 'mbedtls_platform_set_calloc_free'
  4. My expectation & question is: I’m not sure how to correctly include platform.h. I’ve tried #include "platform.h" but it didn’t work.

Well, on one side you are mixing two worlds: Mongoose-OS is already handling MbedTLS for you, so the effectiveness of your intentions will somewhat depend on the order of execution, at least. You should check the internals to see how to make it fit, here, or to check if it’s already been done, if you are worried.
On the other side, what you ask is basic C, to call function X the compiler needs to know the types and quantity of parameters and returned value, that is done with a function prototype declaration, which is usually done at a header file (.h). Which one ? The one associated with the library or module in which the function is defined. Since that is not a Mongoose-OS function, you should include some MbedTLS or IDF header… that is quite likely already done at the library linked above, so take a look at it for this too.

The header file I’m trying to reference is here:

However, when adding “#include mbedtls/platform.h” to my code, I still get the error.

that portion of code is inside a #ifdef macro; it won’t “exist” if MBEDTLS_PLATFORM_FREE_MACRO and MBEDTLS_PLATFORM_CALLOC_MACRO are defined. That can happen since Mongoose-OS is already configuring MbedTLS for you.
I didn’t take the time to follow the structure, my first guess is that file is just there as an original from MbedTLS and actual config is done by also including other files; which in turn depend on your hardware.

Indeed, but I could not find anywhere in the cloned ESP-IDF that either of those were defined, so on that basis I understood that mbedtls_platform_set_calloc_free would be available. I’ll add in a log line to validate.

Ah, OK that looks like a limitation then!