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

Tick Rate Problem

Posted by k3nt00 on December 23, 2014

Hello,

I'm having some trouble with the tick rate. I am using the CORTEXSTM32F107GCC_Rowley demo, but on a different board with the same exact chip and crystal clock frequency of 25MHz. The prvSetupHardware() func sets the clock up for 62.5MHz. I have I2C and UART working at the correct rates. What I can can't seem to get working at the expected timing is the tick rate. My tick rate is set for 1000Hz. When I run a single and simple task that simply toggles a pin and then vTaskDelayUntil for 1 tick, it ends up being ~30ms when it should be 1ms. I've been trying to figure out what I'm doing wrong, but haven't. Any help is greatly appreciated!

Thank you I am using: Chip: STM32F107VC (Cortex-M3) Compiler: arm-none-eabi-gcc Version: FreeRTOS V8.0.1


Tick Rate Problem

Posted by edwards3 on December 23, 2014

You have set your tick to give you a resolution of 1ms, so if you try and block for 1ms I would expect to block for between 0.00001 and 0.99999ms, so you will get odd results, but you should not get longer than 1ms. If you are getting 30ms then likely the SysTick clock in your STM32 is not running at the frequency you think it is. The SysTick is part of the core of the STM32.


Tick Rate Problem

Posted by k3nt00 on December 24, 2014

I actually get ~30ms when using 1-10 delay ticks. If I use greater than 10, the actual blocking delay is (ticks x 3).

my hardware setup func

~~~~~~~

static void prvSetupHardware( void ) { /* Start with the clocks in their expected state. */ RCC_DeInit();

/* Enable HSE (high speed external clock). */ RCCHSEConfig( RCCHSE_ON );

/* Wait till HSE is ready. */ while( RCCGetFlagStatus( RCCFLAG_HSERDY ) == RESET ) { }

/* 2 wait states required on the flash. */ *( ( unsigned long * ) 0x40022000 ) = 0x02;

/* HCLK = SYSCLK */ RCCHCLKConfig( RCCSYSCLK_Div1 );

/* PCLK2 = HCLK */ RCCPCLK2Config( RCCHCLK_Div1 );

/* PCLK1 = HCLK/2 */ RCCPCLK1Config( RCCHCLK_Div2 );

/* PLLCLK = (25MHz / 2 ) * 5 = 62.5 MHz. */ RCCPLLConfig( RCCPLLSourceHSIDiv2, RCCPLLMul5 );

/* Enable PLL. */ RCC_PLLCmd( ENABLE );

/* Wait till PLL is ready. */ while(RCCGetFlagStatus(RCCFLAG_PLLRDY) == RESET) { }

/* Select PLL as system clock source. */ RCCSYSCLKConfig( RCCSYSCLKSource_PLLCLK );

/* Wait till PLL is used as system clock source. */ while( RCC_GetSYSCLKSource() != 0x08 ) { }

/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */ RCCAPB2PeriphClockCmd( RCCAPB2PeriphGPIOA | RCCAPB2PeriphGPIOB |RCCAPB2PeriphGPIOC | RCCAPB2PeriphGPIOD | RCCAPB2PeriphGPIOE | RCCAPB2Periph_AFIO, ENABLE );

/* Set the Vector Table base address at 0x08000000 */ NVICSetVectorTable( NVICVectTab_FLASH, 0x0);

NVICPriorityGroupConfig( NVICPriorityGroup_4 );

/* Configure HCLK clock as SysTick clock source. */ SysTickCLKSourceConfig( SysTickCLKSource_HCLK ); }

~~~~~~~

freertos config

~~~~~~~

ifndef FREERTOSCONFIGH
define FREERTOSCONFIGH
define configUSE_PREEMPTION 1
define configUSEIDLEHOOK 0
define configUSETICKHOOK 0
define configCPUCLOCKHZ ( ( unsigned long ) 62500000 )
define configTICKRATEHZ ( ( TickType_t ) 1000 )
define configMAX_PRIORITIES ( 6 )
define configMINIMALSTACKSIZE ( ( unsigned short ) 128 )
define configTOTALHEAPSIZE ( ( size_t ) ( 30 * 1024 ) )
define configMAXTASKNAME_LEN ( 16 )
define configUSE16BIT_TICKS 0
define configIDLESHOULDYIELD 1

/* Co-routine definitions. */

define configUSECOROUTINES 0
define configMAXCOROUTINE_PRIORITIES ( 2 )
define configUSE_MUTEXES 1
define configUSECOUNTINGSEMAPHORES 0
define configUSEALTERNATIVEAPI 0
define configCHECKFORSTACK_OVERFLOW 2
define configUSERECURSIVEMUTEXES 1
define configQUEUEREGISTRYSIZE 0

/* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */

define INCLUDE_vTaskPrioritySet 1
define INCLUDE_uxTaskPriorityGet 1
define INCLUDE_vTaskDelete 1
define INCLUDE_vTaskCleanUpResources 0
define INCLUDE_vTaskSuspend 1
define INCLUDE_vTaskDelayUntil 1
define INCLUDE_vTaskDelay 1

/* This demo makes use of one or more example stats formatting functions. These format the raw data provided by the uxTaskGetSystemState() function in to human readable ASCII form. See the notes in the implementation of vTaskList() within FreeRTOS/Source/tasks.c for limitations. */

define configUSESTATSFORMATTING_FUNCTIONS 1
define configUSETRACEFACILITY 1
define configGENERATERUNTIME_STATS 0

/* This is the raw value as per the Cortex-M3 NVIC. Values can be 255 (lowest) to 0 (1?) (highest). */

define configKERNELINTERRUPTPRIORITY 255

/* !!!! configMAXSYSCALLINTERRUPT_PRIORITY must not be set to zero !!!! See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */

define configMAXSYSCALLINTERRUPT_PRIORITY 191 /* equivalent to 0xb0, or priority 11. */

/* This is the value being used as per the ST library which permits 16 priority values, 0 to 15. This must correspond to the configKERNELINTERRUPTPRIORITY setting. Here 15 corresponds to the lowest NVIC value of 255. */

define configLIBRARYKERNELINTERRUPT_PRIORITY 15
define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

/----------------------------------------------------------- * Macros required to setup the timer for the run time stats. *-----------------------------------------------------------/ /* The run time stats time base just uses the existing high frequency timer test clock. All these macros do is clear and return the high frequency interrupt count respectively. */ extern unsigned long ulRunTimeStatsClock;

define portCONFIGURETIMERFORRUNTIME_STATS() ulRunTimeStatsClock = 0
define portGETRUNTIMECOUNTERVALUE() ulRunTimeStatsClock

//NEED THESE!!

define vPortSVCHandler SVC_Handler
define xPortPendSVHandler PendSV_Handler
define xPortSysTickHandler SysTick_Handler
endif /* FREERTOSCONFIGH */

~~~~~~~

toggle task

~~~~~~~

static void prvTOGGLETask( void *pvParameters ) {

char bit = 0;

portTickType xLastWakeTime;

xLastWakeTime = xTaskGetTickCount();

/* Block for 10ms. */ const TickTypet xDelay = 10 / portTICKPERIOD_MS;

for(;;) {

  if(bit)
    GPIOC->BSRR = 1 << 6;
  else
    GPIOC->BRR  = 1 << 6;
  bit = !bit;

  vTaskDelayUntil( &xLastWakeTime, xDelay);

} }

~~~~~~~


Tick Rate Problem

Posted by rtel on December 24, 2014

It is out of scope to look at hardware set up here, but looking at your FreeRTOSConfig.h settings:

Where did the value 62500000 come from in your configCPUCLOCKHZ setting? From your description it is most likely that the frequency of the clock feeding the SysTick timer is different from this value.

Regards.


Tick Rate Problem

Posted by k3nt00 on December 24, 2014

Thank you very much for your responses!

I found the problem.

Apologies for the lack of relevance to FreeRTOS.

In the demo program, the prvSetupHardware() function sets the clock as so:

~~~~~~

/* PLLCLK = (25MHz / 2 ) * 5 = 62.5 MHz. */ RCCPLLConfig( RCCPLLSourceHSIDiv2, RCCPLLMul5 );

~~~~~~

But in the most recent stm32f10xrcc.h, RCCPLLSourceHSEDiv2 is not defined for STM32F10X_CL, which is this chip.

~~~~~~

/** @defgroup PLLentryclock_source * @{ */

define RCCPLLSourceHSIDiv2 ((uint32t)0x00000000)
if !defined (STM32F10XLDVL) && !defined (STM32F10XMDVL) && !defined (STM32F10XHDVL) && !defined (STM32F10X_CL)

#define RCCPLLSourceHSEDiv1 ((uint32t)0x00010000) #define RCCPLLSourceHSEDiv2 ((uint32t)0x00030000) #define ISRCCPLLSOURCE(SOURCE) (((SOURCE) == RCCPLLSourceHSIDiv2) || ((SOURCE) == RCCPLLSourceHSEDiv1) || ((SOURCE) == RCCPLLSourceHSEDiv2))

else

#define RCCPLLSourcePREDIV1 ((uint32t)0x00010000) #define ISRCCPLLSOURCE(SOURCE) (((SOURCE) == RCCPLLSourceHSIDiv2) || ((SOURCE) == RCCPLLSource_PREDIV1))

endif /* STM32F10X_CL */

~~~~~~

I used the value ((uint32_t)0x00030000), and I am now getting ~10ms.


[ 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