Late Timer Expiration: STM32L1xx

paulromero wrote on Monday, January 12, 2015:

Hi Folks:

I am using FreeRTOS on STM32L15RD processor–a STM32L152 variant, and using
the Rowley Crossworks for ARM as a toolchain. My problem is when a I set a timer
for what I think is 10000 milliseconds it doesn’t expire until approximately 17000
milliseconds.

The timer is created as follows:

T_SAMPLE = xTimerCreate(“Sample T”, (10000/portTICK_RATE_MS), pdFALSE, &v, sample_handler);

The underlying definition of portTICK_RATE_MS in FreeRtosConfig.h is as follows:

#define configTICK_RATE_HZ ( (Tick_Type_T) 1000)

This is the timeout handler.

void sample_handler(TimerHandler_t timer_id)
{
TLP_MESSAGE msg;

msg.event = AGG_E_SAMPLE_TIMEOUT;
msg.data_len = 0;
msg.data = NULL;
xQueueSendToFront(AGGREGATE_TASK, &msg, portMAX_DELAY);

return;

}

The timer is started and handled in AGGREGATE_TASK and the only thing the task
is doing is waiting for a message as follows:
(i.e. No messages except the timeout message arrive.)

xQueueReceive(AGGREGATE_TASK, &msg, 0);

Do you have any idea what the problem is ?

Best Regards,

Paul R.

rtel wrote on Monday, January 12, 2015:

xQueueSendToFront(AGGREGATE_TASK, &msg, portMAX_DELAY);

You are not supposed to make any Blocking function calls in timers, as to do so will Block the timer task itself, and effect any other timers that might be running. That may be the cause of the problem, but also…

Are you sure the tick interrupt is executing at the frequency you think it is? Can you toggle a pin from a tick hook function and check its frequency on a scope or frequency meter?

Regards.

paulromero wrote on Monday, January 12, 2015:

Hi:

I don’t think that is the problem becuase if one substibutes
xQueueSendToFrontFromISR(), the problem persists. In any case,
the queueing functions don’t do much more than a linked list
insertion.

Best Regards,

Paul R.

paulromero wrote on Tuesday, January 13, 2015:

Hi Folks:

I don’t have a scope handy but is is possible the
clock is not configured as I think. The file with
the clock initialization routines is attached to this note.

Best Regards,

Paul R.

rtel wrote on Tuesday, January 13, 2015:

I’m afraid the configuration of microcontrollers falls outside of FreeRTOS support. Even toggling an LED once per second and timing 60 toggles will give you a gross assessment of how the frequency of the tick count. Also ST provide a spreadsheet that automates clock configuration - you can enter your settings into the spread sheet and it will tell you the frequency of the output clocks.

Regards.