FreeRTOS with IAR on ARM Cortex

Hi Guys - Is there any special support implemented or needed for IAR’s library memory management (like #define configUSE_NEWLIB_REENTRANT)? How does IAR protect memory management from accidental reentrancy between tasks?
Best Regards, Dave

Have you seen this page? IAR’s memory allocation will only be used by FreeRTOS if you include heap_3.c in your application - in which case it is made re-entrant (rather crudely) within the heap_3 implementation. That does not protect the applications use of direct calls to malloc() though - try to ensure you only call pvPortMalloc() and vPortFree() in place of malloc() and free().

Thanks Richard as always! Of course if the IAR library internally uses malloc/free (as does newlib), then the user is hosed, no?
Best Regards, Dave

You can write your own malloc and free implementations that just call pvPortMalloc and vPortFree, so any uncontrollable calls to malloc just call pvPortMalloc, etc. Then you are safe.

Right, that’s the safe way, and IAR does support overriding library functions. Thanks again!

If IAR uses newlib, then there is a reasonable chance that they are using the newlib option to make malloc thread safe. One test is to make a very small program that just calls malloc and check the linker map. If the function __malloc_lock() is present, the option is available, and you can implement __malloc_lock() and __malloc_unlock() to provide the needed safety by having __malloc_lock disable the scheduler and __malloc_unlock re-enable it.

I’m not sure if there is a new lib option for IAR, maybe, but the compiler comes with its own optimised and scalable C library.

A quick check of the IAR web site shows IAR provide their own runtime library:

Yes, it looks like they have their own library, and there is a warning that some parts (like the heap allocations) are not thread safe. There is a comment about building a custom version of the library, so it may be possible to modify the library to make the heap (or other parts) thread safe.

link routed to page not found.
Please Can you share content or info or link again