2025-07-14 4:31 AM - last edited on 2025-07-14 4:45 AM by mƎALLEm
Hi Team,
Currently I am working with FreeRTOS Timers and callback is not firing always.
Please note that timer is creating and main application is calling after once osKernelInitialize(); is done. Above are configurations in FreeRTOSConfig.h.
Please give a solution why Callback is not firing ?
Thanks and Regards,
Ramesh
osTimerId_t FreertosTimerHandle;
const osTimerAttr_t FreertosTimer_attr =
{
.name = "FreertosTimer_LED"
};
void RPS_print_console_Thread(void *argument)
{
/* Initialize watchdog Timer */
IWDG_Init();
StartLEDTimer();
while(1)
{
/* Refresh watchdog periodically */
IWDG_Refresh();
}
}
void StartLEDTimer(void)
{
FreertosTimerHandle = osTimerNew(Fire_LED_Toggle, osTimerOnce, NULL, &FreertosTimer_attr);
if (FreertosTimerHandle != NULL)
{
if (osTimerStart(FreertosTimerHandle, 5000) == osOK)
{
printf("LED timer started\n");
}
else
{
printf("Failed to start LED timer\n");
}
}
else
{
printf("Failed to create LED timer\n");
}
}
void Fire_LED_Toggle(void *argument)
{
printf("Timer callback fired!\n");
HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, SET);
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, SET);
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, SET);
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, SET);
}
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 6 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH 256
2025-07-14 4:39 AM
Make sure that there is no thread stuck in a loop not calling any system service. Your RPS_print_console_Thread is such a thread - call some osDelay() in it.
OS timers work in the context of the system timer task. If its priority is lower that the priority of some active task, the timer callbacks will not be called.
2025-07-14 7:12 AM
Hello @ram_jana
You mentioned calling osKernelInitialize(), but the scheduler must be started with osKernelStart() for timers and other RTOS objects to work.
Timers rely on the timer service task, which only runs when the scheduler is active.
osKernelInitialize();
// Create timers, threads, etc.
osKernelStart(); // This starts the scheduler and timer service task
2025-07-14 8:03 AM
Hi Saket,
I have kept the function calls in the mentioned order and still no resolution on this. For more I have pasted the order of calling these functions
/* Init scheduler */
osKernelInitialize();
App_CreateTasks(); // Threads creation & Timer creation
/* Call init function for freertos objects (in app_freertos.c) */
MX_FREERTOS_Init();
/* Start scheduler */
osKernelStart();
2025-07-14 8:03 AM
Hi gbm,
I have tried the following and still issue is not yet resolved.