just like previous example, this program create two task from different functions but this time we block each task with the function vTaskDelay to create a delay

Code Example:

#include "bsp.h"

/*Functions to act as tasks*/
static void vTask1( void *parameters );
static void vTask2( void *parameters );

int main( void )
{
    HAL_Init( );     /*Inicializamos la librería*/

    /*enable RTT and system view*/
    SEGGER_SYSVIEW_Conf( );
    SEGGER_SYSVIEW_Start( );

    /*register first task using the function vTask1 with (128*4) bytes de stack, no parameters
    priority of 1 and no task handler registered*/
    xTaskCreate( vTask1, "Task1", 128u, NULL, 1u, NULL );
    /*register second task using the function vTask2 with (128*4) bytes de stack, no parameters
    priority of 1 and no task handler registered*/    
    xTaskCreate( vTask2, "Task2", 128u, NULL, 1u, NULL );
    
    /*run the RTOS scheduler*/
    vTaskStartScheduler( ); 
    
    return 0u;
}

/*Simple task that initialize pin C0 as output and toggle the pin state every 1000ms*/
static void vTask1( void *parameters )
{
    GPIO_InitTypeDef GPIO_InitStruct;                   /* GPIO PIN Handler */
    __HAL_RCC_GPIOC_CLK_ENABLE( );                      /* Enable the clock for the port C */

    GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;        /* Configure the Pin as output */
    GPIO_InitStruct.Pull  = GPIO_NOPULL;                /* Configure pin as no pull up - no pull down */
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;       /* Configure frequency of pin as High */
    GPIO_InitStruct.Pin   = GPIO_PIN_0;                 /* Configure PIN 0 */
    HAL_GPIO_Init( GPIOC, &GPIO_InitStruct );           /* Initialize the GPIO */

    for( ; ; )
    {
        HAL_GPIO_TogglePin( GPIOC, GPIO_PIN_0 );        /* change the state of pin 0, port c */
        vTaskDelay( 1000u );                            /*block task for 1000 ticks*/
    }
}

/*Simple task that initialize pin C1 as output and toggle the pin state every 2000ms*/
static void vTask2( void *parameters )
{
    GPIO_InitTypeDef GPIO_InitStruct;                   /* GPIO PIN Handler */
    __HAL_RCC_GPIOC_CLK_ENABLE( );                      /* Enable the clock for the port C */

    GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;        /* Configure the Pin as output */
    GPIO_InitStruct.Pull  = GPIO_NOPULL;                /* Configure pin as no pull up - no pull down */
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;       /* Configure frequency of pin as High */
    GPIO_InitStruct.Pin   = GPIO_PIN_1;                 /* Configure PIN 1 */
    HAL_GPIO_Init( GPIOC, &GPIO_InitStruct );           /* Initialize the GPIO */ 

    for( ; ; )
    {
        HAL_GPIO_TogglePin( GPIOC, GPIO_PIN_1 );        /* change the state of pin 1, port c */
        vTaskDelay( 2000u );                            /*block task for 2000 ticks*/
    }
}

SystemView Output

Document

Now the tasks are not consuming unnecessary time processor, each task is blocked before execute for a specified time. The tasks is more visible and unsderstanble on time line.
Observe that the first execution is for Task 2 that changes the LED 1 status and is blocked for 2 seconds. Next Task 1 changes the LED 0 status and is blocked for 1 second.

When a second is elapsed, Just Task 1 is executed changing the LED 0 state and blocked again by 1 second.
Task 2 is blocked because time has not elapsed yet.

When another second elapsed, both task are executed changing the LED state like at the beginning.
Notice that now the Timeline is more clear and we can identify when the task changes the LED state.