vPortFree on STM32 Demonstration Builder developer guide

erps wrote on Friday, August 15, 2014:

Hi:
I am working with a STMicrolectronics Demo STM3221G-EVA board. This Demo uses on FreeRTOS. I would like to add a GUI Module into this demo. I have followed the documentation UM1550 STM32 Demonstration Builder developer guide, at Chapter 5 Building a Module. Also I have used the template file provided with the Demo, to add this new module and I was successful to include an icon in the right location.
Now, when I click in the icon the code goes to an infinite loop at: (arrowed part)

static void TEMPLATE_INFO_SwitchPage(GL_Page_TypeDef* pParent, uint32_t PageIndex)
{
/* Switch to new page, and free previous one. /
GL_Page_TypeDef
NextPage = NULL;

(pParent).ShowPage(pParent, GL_FALSE);
DestroyPage(pParent);
vPortFree(pParent); /
<— Code stuck here */
pParent = NULL;

if (PageIndex == PAGE_MENU)
{
GL_ShowMainMenu();
return;
}

This function is referenced in the following function:

static void TEMPLATE_INFO_Startup (void)
{
vTaskSuspend(Core_Time_Task_Handle);
TEMPLATE_INFO_SwitchPage(GL_HomePage, TEMPLATE_MAIN_PAGE);
}

vPortFree is a FreeRTOS function, but it may be a pointer problem where there’s no definition of the pointer or something, I don’t know. This Demo uses heap_2.c
The original Modules work ok. I am missing something here?
Thanks.

rtel wrote on Friday, August 15, 2014:

I have no clue about that code, but vPortFree() is a very small function in heap_2.c so you should be able to see where it gets stuck. I think the only place it could get stuck would be in the prvInsertBlockIntoFreeList() function, which would be an indication that the block being freed, or the heap itself, had been corrupted (overwritten) by something.

Regards.

erps wrote on Friday, August 15, 2014:

I just find out that if vPportFree(pParent) is replaced by free(pParent) works ok.
That tells you anything?

edwards3 wrote on Friday, August 15, 2014:

As you say you use heap_2 then if the memory was allocated with pvPortMalloc() then it must be freed by vPortFree(). If the memory was allocated by malloc() then it must be freed using free(). How was it allocated? You probably just leaked the memory.

erps wrote on Friday, August 15, 2014:

Memory was allocated using malloc. That’s why.
Thanks so much.