VtaskDelay before scheduler start

Dear, Question is in the subject, does vTaskDelay is safe before Scheduler is starting of is this better to use alternate function for making delay ? Regards

VtaskDelay before scheduler start

vTaskDelay won’t work before the scheduler is started, as the system tick hasn’t been started yet, and interrupts are disabled.

VtaskDelay before scheduler start

Thanks Richard, in my case STM32L4 the initTick was already called before scheduler start so my FreeRTOS timer is working, so is there are other reason linked to task that not allow me to use vTaskDelay ?

VtaskDelay before scheduler start

Calling vTaskDelay() before the scheduler starts doesn’t really have any semantic sense as, if the scheduler has not been started, no tasks are executing, so no task can call vTaskDelay(). Calling vTaskDelay() from a function called by main() doesn’t make sense as its not a task. What is the use case?

VtaskDelay before scheduler start

initTick is NOT the call to setup the tick for FreeRTOS, that sounds like maybe part of the STMicro library (maybe they somehow support a dual use for it). Also, as Richard Barry said, what vTaskDelay does is put the current task into the blocked state and switch to another task for the duration, that sort of is hard to do before the schedule starts, since you don’t have any task, either current or another. If you have some initiliation that needs those sorts of delays, either you need a spin wait delay loop, or you postpone that part of the initialization until after your enable the FreeRTOS scheduler.

VtaskDelay before scheduler start

initTick is NOT the call to setup the tick for FreeRTOS, that sounds like maybe part of the STMicro library (maybe they somehow support a dual use for it).
ST chain their tick and the FreeRTOS tick.
If you have some initiliation that needs those sorts of delays, either you need a spin wait delay loop, or you postpone that part of the initialization until after your enable the FreeRTOS scheduler.
There is also an intialisation hook, which runs in the context of the timer task (which means you need to have timers enabled). It runs once when the scheduler starts and is provided to allow you to perform initialisation that requires the kernel. More traditional methods use an ‘initialisation’ task that performs the initialisation then creates all the other application tasks.