pvPortMalloc failes after the scheduler is started

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

pvPortMalloc failes after the scheduler is started

3,115件の閲覧回数
yuliap
Contributor II

Hi,

I have trouble with the pvPortMalloc function. My project contains the FreeRTOS component from Erich Styger and lwip from KSDK. I set the momery scheme to 3 in FreeRTOS and define a large heap in the CPU component. Large enough for all the memory allocations I need. The process initialization goes as expected, the memory is allocated without errors. When the scheduler is started a thread calls netconn_new, which in the end calls pvPortMalloc. The return value is zero. If I move the netconn_new call to before the scheduler, the memory allocation returns a sensible value. It looks almost like when the scheduler is started, the malloc is not functioning any more. Does anyone have any ideas about what it could be? My HW is custom..

Regards,

Julia

タグ(2)
0 件の賞賛
返信
3 返答(返信)

1,983件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Hi Julia,

my thinking is that your malloc() is not thread safe? FreeRTOS will do its usage of malloc() in a thread safe way (disabling interrupts.

What I think happens on your side is:

- lwip calls malloc() (not thread safe)

- tick interrupt happens, and the RTOS/task will call malloc() in thread safe way.

- as lwip started a malloc(), but not finished it, your malloc is screwed up.

Could you try replacing malloc() with pvPortMalloc() in lwip?

Erich

0 件の賞賛
返信

1,983件の閲覧回数
yuliap
Contributor II

Hi Erich,

thanks for the reply.

I modified the blinky task instead, and removed all the lwip usage from my project. The blinky task is now:

static void task_blinky(void *pvParameters) {

  (void)pvParameters; /* parameter not used */

  for(;;) {

      void *pvReturn = pvPortMalloc(100);

      GPIO_DRV_TogglePinOutput(DIAG_LED0);

      vTaskDelay(500/portTICK_RATE_MS);

      vPortFree(pvReturn);

  }

}

The program still crashes at the first call to pvPortMalloc in the blinky task, i.e after the task is scheduled for the first time. The pvReturn is zero. I noticed also that the SP register value drops from the top of the "data 0x2000000" partition to almost its start. I wonder if I configured the FreeRTOS wrong in a way...The FreeRTOSConfig.h is similar to the demo examples one.

0 件の賞賛
返信

1,983件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Hi Julia,

I'm affraid that you will need to debug it to find out what is going wrong here.

Erich

0 件の賞賛
返信