FreeRTOS / FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.

Home Page:https://www.FreeRTOS.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] xTaskGetTickCount() erroneously skips ahead

AndrewSvatikDRS opened this issue · comments

xTaskGetTickCount() erroneously skips ahead after every 65536 ticks. So when calculating timing using values returned by xTaskGetTickCount(), there are problems! vTaskDelay() has no problems. The problem is with xTaskGetTickCount()...

For example:
Code:

TickType_t tickCount1, tickCount2;
while (1) {
	tickCount1 = xTaskGetTickCount();
	vTaskDelay(25);
	tickCount2 = xTaskGetTickCount();
	printf("[%ld] %lu ms have passed!\r\n",
			tickCount2, (tickCount2-tickCount1));
}

Output:

[64887] 25 ms have passed!
[64912] 25 ms have passed!
[64937] 25 ms have passed!
[64962] 25 ms have passed!
[66087] 1125 ms have passed!
[66112] 25 ms have passed!
[66137] 25 ms have passed!
[66162] 25 ms have passed!
[66187] 25 ms have passed!

Workaround is to use vTaskDelay() instead:

TickType_t tickCount = 0;
while (1) {
	vTaskDelay(25);
	tickCount += 25;
	printf("[%ld] %lu ms have passed!\r\n",
		xTaskGetTickCount(), tickCount);
}

PLATFORM:
Microprocessor: STM32L496xx (ARM Cortex-M4)
GNU Tools for STM32 (11.3.rel1)
FreeRTOS API CMSIS v2
FreeRTOS version 10.3.1
CMSIS-RTOS version 2.00

This looks very much like the issue reported on the FreeRTOS forum, and which is still "open".

Chances are very small that you have discovered a bug in the kernel that can be demonstrated so simply.

Please investigate the comments that you received and I am sure that you will find an explanation of the observed behaviour.

Results on STM32H743ZI:

[64960] 25 ms have passed!
[64987] 25 ms have passed!
[65014] 25 ms have passed!
[65041] 25 ms have passed!
[65068] 25 ms have passed!
[65095] 25 ms have passed!
[65122] 25 ms have passed!
[65149] 25 ms have passed!
[65176] 25 ms have passed!
[65203] 25 ms have passed!
[65230] 25 ms have passed!
[65257] 25 ms have passed!
[65284] 25 ms have passed!
[65311] 25 ms have passed!
[65338] 25 ms have passed!
[65365] 25 ms have passed!
[65392] 25 ms have passed!
[65419] 25 ms have passed!
[65446] 25 ms have passed!
[65473] 25 ms have passed!
[65500] 25 ms have passed!
[65527] 25 ms have passed!
[65554] 25 ms have passed!
[65581] 25 ms have passed!
[65608] 25 ms have passed!
[65635] 25 ms have passed!
[65662] 25 ms have passed!
[65689] 25 ms have passed!
[65716] 25 ms have passed!
[65743] 25 ms have passed!
[65770] 25 ms have passed!
[65797] 25 ms have passed!
[65824] 25 ms have passed!
[65851] 25 ms have passed!
[65878] 25 ms have passed!
[65905] 25 ms have passed!
[65932] 25 ms have passed!
[65959] 25 ms have passed!
[65986] 25 ms have passed!
[66013] 25 ms have passed!
[66040] 25 ms have passed!
[66067] 25 ms have passed!
[66094] 25 ms have passed!
[66121] 25 ms have passed!
[66148] 25 ms have passed!
[66175] 25 ms have passed!
[66202] 25 ms have passed!

Lets continue the discussion on the forum.

This looks very much like the issue reported on the FreeRTOS forum, and which is still "open".

Chances are very small that you have discovered a bug in the kernel that can be demonstrated so simply.

Please investigate the comments that you received and I am sure that you will find an explanation of the observed behaviour.

Yes, I let myself become fooled. I wish I could delete this

No Problem, the issue is now

image

Remember that 99% of our bugs are most probably caused by our own code. You're not the only one.

Wish you good luck with your projects.