Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

non-uniform ticks

Posted by bertino on March 18, 2014

Hi,

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
  GPIO_HIGH(GPIOC,GPIO_Pin_14);
#endif
	( void ) portSET_INTERRUPT_MASK_FROM_ISR();
	{
		/* Increment the RTOS tick. */
		if( xTaskIncrementTick() != pdFALSE )
		{
			/* A context switch is required.  Context switching is performed in
			the PendSV interrupt.  Pend the PendSV interrupt. */
			portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
		}
	}
	portCLEAR_INTERRUPT_MASK_FROM_ISR( 0 );
#ifdef ST_DEBUG
  GPIO_LOW(GPIOC,GPIO_Pin_14);
#endif
}

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 :

portNVICINTCTRLREG = portNVICPENDSVSET_BIT;

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.

Regards.


non-uniform ticks

Posted by bertino on March 18, 2014

Ok,

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


int main(void)
{       
MainHWInit();

/* Start the scheduler. */
vTaskStartScheduler();

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

}

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


void MainHWInit()
{   
RCC_Configuration();

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

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

}

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).

Regards.


non-uniform ticks

Posted by bertino on March 18, 2014

Hi,

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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists