Moving the FreeRTOS Heap to External SRAM


I am using the SAM4E with FreeRTOS version 9.0.0 as I am using FreeRTOS Labs as I am wanting to use the plus libraries. I am using Heap4.

One of the first tasks I have is to allocate the heap to external SRAM, therefore I initalise the SRAM peripheral and allocate ucHeap before any freertos interaction.

/* Allocating FreeRTOS Heap to external memory*/
ucHeap = (uint8_t*)mh_get_freertos_base();

I can then step through the vTaskStartScheduler, and can see all memory allocation is done in 0x6… which is where my SRAM is. The problem I encounter is that once it enters the timer task it does not switch to the first user defined task at all, however I can see that it has a valid pcb.

To test my code I have even allocated the heap to internal RAM location:

uint8_t array[configTOTAL_HEAP_SIZE];

ucHeap = array;

And this works, my user defined task is executed. I have further tested my SRAM by writing and reading back the correct data.

Am I missing another requirement to be able to put the FreeRTOS Heap on external memory? Is there anything else I could do to get any more clues?

I would appreciate any help,

I forgot to add that to get the timer and idle task working I had to allocate these tasks statically.

I have updated the FreeRTOS source code to the latest, which undid the static allocation, and I’m finding the same issue. Which does seem to point to me missing something.

Hello @Dyfan,

Welcome to FreeRTOS Forums!

I am guessing you mean FreeRTOS+FAT? Because other libraries such as FreeRTOS+TCP are not labs anymore.

I am curious as to why do you want to use external SRAM. (Don’t quote me on this but,) I ask because they often tend to be slower and you should strive to put data which is not accessed frequently in the SRAM. The heap can be placed in the flash itself if the flash is big enough.

Regardless, can you verify that the SRAM is memory mapped? As in to access certain memory location, one can just write to (or read from) 0x6… address and it will be properly accessed?
You can look at the reading and writing operation functions that you are using to check how a given memory location is accessed.

Let me know if that helps!