cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS: prvProcessExpiredTimer BUG

Posted on March 29, 2018 at 10:39

Hello there,

0690X0000060AJ2QAM.png

Firmware Package for Family STM32L4: 1.10.0

When using FreeRTOS timers, there is a bug in function prvProcessExpiredTimer (Middlewares/Third_Party/FreeRTOS/Source/timers.c, line 498). The last operation before returning from the function is calling the provided at initialization callback function:

    /* Call the timer callback. */

    pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );

The arguments for the function is pxTimer, which is wrong, as the user has no way of extracting the address from pxTimer, since its type (Timer_t) is private... The only way to overcome this is to add a fixed address offset to hit the pvTimerID variable in the struct. This last line should look like this:

    /* Call the timer callback. */

    pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer->pvTimerID );

This way the callback function is really obtaining the value provided at init.

Could someone confirm please?

#timers #freertos
2 REPLIES 2
Barry.Richard
Associate III
Posted on March 29, 2018 at 19:14

[From a FreeRTOS author, not an ST representative]

I'm afraid it is not clear to me what you think the bug is.  The timer's handle is passed into the callback function to allow the same callback to be used for multiple software timers.  You can obtain the ID, if it is required, from the timer's handle.  An example of how to do that is provided here: 

https://www.freertos.org/FreeRTOS-timers-xTimerCreate.html

 If you still think this is a bug please open a thread on the FreeRTOS support forum, rather than the ST forum, and we can work through it.  If you do open a thread there, please do not say it is a bug in the subject line, as it can be confusing for people if it is not a bug - if we determine there is an issue we can then open a bug tracking ticket (on the FreeRTOS site).

Regards.

Posted on March 29, 2018 at 23:11

Hello, thank you for answer.

You are right, this is no bug, but my mistake. I was not aware that this function exists:

void *pvTimerGetTimerID( const TimerHandle_t xTimer )

{

Timer_t * const pxTimer = ( Timer_t * ) xTimer;

void *pvReturn;

    configASSERT( xTimer );

    taskENTER_CRITICAL();

    {

        pvReturn = pxTimer->pvTimerID;

    }

    taskEXIT_CRITICAL();

    return pvReturn;

}

Sorry for the confusion.