Hello,
I’m using FreeRTOS V11.0.1 on a LPC55S69 with heap_5 and multiple regions.
I’m trying to get the vPortGetHeapStats
function to return heap usage but the code is getting stuck in the while loop.
Here are the important bits. The code is compiled as c++ but it shouldn’t change anything.
Global variables
__attribute__((section(".SRAMX_FreeRTOSHeap"))) static std::array<uint8_t, 0x0'8000> heapSRAMX;
__attribute__((section(".SRAM_FreeRTOSHeap"))) static std::array<uint8_t, 0x3'D000> heapSRAM;
__attribute__((section(".SRAM4_FreeRTOSHeap"))) static std::array<uint8_t, 0x0'4000> heapSRAM4;
__attribute__((section(".USB_RAM_FreeRTOSHeap"))) static std::array<uint8_t, 0x0'4000> heapUSB_RAM;
const HeapRegion_t xHeapRegions[] = {
{heapSRAMX.data(), heapSRAMX.size()}, // SRAMX
{heapSRAM.data(), heapSRAM.size()}, // SRAM
{heapSRAM4.data(), heapSRAM4.size()}, // SRAM4
{heapUSB_RAM.data(), heapUSB_RAM.size()}, // USB_RAM
{nullptr, 0} // Array termination
};
The main function
int main()
{
...
vPortDefineHeapRegions(xHeapRegions);
...
vTaskStartScheduler();
}
The task function
{
...
HeapStats_t heapStats;
vPortGetHeapStats(&heapStats);
volatile auto debugHeapStats = heapStats; // For debug purposes
....
}
Now when I run the program with a debugger, I have verified that the xHeapRegion
structure look correct.
When I call the vPortGetHeapStats
function, it gets stuck in this while loop at lines 666 to 691 in portable/MemMang/heap_5.c
.
Now if I change the source code of heap_5.c
that way, it now works and returns the expected values:
@@ -663,7 +663,7 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
* is initialised automatically when the first allocation is made. */
if( pxBlock != NULL )
{
- while( pxBlock != pxEnd )
+ while( pxBlock != pxEnd && pxBlock != NULL )
{
/* Increment the number of blocks and record the largest block seen
* so far. */
From the debugger, here are the values of pxEnd and pxBlock at the beginning of the while loop:
Note that some allocations have been done already.
pxBlock
looks all right, up until the last block which should be equal to pxEnd
but isn’t.
Is this a bug in FreeRTOS or a mistake on my end? What can I do to fix the problem without modifying FreeRTOS ?