Freertos vTaskDelete (NULL) no free memory

I'm starting to learn FreeRTOS. Just now I am trying to make the print job function using this code:

static void vTaskPrint(void *pvParameters) { taskENTER_CRITICAL(); printf("%s", (char *)pvParameters); printf("xPortGetFreeHeapSize: %d\r\n", xPortGetFreeHeapSize()); taskEXIT_CRITICAL(); vTaskDelete(NULL); } 

But after 14 calls:

 xTaskCreate(vTaskPrint, (char *)"vTaskPrint", configMINIMAL_STACK_SIZE, (void *)buffer, 3, (xTaskHandle *)NULL); 

In cortex M3 memory ends:

 ************** TEST GPIO & LEDS FREERTOS OPEN103Z EVB ************** vTaskLeds xPortGetFreeHeapSize: 7832 vTaskReadKeys xPortGetFreeHeapSize: 7232 [INFO] vTaskPrint created successful Key pressed RIGHT xPortGetFreeHeapSize: 6632 [INFO] vTaskPrint created successful Key pressed CENTER KEY xPortGetFreeHeapSize: 6032 [INFO] vTaskPrint created successful Key pressed RIGHT xPortGetFreeHeapSize: 5432 [INFO] vTaskPrint created successful Key pressed LEFT xPortGetFreeHeapSize: 4832 [INFO] vTaskPrint created successful Key pressed RIGHT xPortGetFreeHeapSize: 4232 [INFO] vTaskPrint created successful Key pressed LEFT xPortGetFreeHeapSize: 3632 [INFO] vTaskPrint created successful Key pressed RIGHT xPortGetFreeHeapSize: 3032 [INFO] vTaskPrint created successful Key pressed LEFT xPortGetFreeHeapSize: 2432 [INFO] vTaskPrint created successful Key pressed RIGHT xPortGetFreeHeapSize: 1832 [INFO] vTaskPrint created successful Key pressed LEFT xPortGetFreeHeapSize: 1232 [INFO] vTaskPrint created successful Key pressed RIGHT xPortGetFreeHeapSize: 632 [INFO] vTaskPrint created successful Key pressed LEFT xPortGetFreeHeapSize: 32 [INFO] vTaskPrint created successful [ERROR] vTaskPrint not created successful 

How can I free memory?

+5
source share
1 answer

When you delete a task, the memory allocated for the task is freed from the Idle task. Therefore, you must let it run a simple task at some point. This is clearly indicated in the documentation for the function you are calling: http://www.freertos.org/a00126.html

In most applications, the standby task will be performed the most, so your test is somewhat artificial.

Aside: it's actually not very good to call such long functions as printf from a critical section, and you break the rules for using the FreeRTOS API by calling xPortGetFreeHeapSize () from the critical section (although you probably get the general rule in this case, it’s not to call the RTOS API functions from the critical section or when the scheduler is locked). This FAQ page is here: http://www.freertos.org/FAQHelp.html

There is a lot of information, as well as a special FreeRTOS expert support forum, which is available for free use on the FreeRTOS website, so I never understand why people ask about FreeRTOS problems anywhere.

+4
source

Source: https://habr.com/ru/post/1209925/


All Articles