Issue with xTaskDelayUntil API

Hello All,

I am facing an issue with the xTaskDelayUntil API. My goal is to create tasks with execution frequencies of 5ms and 10ms using this API.

The problem I’m encountering is that when I run the code, the 5ms and 10ms counters increment properly. However, if I stop the code and rerun it, the counters no longer increment at all.

Even when I set a breakpoint inside the vTask1_handler, the counters remain stagnant. It’s important to note that the program is in the run state and not halting anywhere.

Upon breaking the execution of the program, I’ve observed that it halts at the following API: prvCheckTasksWaitingTermination().

For reference, the value of pxDelayedTaskList is 1, and pxDelayedTaskList = 2.

Below is the relevant code snippet:

xTaskCreate(vTask1_handler, "Task_1", configMINIMAL_STACK_SIZE, NULL, 2, &xTaskHandle1);

void vTask1_handler(void *params)
{
    TickType_t xLastWakeTime;
    const TickType_t xFrequency = pdMS_TO_TICKS(5);

    xLastWakeTime = xTaskGetTickCount();
    while (1)
    {
        // Wait for the next cycle.
        xWasDelayed = xTaskDelayUntil(&xLastWakeTime, xFrequency);

        FreeRtos_5ms_Counter++;

        taskYIELD();
    }
}

I appreciate any assistance in resolving this issue. Thank you!

The point you are seeing is in the idle task, so the system thinks no tasks are ready. One question, what do you mean by “stop the code and rerun it”?

Your code should work, and you shouldn’t need the call to taskYIELD(), as xTaskDelayUntil should block the task until the next time point. The one provision is that the tick rate needs to be at least 200 Hz (so the tick period is no longer than 5 ms) of pdMS_TO_TICKS(5) would return 0, which is invalid.

One possible problem is that somewhere else in your code you are doing something which messes the scheduler. One common problem is an ISR with an incorrect priority.

Is configASSERT defined to catch problems?

Thank you for the response!
What I mean by “stop the code and rerun it”? is that when I flash the code and run it those counter starts incrementing. There is no problem in that but when I pause the code using the debugger and once again resume it for the execution then those counters don’t increment for certain period of time. (like 50 sec to 1 min). After that they start to increment. If once again I pause the running code and rerun, again same thing will happen.

In the second scenario when I put a breakpoint here,


that breakpoint gets hit. But after that when I run the code counters will not increment.

I have used a configASSERT over here (Not in entire program).

status1 = xTaskCreate(vTask1_handler, “Task_1”, configMINIMAL_STACK_SIZE, NULL,2, &xTaskHandle1 );

configASSERT(status1 == pdPASS);

status2 = xTaskCreate(vTask2_handler, “Task_2”, configMINIMAL_STACK_SIZE, NULL,2, &xTaskHandle2 );

configASSERT(status2 == pdPASS);

Both the status 1 and status 2 values are 1.

Now, in my program tick rate is defined as 1000 and frequency is 300 MHz.

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

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

My understanding is, please correct me if I am wrong, when we use xTaskDelayUntil in the task, then for that specific period of time let’s assume 5 ms that particular stack will be moved to block/ready state and Freertos scheduler will run the idle task. Once that timer is elapsed once again schedular will run the original task and this goes on and on.

But I think in my case schedular is getting stuck in idle task not able to resume the original task as there are no tasks present in ready list as value of pxReadyTasksLists is 1.

if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( UBaseType_t ) 1 )
{
taskYIELD();
}
else
{
mtCOVERAGE_TEST_MARKER();
}

Please note that as I mentioned earlier the counter starts incrementing after 50s to 1 min (Not specific) time after I pause and run the code again.

Or is there an issue with your systick timer rep. systick handler ?
Can you put a breakpoint there before resuming execution to see that it’s hit right after resuming as it should ?

What is your debugger? We may be looking at a tool problem here instead of a problem related to FreeRTOS.

What is configUSE_TICKLESS_IDLE set to? If it is undefined in FreeRTOSConfig.h then it will default to 0.

Is there a chance that, while the processor is halted, the interrupt from the periodic timer that the scheduler uses is missed but the counter it’s using continues to advance, so the counter must wrap around back to the value the scheduler expects for the deadline to be detected?

Hello All,
Thank you for your responses.

Here, We are using Lauterbach debugger.
Value of configUSE_TICKLESS_IDLE is not defined.

I want to address one point here. Right now, I flashed the one Freertos demo code iLLD_TC375_ADS_FreeRTOS_Basic present in aurix development studio.
And I observed that my counters which are defined in the task are incrementing properly without using any delay function.

Code :–

void vTask1_handler(void * params)
{
while(1)
{

    FreeRtos_Task1_Counter++;

}

}
void vTask2_handler(void * params)
{

while(1)
{
    FreeRtos_Task2_Counter++;

}

}

void vApplicationTickHook()
{

TickHookCounter++;

}
void vApplicationIdleHook( void )
{

IDLEHookCounter++;

}

Values after starting the code :–

FreeRtos_Task2_Counter = 32662586
FreeRtos_Task1_Counter = 32683002
IDLEHookCounter = 0
TickHookCounter = 1963
xTickCount = 1963

But the problem is that when I stop the execution program and rerun it again
my task counters start incrementing as soon as I run the code but xTickCount and TickHookCounter doesn’t increment for certain period of time.

Scenario 1 - Following are the values when I stop the code :–

FreeRtos_Task2_Counter = 111578373
FreeRtos_Task1_Counter = 111595092
IDLEHookCounter = 0
TickHookCounter = 6705
xTickCount = 6705

Scenario 2 - Following are the values when I run the code again :–

FreeRtos_Task2_Counter = 111578373
FreeRtos_Task1_Counter = 364759087
IDLEHookCounter = 0
TickHookCounter = 6706
xTickCount = 6706

Scenario 3 - Following are the values after some time when the code is running :–

FreeRtos_Task2_Counter = 1188549687
FreeRtos_Task1_Counter = 1508043176
IDLEHookCounter = 0
TickHookCounter = 71423
xTickCount = 71424

In scenario 2 task counters increments but xTickCount wont increment.
In scenario 3 every counter increments.

For your reference after scenario 1 which is after I stopped the code, I check the STM timer, and I got to know that even I have stooped the code STM timer is running.
image

Can anyone please help me here?
I am stuck here for last couple of days.

Also, can someone explain me timer interrupt works in freertos?

One more thing, Also I don’t think that timer interrupt is generating at 1ms even my configTICK_RATE_HZ is 1000.

If xTickCount does not increment, your interrupts may be turned off. Check yur processor registers.

Again, I believe that you are dealing with an issue on the debugger side, not FreeRTOS operation.

Looks like if you (or the debugger) can configure the TC375 to halt the STM0 timer when execution is stopped in the debugger, then this problem will go away. Here is what seems to be the issue. The timer keeps counting while execution stops, so it pends a tick interrupt while execution is stopped. When execution resumes, the tick ISR finally executes. That tick ISR advances the compare register (STM0_CMP0), but by that time the counter has already passed the new compare value. So the counter must count all the way around until it reaches the compare value again.

Hello,

My issue has been resolved. I changed the debugger, and my tasks were running properly.

Thank you everyone for your support.

Note : The code also works on Lauterbach debugger if we set the SUS register bit of STM as “Set Suspended”.

Thank you for sharing your solution!