Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


non-uniform ticks

Posted by bertino on March 18, 2014


I'm running FreeRTOS v7.6.0 on the cortex-M3 based STM32L151xB micro. In my FreeRTOSConfig.h i have :

#define configTICK_RATE_HZ				( ( portTickType ) 1000 )

which makes me assume I have a tick triggering every millisecond. Just to evaluate some application timing issues in relation to the tick I added GPIO pin toggling within the xPortSysTickHandler() to watch ticks on the oscilloscope, therefore in port.c I have :

void xPortSysTickHandler( void )
	/* The SysTick runs at the lowest interrupt priority, so when this interrupt
	executes all interrupts must be unmasked.  There is therefore no need to
	save and then restore the interrupt mask value as its value is already
	known. */
#ifdef ST_DEBUG
		/* Increment the RTOS tick. */
		if( xTaskIncrementTick() != pdFALSE )
			/* A context switch is required.  Context switching is performed in
			the PendSV interrupt.  Pend the PendSV interrupt. */
#ifdef ST_DEBUG

my debug code added under ST_DEBUG defines. Using an oscilloscope I can see the xPortSysTickHandler() pulses sent on GPIO C, pin 14 , they all have a duration between 3 and 5 microseconds. Here are the issues :

1)I was expecting ticks pulses to be uniformly distributed at regular 1ms intervals with at most some jitter here and there, but the situation I see is slightly different. I have groups of few ticks interleaved by 1ms as expected and then some gaps 5 or 6 ms long in between groups; I was initially thinking that those long gaps were due to higher priority interrupt service routines but things didn't change after disabling them. I was just wondering if there is something else I'm missing, can be some macro/service that needs to be disabled within FreeRTOSConfig.h ? What are your thoughts on this ?

2)Minor point : returning to the code snippet I pasted above, if my understanding is right, the task context switch is done once within xPortSysTickHandler() we run the following statement :


which, as the comment suggests will cause the PendSV interrupt handler (as specified in portasm.s) to start running. So in general in this case the tick pulse duration measured as explained above might include the task switching time and pendSV interrupt time entry as well right ?

Thanks, Adalberto

non-uniform ticks

Posted by rtel on March 18, 2014

The systick and pendsv handlers run at the same priority, so one will run after the other - using the ARM Cortex-M tail chaining mechanism (so registers are not unstacked and then stacked again by the hardware in between the two interrupts).

Can you run the same experiment with no application tasks running at all - so only the idle and possible the timer (depending on the configUSE_TIMERS setting) will be running.

Please also post the GPIOHIGH and GPIOLOW code. Please surround any code you post in [pre][code] ... [/code][/pre] tags (BUT USING ANGLE BRACKETS INSTEAD OF SQUARE BRACKETS) as this forum software extremely unhelpfully interprets C syntax as formatting tags. I have already edited your original post to do this.


non-uniform ticks

Posted by bertino on March 18, 2014


so in order to follow the suggestions I removed createTask statements and main becomes :

int main(void)

/* Start the scheduler. */

/* we should never get here */
for( ;; );


At this point MainHWInit() is reduced to very basic initializations :

void MainHWInit()

/* Init I/O ports */
Init_GPIOs ();



I still have the same tick gaps when I run after this. Whether or not worth to mention I have some code in the vApplicationTickHook(..) that toggles a "lifeness" led every 1000 tick counts using the same GPIO_HIGH/LOW commands to drive a led as used on the debug pin. Finally as you requested the GPIO high/low command definition:

#define GPIO_HIGH(a,b)          a->BSRRL = b
#define GPIO_LOW(a,b)           a->BSRRH = b

//plus defines below from stm32l1 libraries provided by default :

//from stm32l1xx.h :
#define GPIOC               ((GPIO_TypeDef *) GPIOC_BASE)

//from stm32l1xx_gpio.h :
#define GPIO_Pin_14                ((uint16_t)0x4000)  /*!< Pin 14 selected */

Please let me know if I'm still missing something. Thanks, Adalberto

non-uniform ticks

Posted by rtel on March 18, 2014

As the IO functions are direct hardware access macros, and nothing else is running that could potentially be disabling interrupts, assuming the clock to the CPU is stable I cannot say why you get the results you do. I would expect to see very regular pulses.

Could it be the resolution of your scope? Try setting the pin high on one tick, then low on the next tick, instead of high then low within the same tick period.

Do you have configUSETICKLESSIDLE defined? If so, is it defined to 0? (it will default to 0 if it is not defined).


non-uniform ticks

Posted by bertino on March 18, 2014


due to other needs the measurement equipment on my desk was temporarily downgraded to an old scope on which I found out some issues with the record lenght. So yes, you were right, the issue was scope resolution (sorry).

Thanks a lot for keeping me going forward. Regards, Adalberto

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner