I’m having trouble with hard faults when trying to use heap_5.c
. We are using both the internal SRAM and an exteral SRAM to store the heap. Whenever heap is trying to allocate memory on the second region on external RAM the controller is running into an hard fault.
I tracked this down to the function prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert )
. First time pxBlockToInsert
will be on the external RAM the for
loop on top of the function will crash because pxIterator->pxNextFreeBlock
will become NULL after the last block in first section, so pxIterator
will become NULL thus referencing pxIterator->pxNextFreeBlock
will lead to the hardfault.
We are setting up heap like this
static uint8_t au8HeapInternalRAM[(10 * 1024)]; //everything without defined section will get placed in internal RAM
__attribute__ ((section (".extram"))) static uint8_t au8HeapExternalRAM[(80 * 1024)]; // section ".extram" is defined using linker script, starting at `0x60000000`
const HeapRegion_t xHeapRegions[] =
{
{ ( uint8_t* ) &au8HeapInternalRAM, (10 * 1024) },
{ ( uint8_t* ) &au8HeapExternalRAM, (80 * 1024) },
{ NULL, 0 } /* Terminates the array. */
};
vPortDefineHeapRegions(xHeapRegions);
is called right after the hardware initialization and I made sure this is called before the first call to pvPortMalloc
(or any other creation causing allocation).
I have configASSERT() defined like this
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
but this does not stop the program at any point.
The code is build using GCC (Embitz IDE) and is running on a STM32F439NGH6.
The external RAM is an 512KB SRAM connected via the FSMC interface of the controller.
Starting addresses:
* au8HeapInternalRAM 0x20004A0C
* au8HeapExternalRAM 0x60029850
Can anyone help me by telling me what could be the problem here?