# STM32F10x tick rate 1/2 speed

**URL:** <https://forums.freertos.org/t/stm32f10x-tick-rate-1-2-speed/899>\
**Category:** Kernel\
**Created:** [February 2, 2016, 5:07am UTC](https://forums.freertos.org/t/stm32f10x-tick-rate-1-2-speed/899 "2016-02-02T05:07:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 2, 2016, 5:07am UTC](https://forums.freertos.org/t/stm32f10x-tick-rate-1-2-speed/899/1 "2016-02-02T05:07:47Z")

</div>

**[ajcurtis84](https://sourceforge.net/u/ajcurtis84/)** wrote on [Tuesday, February 02, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/26d3a683/#0709):

Hello,  
I am having difficulties with timers and vTaskDelay() with the STM32F processor. It appears that delays are about 2X the programmed rate.

I created a very simple task that delays for 4 seconds and reports the actual number of elapsed ticks. The ticks are correct but the actually delay is around 8 seconds.

Sample code:

```auto
 	TickType_t start_tick;
 	TickType_t end_tick;
 	do {
 		start_tick = xTaskGetTickCount();
 		vTaskDelay(4000);
 		end_tick = xTaskGetTickCount();
 		trace_printf("msec2ticks:%u ticks\n", (uint16_t)(end_tick-start_tick));
 	}
 	while (pdTRUE);

```

Originally I thought this was a problem in 8.2.3, however I back ported to 8.2.0 and received the same results.

The only other change is the trace output configuration. Changed:

```auto
#undef OS_USE_TRACE_SEMIHOSTING
#define OS_USE_TRACE_ITM

```

Has anyone else had this issue?

TIA

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 2, 2016, 6:07am UTC](https://forums.freertos.org/t/stm32f10x-tick-rate-1-2-speed/899/2 "2016-02-02T06:07:32Z")

</div>

**[ajcurtis84](https://sourceforge.net/u/ajcurtis84/)** wrote on [Tuesday, February 02, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/26d3a683/#224a):

Here is some more information:

1. Created a BlinkyLED application from the Eclipse/GNUARM plugin. Removed all the LED related code and used the simple timer routines. These worked as expected.
2. Copied the STM “system” code from the BlinkyLED project to the FreeRTOS test program. Same problem with the tick rate being 1/2 rate.
3. Compared the RCC register configuration between the two programs. They were the SAME!

RCC:CR = 0x00015283  
RCC:CSR = 0x1C000000  
RCC:AHBENR = 0x00000014

Can anyone provide further insight or recommendations?

Thanks

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 2, 2016, 7:18am UTC](https://forums.freertos.org/t/stm32f10x-tick-rate-1-2-speed/899/3 "2016-02-02T07:18:55Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Tuesday, February 02, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/26d3a683/#3fa6):

Hi Allen,

What is your program printing:

```
msec2ticks:4000 ticks

```

or

```
msec2ticks:8000 ticks

```

?

I suppose that `configTICK_RATE_HZ` is defined as `1000` ?

Wat does `sysclk_get_cpu_hz()` return? Is the CPU really running at the expected frequency?

Regards.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 2, 2016, 9:06am UTC](https://forums.freertos.org/t/stm32f10x-tick-rate-1-2-speed/899/4 "2016-02-02T09:06:25Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, February 02, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/26d3a683/#68cf):

When I read:

> I created a very simple task that delays for 4 seconds and reports the actual number of elapsed ticks. The ticks are correct but the actually delay is around 8 seconds.

When reading this my thought was, if the delay is correct in the number of ticks, but the time is different, then this is simply a case of the CPU clock running at a different frequency to that which you think it is. Perhaps configCPU\_CLOCK\_HZ is wrong. However, then you write:

```
#undef OS_USE_TRACE_SEMIHOSTING
#define OS_USE_TRACE_ITM
```

you mention semihosting. Are you using semihosting? If so, don’t, it will mess up your timing as it will stop the CPU while outputing to the host - and that might be the problem you are seeing.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 2, 2016, 7:35pm UTC](https://forums.freertos.org/t/stm32f10x-tick-rate-1-2-speed/899/5 "2016-02-02T19:35:48Z")

</div>

**[ajcurtis84](https://sourceforge.net/u/ajcurtis84/)** wrote on [Tuesday, February 02, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/26d3a683/#9aa4):

Hello,

Thank you for the reply. No, I am not using SEMIHOSTING. Originally I was but it was causing all sorts of problems.

My BSP does not have the sysclk\_get\_clk\_hz() function so I inserted the following code.

```auto
  trace_printf("System clock: %u Hz\n", SystemCoreClock);

	RCC_ClocksTypeDef clock;
	RCC_GetClocksFreq(&clock);
	trace_printf("SYSCLK=%ld,HCLK=%ld,PCLK1=%ld,PCLK2=%ld,ADCCLK=%ld\n",
			clock.SYSCLK_Frequency,
			clock.HCLK_Frequency,
			clock.PCLK1_Frequency,
			clock.PCLK2_Frequency,
			clock.ADCCLK_Frequency);

```

This is the output

> System clock: 8000000 Hz  
> SYSCLK=8000000,HCLK=8000000,PCLK1=8000000,PCLK2=8000000,ADCCLK=4000000

Based on this I debugged the SystemInit() function and determined that HSE never becomes ready. It looks like the oscillator isn’t working?

Thank you for pointing me in the right direction.
