Here’s another silly question:
Is there a way to get a count of clock or timer ticks between two points? I meant some API that behaves in a similar way to STM32 HAL_GetTick() function.
The idea comes from the need to take an arbitrary time count and then poll until a count of ticks(or miliseconds) has reached a condition.
PS: vTaskDelay() API does not work in this scenario
xTaskGetTickCount - RTOS task (thread) utilities including API functions for tracing FreeRTOS, getting the RTOS tick count, getting a task handle, getting the RTOS kernel or RTOS scheduler state, listing the tasks in the embedded system, and obtaining run time task statistics.
vTaskDelayUntil is probably what you are looking for - FreeRTOS - A FREE Open Source Simple RTOS Scheduler API documentation
The only thing to add to what @aggarg wrote is that FreeRTOS tick clocks may not aacurately reflect “absolute” time because heavy ISR activity may starve out the sytem clock. If you need absolute time deltas, you may want to keep a free running timer (on an ST Cortex M, there will be plenty) and simply query its counter value.
In addition to @aggarg you could use RTOS - vTaskSetTimeOutState() in conjunction with RTOS - xTaskCheckForTimeOut() for instance if you need to poll something guarded by a timeout. You could use a
vTaskDelay inside the poll loop to avoid hogging the CPU completely.
See the example code of the latter how to do that.
Thank you all guys,
The xTaskGetTickCount() suggested by @aggarg is the best fit for my case. The accuracy in my case is not a must, as I just need to check a timeout condition has happened while writing to a NOR flash memory. So, not need for setting a hardware timer in this case.
The @hs2 suggestion looks interesting, a bit hard to understand for me now, as I am a newbie using FreeRTOS. I will take a look at it though