5

我在 STM32F107VC 上使用 FreeRTOS V6.1.1 并经常遇到 malloc 错误。堆区域是在链接器脚本中定义的,但在几次分配后它一直卡在 pvPortMalloc() 循环中:

while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
{
    pxPreviousBlock = pxBlock;
    pxBlock = pxBlock->pxNextFreeBlock;
}

pxBlock: 0x20002300
pxPreviousBlock: 0x20002300
pxNewBlockLink: 0x00
xHeapHasBeenInitialised: 0x01

链接器脚本:

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20010000;    /* end of 64K RAM */

/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0;      /* required amount of heap  */
_Min_Stack_Size = 0x200; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 256K
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 64K
  MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K
}

...

怎么会这样?

4

1 回答 1

2

这可能是由 heap_2.c 中的碎片引起的。尽管分配很小,但行为是一致的。使用 heap_4.c 解决了它。

于 2014-01-28T00:28:39.500 回答