Hi. I am using a custom board using an STM32H7.
In most cases, this works fine, but on some boards, the EwInit() function gets stuck in an infinite loop while running.
Through debugging, we found that the infinite loop was caused by the FindPrevBestFit() function.
There seems to be an issue with the allocation of heap memory allocated to external SDRAM.
/* The following helper function traverses the list of free blocks looking
for a block with optimal size of at aSize bytes. The search operation
starts with the block aBlock. The function returns the found block or 0
if there is no block matching the search condition. Also, the function
stops if the actual block lies in front of aStop and returns this block. */
static XMemoryBlock *FindPrevBestFit(long aSize, XMemoryBlock *aBlock,
XMemoryBlock *aStop) {
XMemoryBlock *foundBlock = 0;
long foundSize = 0x7FFFFFFFl;
for (; aBlock > aStop; aBlock = aBlock->Prev)
if ((aBlock->Size >= aSize) && (aBlock->Size < foundSize)) {
foundBlock = aBlock;
foundSize = aBlock->Size;
}
return foundBlock ? foundBlock : aBlock;
}
In that function, the value of 'aSize' is 128, the address of 'aBlock' is 0xd0a0d0a0, and the address of 'aStop' is 0x7a007a.
The address of aStop has an address value that is unrelated to the SDRAM(16MB) area, so it gets stuck in an infinite loop.
The aStop argument is the value of pool->Separator.
I'm not sure why only some boards have issues with using Heap.
Of the 16MB SDRAM,
I use about 2MB for the display buffer and double buffer, ( display buffer: 0xD0000000 ~ 0xD012BFFF, double buffer 0xD012C000 ~ 0xD0257FFF )
6MB for temporary space of other data, ( 0xD0A00000 ~ 0xD0FFFFFF )
and the remaining 8MB is used for the Heap memory area. ( 0xD0258000 ~ 0xD0BFFFFF )
Can you tell me what might be causing the problem?