FreeRTOS task not executed

2 means that the scheduler is running - FreeRTOS-Kernel/include/task.h at main · FreeRTOS/FreeRTOS-Kernel · GitHub.

Put a breakpoint in vPortStartFirstTask and step through the it and see where the control goes after this instruction - FreeRTOS-Kernel-Partner-Supported-Ports/Tasking/AURIX_TC3xx/port.c at main · FreeRTOS/FreeRTOS-Kernel-Partner-Supported-Ports · GitHub.

Reaching out to Infineon would probably also be a good idea.

OK, Thanks for the clarification!

I actually tried a different approach running this piece of code from TickHook. and putting a breakpoint at vPortFree( pxTaskStatusArray. I noticed beside Idle and my task another one was running which name starts with letter “T” and has priority 9, after some reasearch I found it is called “Timer Service Task” , I change the definition of configUSE_TIMERS to 0 and my task is finally reached. I have to check more to understand why this task is neccesary and why it is blocking anything else.

void vTaskGetRunTimeStats_bla( void )
{
    TaskStatus_t *pxTaskStatusArray;
    volatile UBaseType_t uxArraySize, x;
    unsigned long ulTotalRunTime, ulStatsAsPercentage;

   /* Take a snapshot of the number of tasks in case it changes while this
      function is executing. */
   uxArraySize = uxTaskGetNumberOfTasks();

   /* Allocate a TaskStatus_t structure for each task. An array could be
      allocated statically at compile time. */
   pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );

   if( pxTaskStatusArray != NULL )
   {
      /* Generate raw status information about each task. */
      uxArraySize = uxTaskGetSystemState( pxTaskStatusArray,
                                 uxArraySize,
                                 &ulTotalRunTime );

      /* For percentage calculations. */
      ulTotalRunTime /= 100UL;

      /* Avoid divide by zero errors. */
      if( ulTotalRunTime > 0 )
      {
         /* For each populated position in the pxTaskStatusArray array,
            format the raw data as human readable ASCII data. */
         for( x = 0; x < uxArraySize; x++ )
         {
            /* What percentage of the total run time has the task used?
               This will always be rounded down to the nearest integer.
               ulTotalRunTimeDiv100 has already been divided by 100. */
            ulStatsAsPercentage =
                  pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
         }
      }

      /* The array is no longer needed, free the memory it consumes. */
      vPortFree( pxTaskStatusArray );
   }
}

If you are not creating any timer in your application, the timer task should mostly be blocked. What are the values of configUSE_PREEMPTION and configUSE_TIME_SLICING?

#define configUSE_PREEMPTION                       1

I didn’t define configUSE_TIME_SLICING so I assume it is 1 by default. I also defined:

#define configTIMER_TASK_PRIORITY                  ( 9 )
#define configTIMER_QUEUE_LENGTH                   ( 5 )

Is vTaskDelay() impacted by this timer task since it seems not to delay the execution for the number of ticks required?(e.g. if I give 1000 ticks it is just toggling the LED again instantly). If I use other instruction like the one below is working just fine:

waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER,LED1_BLINKY_PERIOD_MS);

No, it is not and the behavior you mention should not happen. May be try to step through it and see why is it not blocking.

Can you share your complete FreeRTOSConfig.h?

Sure

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#define configUSE_PREEMPTION                       1
#define configUSE_IDLE_HOOK                        0

#define configCPU_CLOCK_HZ                         ( ( unsigned long ) 300000000UL )
#define configTICK_RATE_HZ                         ( ( TickType_t ) 1000UL )

#define configMAX_PRIORITIES                       ( 10 )
#define configMINIMAL_STACK_SIZE                   ( ( unsigned short ) 1024 )
#define configTOTAL_HEAP_SIZE                      ( ( size_t ) ( 32U * 1024U ) )
#define configMAX_TASK_NAME_LEN                    ( 16 )

#define configENABLE_BACKWARD_COMPATIBILITY        1
#define configUSE_TRACE_FACILITY                   1
#define configUSE_16_BIT_TICKS                     0
#define configIDLE_SHOULD_YIELD                    0
#define configUSE_MALLOC_FAILED_HOOK               0
#define configCHECK_FOR_STACK_OVERFLOW             1
#define configUSE_TICK_HOOK                        0
#define configUSE_COUNTING_SEMAPHORES              1
#define configUSE_RECURSIVE_MUTEXES                1
#define configUSE_MUTEXES                          1
#define configRECORD_STACK_HIGH_ADDRESS            1

#define configNUM_THREAD_LOCAL_STORAGE_POINTERS    5

/* Software timer configuration. */
#define configUSE_TIMERS                           ( 0 )
#define configTIMER_TASK_PRIORITY                  ( 9 )
#define configTIMER_QUEUE_LENGTH                   ( 5 )
#define configTIMER_TASK_STACK_DEPTH               configMINIMAL_STACK_SIZE

/* Set the following definitions to 1 to include the API function, or zero
 * to exclude the API function. */
#define INCLUDE_vTaskPrioritySet                   1
#define INCLUDE_uxTaskPriorityGet                  1
#define INCLUDE_vTaskDelete                        1
#define INCLUDE_vTaskCleanUpResources              1
#define INCLUDE_vTaskSuspend                       1
#define INCLUDE_vTaskDelayUntil                    1
#define INCLUDE_vTaskDelay                         1

/* Interrupt above priority 31 are not effected by critical sections, but cannot call interrupt safe FreeRTOS functions. */
#define configMAX_API_CALL_INTERRUPT_PRIORITY      31

/* Default definition of configASSERT(). */
#ifdef DEBUG
#ifdef __TASKING__
#define configASSERT( x )    if( ( x ) == 0 ) { __disable(); __debug(); }
#endif
#ifdef __clang__
#define configASSERT( x )    if( ( x ) == 0 ) { __builtin_tricore_disable(); __builtin_tricore_debug(); }
#endif
#else
#define configASSERT( x ) ((void)(x)) /* Empty macro to remove compiler warning(s) about unused variables */
#endif

/* AURIX TCxxx definitions */
#define configCONTEXT_INTERRUPT_PRIORITY    1
#define configTIMER_INTERRUPT_PRIORITY      2 /* This value must not be bigger then context priority */
#define configCPU_NR                        0
#define configPROVIDE_SYSCALL_TRAP          0
#define configSYSCALL_CALL_DEPTH            2
#define configSTM                           ( ( uint32_t * ) (0xF0001000 + configCPU_NR*0x100 ) )
#define configSTM_SRC                       ( ( uint32_t * ) (0xF0038300 + configCPU_NR*0x8) )
#define configSTM_CLOCK_HZ                  ( 100000000 )
#define configSTM_DEBUG                     ( 1 )
#define configCONTEXT_SRC                   ( ( uint32_t * ) 0xF0038990 )

#endif /* FREERTOS_CONFIG_H */

Can you change this to the following to be double sure-

#define configASSERT( x )    if( ( x ) == 0 ) { takDISABLE_INTERRUPTS();  for( ;; ); }

Can you double check that there is no interrupt at priority above 31 which calls FreeRTOS APIs?

If enabling timer task is causing your application to not work, you can check if timer task is running by blinking an LED in the timer task.

I did it! No change!

There are none above 31.

If I insert code, the LED is blinking.

Please do one more experiment. Turn on timers by setting configUSE_TIMERS to 0 and create 2 tasks with different priorities which blink different LEDs:

void LowPrioTask( void * param )
{
    ( void ) param;

    for( ;; )
    {
        Blink_Led1();

        vTaskDelay( pdMS_TO_TICKS( 1000 ) );
    }
}

void HighPrioTask( void * param )
{
    ( void ) param;

    for( ;; )
    {
        Blink_Led2();

        vTaskDelay( pdMS_TO_TICKS( 1000 ) );
    }
}

The thing I want to check is if the context switch is working.

I think it is not working fine, in this case if configCONTEXT_INTERRUPT_PRIORITY is 5 and configTIMER_INTERRUPT_PRIORITY is 6 and I run the tasks below only task_blinky_1 is executed. Btw, could you please explain the relation between these 2 defines(configCONTEXT_INTERRUPT_PRIORITY / configTIMER_INTERRUPT_PRIORITY ) ? Should they always have higher priorities than usual tasks?

xTaskCreate(task_blinky_1, "APP LED1", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(task_blinky_2, "APP LED2", configMINIMAL_STACK_SIZE, NULL, 0, NULL);

If I apply the following config only task_blinky_2 is executed:

xTaskCreate(task_blinky_1, "APP LED1", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(task_blinky_2, "APP LED2", configMINIMAL_STACK_SIZE, NULL, 1, NULL);

In both cases above vTaskDelay is not respected, the blink function is executed almost immediately after vTaskDelay.

The only case in which the system is behaving aproximately right is with the following settings, both tasks are executed and LEDs are blinking, when using vTaskDelay() everything is messed up:

#define configCONTEXT_INTERRUPT_PRIORITY    1
#define configTIMER_INTERRUPT_PRIORITY      2 /* This value must not be bigger then context priority */
....
    returnValue = xTaskCreate(task_blinky_1, "APP LED1", configMINIMAL_STACK_SIZE, NULL, 0, NULL);
    returnValue = xTaskCreate(task_blinky_2, "APP LED2", configMINIMAL_STACK_SIZE, NULL, 0, NULL);
....
/* Task which runs the LED1 app */
void task_blinky_1(void *arg)
{
    task_init_1();

    for( ;; )
        {

        IfxPort_togglePin(LED_D107);                                                /* Toggle the state of the LED      */

        /* Delay 1000ms */
        waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, LED1_BLINKY_PERIOD_MS));    /* Wait 500 milliseconds            */
        //vTaskDelay(pdMS_TO_TICKS(LED1_BLINKY_PERIOD_MS));
    }
}

void task_blinky_2(void *arg)
{
    task_init_2();

    for( ;; )
        {

        IfxPort_togglePin(LED_D108);                                                /* Toggle the state of the LED      */

        /* Delay 1000ms */
        waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, LED1_BLINKY_PERIOD_MS));    /* Wait 500 milliseconds            */
        //vTaskDelay(pdMS_TO_TICKS(LED1_BLINKY_PERIOD_MS));
    }
}


Also, when vTaskDelay is called CPU goes to IfxCpu_Trap_busError

configCONTEXT_INTERRUPT_PRIORITY is the priority of the interrupt which handles context switching - FreeRTOS-Kernel-Partner-Supported-Ports/Tasking/AURIX_TC3xx/port.c at main · FreeRTOS/FreeRTOS-Kernel-Partner-Supported-Ports · GitHub.
configTIMER_INTERRUPT_PRIORITY is the priority of the timer interrupt - FreeRTOS-Kernel-Partner-Supported-Ports/Tasking/AURIX_TC3xx/port.c at main · FreeRTOS/FreeRTOS-Kernel-Partner-Supported-Ports · GitHub.

These are interrupt priorities and do not have any relation to the task priorities.

This should not happen. Can you examine the callstack and see if it provides any information. You can also consult hardware manual if it provides some information to debug bus errors?

Yes, there are some explanations. The trap class is 4(System Bus and Peripheral Errors) and ID 2(Data Access Synchronous Error).

Try to figure out which location is it trying to access which results in bus error.

Hi, I have similar problem on the Infineon Tc364. Also task is never executed, I try change macro
#define configUSE_TIMERS ( 0 ) - from 1 to 0
And then my task is executed, but only one task is working, context switching feels to not working.

Do you have any vTaskDelay call in your tasks? For me the context switch is working when just blinking the LED and adding a delay using waitTime() function. Otherwise the context switch is not working. I tried both Tasking and GCC ports and it is the same for both. In Tasking I also get CPU trap when using vTaskDelay .

For me waitTime is freezing application and with vTaskDelay only the second task (in order of creation) is executed.

It seems that the context switch is not working. This is a partner supported port and I am not very familiar with it. Let me know if you’d like to have debug session to debug this together. If yes, please DM me with you email and preferred time slots.