cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS Timer Callback is not firing [CMSIS_RTOS_V2]

ram_jana
Associate II

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

 

4 REPLIES 4
gbm
Principal

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Saket_Om
ST Employee

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
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

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();

Hi gbm,

I have tried the following and still issue is not yet resolved.