This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

CMSIS OS timer argument documentation issue/bug

I am using CMSIS OS wrapper on FreeRTOS running on STM32F4. It seems like the CMSIS OS documentation (www.keil.com/.../group__CMSIS__RTOS__TimerMgmt.html) is wrong about timer callback argument. Or the wrapper is buggy.

It is written that last argument for osTimerCreate will be passed to the timer callback function as "void const * argument". But my tests show it's not like that, argument pointer is actually the timer pointer. FreeRTOS manual (www.freertos.org/FreeRTOS-timers-pvTimerGetTimerID.html) confirms it and says that pvTimerGetTimerID function must be used to get the pointer value which was passed on timer creation.

To put it into code:

uint32_t value_to_pass = 123U;

osTimerDef(MyTimer, TimerCallback);
timer_id = osTimerCreate(osTimer(MyTimer), osTimerPeriodic, &value_to_pass);


void TimerCallback(void const * argument)
{
  // How to get value based on CMSIS OS manual.
  // Does not work. The "argument" is actually the "timer_id"
  uint32_t value = *((uint32_t *)argument);

  // Working solution based on the FreeRTOS documentation:
  uint32_t value = *((uint32_t *)pvTimerGetTimerID((const TimerHandle_t *)argument));
}