1
votes

I have STM32F746ZG Nucleo-144pin board and generated the codes using STMCubeMx. I chose the FreeRTOS which is version 10.0.0 offered by CubeMx and the toolchain is SW4STM32.

I made two tasks and the following is my function. My code here:

void led1_task(void)
{
    while(1)
    {
        HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);
        HAL_Delay(1000);
    }
}

void led2_task(void)
{
    while(1)
    {
        HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);
        HAL_Delay(4100);
    }
}
  1. Task priority.

I found that if two tasks have the same task priority, the two tasks work fine, but if they have different priority of task, the low task does not work.

  xTaskCreate(led1_task, "led1_task", 1024, NULL, 2, NULL);  ==> Works fine.
  xTaskCreate(led2_task, "led2_task", 1024, NULL, 2, NULL);  ==> Works fine.

----------------------------------------------------------------------------

  xTaskCreate(led1_task, "led1_task", 1024, NULL, 2, NULL);  ==> This task is not working.
  xTaskCreate(led2_task, "led2_task", 1024, NULL, 3, NULL);  ==> Works fine.

  1. Task stack size.

If the stack size of the two tasks combined to be greater than 3 KB, it was confirmed that the task was not working correctly. The code below works correctly.

  xTaskCreate(led1_task, "led1_task", 2048, NULL, 2, NULL);  ==> Works fine.
  xTaskCreate(led2_task, "led2_task", 1024, NULL, 2, NULL);  ==> Works fine.

However, the second task does not work if the stack size is changed as follows.

  xTaskCreate(led1_task, "led1_task", 2048, NULL, 2, NULL);  ==> Works fine.
  xTaskCreate(led2_task, "led2_task", 2048, NULL, 2, NULL);  ==> This task is not working.

Attempting to change the _Min_Stack_Size from 0x400 to 0x4000 in STM32F746ZGTx_FLASH.ld has the same problem.

/* Generate a link error if heap and stack don't fit into RAM */

_Min_Heap_Size = 0x200; /* required account of heap */

_Min_Stack_Size = 0x4000;  /* required account of stack */

Can anyone explain the reason for this?

1

1 Answers

5
votes

To answer your questions:

  1. Task priority

Your lower priority task doesn't work because you use HAL_Delay. This function performs "active" blocking, i.e. the task that calls this function will keep on checking the internal tick counter until the condition is met. In other words - it doesn't block this task in RTOS sense. You should use vTaskDelay instead of HAL_Delay.

  1. Task stack size

There are a few points to note here.

a. The stack depth given to xTaskCreate is given in words, not bytes. In your example, the combined size of task stacks is `(2048 + 1024) * sizeof(uint32_t)' bytes. It's a lot in your case, much too much for what you do there currently.

b. Without debugging it's hard to tell with certainty why your second task isn't working, but it's highly likely that the second task doesn't get created at all because you hit some limit, e.g. going past RTOS heap size. It depends which FreeRTOS memory management implementation you use (heap_1, heap_2 etc.). You likely use one that depends on the configTOTAL_HEAP_SIZE - this is the definition that you should check and increase respectively.

c. _Min_Heap_Size and _Min_Stack_Size have nothing to do with FreeRTOS (unless you use heap_3 which uses malloc internally). These correspond to heap and stack outside of RTOS.