The configAPPLICATION_ALLOCATED_HEAP constant enables the application to place ucHeap wherever it likes. You may be able to use a linker variable to automatically place ucHeap at the start of the free memory block, but I don’t think you can use linker variables to set the configTOTAL_HEAP_SIZE constant (partly because the constant is used before linking, so you would have a circular dependence).
Your other options would be to use heap_3.c, which just wraps the standard C library implementation of malloc() and free() to make them thread safe. Then you can place the heap to use up all the free memory as you would in a non-FreeRTOS application.
Hi Aggarg,
I found this solution in heap5.c and implementation in .ld file using GCC compiler.
But I don’t know how to export 2 variables from scatter file in Keil5 using ARMCC compiler.
Could you point me out how to export free_ram_end and free_ram_start from scatter file.
Thanks a lot.
Best Regards.
Hi Aggarg,
Thanks for quick response.
I follow the code example from your link. I can get the rest of SRAM by the variables from sct files.
Then I do the ucHeap initialization in my code as below,
ucHeap = (uint8_t *)(( uint32_t )(&( Image$$ER_IRAM_NS_UNPRIVILEGED_ALIGN$$Limit ) + 0x01));
But the code didn’t work correctly. From the map file,
Image$$ER_IRAM_NS_UNPRIVILEGED_ALIGN$$Limit 0x200020e0 Number 0 anon$$obj.o ABSOLUTE
__initial_sp 0x200020e0 Data 0 startup.o(STACK)
I find the reason why it didn’t work since I change the array ucHeap[] to a global point uint8_t *ucHeap, but not changed in heap_4.c.
Actually for heap_4.c just need to know start address of heap and the length is enough. It both work for heap_4.c and heap_5.c as well.
The size of heap_4 is configured using a compile time macro configTOTAL_HEAP_SIZE. You need to ensure that it is set correctly to the size of free RAM available.
Heap_5 allows you set the size of memory region to be used as heap using vPortDefineHeapRegions.