FreeRTOS task not executed

Hi,

I try to run a simple piece of code in a FreeRTOS task for Infineon TC387, I created an emty project for my evaluation board(KIT_A2G_TC387_5V_TFT), then imported the kernel in my project and the portables from here: [Free RTOS/FreeRTOS-Kernel-Partner-Supported-Ports].

/* code */
Unfortunately FreeRTOS task is never executed(I checked also with the debugger). Any clue where the issue could be?
Thank you!

void core0_main(void)
{
    IfxCpu_enableInterrupts();
    
    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
    
    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
    
    /* Create LED1 app task */
    xTaskCreate(task_app_led1, "APP LED1", configMINIMAL_STACK_SIZE, NULL, 0, NULL);

    /* Create LED2 app task */
    xTaskCreate(task_app_led2, "APP LED2", configMINIMAL_STACK_SIZE, NULL, 0, NULL);

    /* Start the scheduler */
    vTaskStartScheduler();
    
    while (1)
    {
    }
}
/* end code */

@florin611

Can you share your task implementation: task_app_led1 and task_app_led2.

#define LED1_BLINKY_PERIOD_MS (250)                         /* The period (in milliseconds) at which LED1 will blink */
#define LED_D107    &MODULE_P13,0                                           /* LED D107: Port, Pin definition       */
#define WAIT_TIME   500

/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
/* Initialization function for LED1 app */
static void app_init(void)
{
    /* Setup the port/pin connected to LED1 to general output mode push-pull. This function can be
     * used to initialize any port pin by specifying the port number, pin number and port pin mode.
     */
    /* Initialization of the LED used in this example */
    IfxPort_setPinModeOutput(LED_D107, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);

    /* Switch OFF the LED (low-level active) */
    IfxPort_setPinHigh(LED_D107);
}

/* Task which runs the LED1 app */
void task_app_led1(void *arg)
{
    app_init();

    while (1)
    {
        IfxPort_togglePin(LED_D107);                                                /* Toggle the state of the LED      */
        waitTime(IfxStm_getTicksFromMilliseconds(LED1_BLINKY_PERIOD_MS, WAIT_TIME));    /* Wait 500 milliseconds            */
    }
}
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "IfxSrc.h"
#include "IfxScuEru.h"

#include "App_Config.h"
#include "FreeRTOS.h"
#include "task.h"
#include "IfxPort.h"
#include "Bsp.h"

/*********************************************************************************************************************/
/*-----------------------------------------------------Macros--------------------------------------------------------*/
/*********************************************************************************************************************/
#define ISR_PRIORITY_SCUERU_INT0 (3)                        /* Define the SCU ERU interrupt priority                 */
#define LED_D107    &MODULE_P13,0
#define LED_D108    &MODULE_P13,1                                           /* LED D107: Port, Pin definition       */
#define WAIT_TIME   500

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
static TaskHandle_t g_AppTaskHandle;                            /* LED2 App task handle                              */
static const IfxScu_Req_In * g_ReqIn = &IfxScu_REQ4A_P33_7_IN;  /* External Request pin: P33.7                       */

/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
/* ISR for handling the ERU interrupt */
IFX_INTERRUPT(SCUERU_Int0_Handler, 0, ISR_PRIORITY_SCUERU_INT0)
{
    BaseType_t externalIsrTriggered;

    /* Notify task from ISR */
    vTaskNotifyGiveFromISR(g_AppTaskHandle, &externalIsrTriggered);

    /* Yield if higher priority task is selected */
    portYIELD_FROM_ISR(externalIsrTriggered);
}


/* Initialization function for LED2 app */
static void app_init(void)
{
    IfxScuEru_InputNodePointer triggerSelect    = IfxScuEru_InputNodePointer_0;
    IfxScuEru_OutputChannel outputChannel       = IfxScuEru_OutputChannel_0;
    IfxScuEru_InputChannel inputChannel         = (IfxScuEru_InputChannel)g_ReqIn->channelId;

    /* Initialization of the LED used in this example */
    IfxPort_setPinModeOutput(LED_D108, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);

       /* Switch OFF the LED (low-level active) */
    IfxPort_setPinHigh(LED_D108);

    /* Enable input mode with pull-down for the REQ_IN pin and configure the ERU input multiplexer */
    IfxScuEru_initReqPin(g_ReqIn, IfxPort_InputMode_pullDown);

    /* Input channel configuration, interrupt triggered on a falling edge */
    IfxScuEru_enableFallingEdgeDetection(inputChannel);

    /* Event Trigger Logic (ETL) configuration... */
    IfxScuEru_enableTriggerPulse(inputChannel);             /* Enable trigger event */
    IfxScuEru_connectTrigger(inputChannel, triggerSelect);  /* Set output channel for trigger event */

    /* Configure output channel in the OutputGating Unit (OGU) */
    IfxScuEru_setInterruptGatingPattern(outputChannel, IfxScuEru_InterruptGatingPattern_alwaysActive);
    /* --- */

    /* Service request configuration */
    /* Get source pointer depending on outputChannel (SRC_SCUERU0 for outputChannel0) */
    volatile Ifx_SRC_SRCR *srcReg = &MODULE_SRC.SCU.SCUERU[(int)outputChannel % 4];
    IfxSrc_init(srcReg, IfxSrc_Tos_cpu0, ISR_PRIORITY_SCUERU_INT0);
    IfxSrc_enable(srcReg);
    /* --- */
}

/* Task which runs the LED2 app */
void task_app_led2(void *arg)
{
    g_AppTaskHandle = xTaskGetCurrentTaskHandle();

    app_init();

    while (1)
    {
        // Wait for task notification and then toggle LED2
        ulTaskNotifyTake(0, portMAX_DELAY);

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

I tried also to create a single task with a very short code inside and the same:

/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "IfxPort_PinMap.h"
#include "Port/Io/IfxPort_Io.h"

#include "FreeRTOS.h"
#include "task.h"

/*********************************************************************************************************************/
/*-----------------------------------------------------Macros--------------------------------------------------------*/
/*********************************************************************************************************************/
#define LED_D107    &MODULE_P13,0                                           /* LED D107: Port, Pin definition       */
#define LED1_BLINKY_PERIOD_MS   (250)                       /* The period (in milliseconds) at which LED1 will blink */

/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
/* Initialization function for LED1 app */
static void task_init(void)
{
    /* Initialization of the LED used in this example */
    IfxPort_setPinModeOutput(LED_D107, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);

    /* Switch OFF the LED (low-level active) */
    IfxPort_setPinHigh(LED_D107);
}

/* Task which runs the LED1 app */
void task_blinky(void *arg)
{
    task_init();

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

        /* Delay 250ms */
        vTaskDelay(pdMS_TO_TICKS(LED1_BLINKY_PERIOD_MS));
    }
}

Please enclose code blocks by 3 tildes ā€˜~ā€™ or backticks for better readablity. Thanks !

Sometimes it helps to append a language tag like this ā€˜~~~cā€™ in case the code is not rendered properly.

1 Like


I tried all portables found(official and not official) and the result is the same.

Can you check the xtaskCreate return value and see if the task are getting created? If yes, next you should check if the tick interrupt is firing and xTickCount is getting incremented.

xtaskCreate return 1 and xTickCount is incremented. Anyway, I can see the value of xTickCount only after I pause the execution, after I resume it xTickCount is incremented 1 more time then it remains unchanged, probably something is getting messed up during the execution pause.

That does not seem correct. Can you put a breakpoint in your Tick ISR and xTaskIncrementTick to ensure that these are getting called continuously?

Yes, they are called but it takes around 30 seconds between succesive breakpoints are reached. After they are reached xTickCount is incremented with 1.

That seems odd - is it possible that your debugger has issues? You may try to blink an LED in tick hook and run without debugger to confirm that tick ISR is happening continuously.

I inserted the Led blink in a tick hook and toggled the LED every 1000 ticks and the LED is toggling as expected(every 1 second) . The settings are done as follow:

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

This is good sign. Now try to write a simple task which blinks a different LED and see if that works. Do not create any other task yet.

I did it, unfortunately task_blinky is never reached.

    /* Create LED1 app task */
    returnValue = xTaskCreate(task_blinky, "APP LED1", configMINIMAL_STACK_SIZE, NULL, 10, NULL);

    /* Start the scheduler */
    vTaskStartScheduler();

    while (1)
    {
    }
  1. Do not create this task_blinky and blink the LED in the IDLE task hook. This will confirm if the idle task is running successfully.
  2. What is the value of configMINIMAL_STACK_SIZE?

If I insert a call to xTaskGetSchedulerState() inside vApplicationTickHook the scheduler state seems suspended.

  1. vApplicationIdleHook is not reached;
  2. #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 256 )

That does not seem correct. What is the value of uxSchedulerSuspended?

Try increasing it to 1024 just for a quick testing.

The value of uxSchedulerSuspended is 0, xTaskGetSchedulerState() returns 2 when called from vApplicationTickHook()

Done! Nothing changed!