Hello,
I Am using freeRTOS with STM32 F2 microprocessor.
I need to execute some operations for configuring my hardware, before creating my Tasks. In this Setup operations, I need to use any kind of delay() function.
But At the beginning of the program, vTaskDelay() is not still available. What is the way for using delay functionality before create Tasks and starts scheduler, by calling vTaskStartScheduler() ?
Or stated another way:
Do I have to create a Setup() function as a Task, and then the other Tasks have to wait to start till the setup() finalizes? Is there an specific freeRTOS function to synchronize them that way?
If you want to have a blocking delay without using RTOS, you’ll have to setup a timer that triggers an interrupt.
What I would do:
Setup the clocks and a timer for RTOS
Start your first task and from there:
Call your Setup() and use vTaskDelay()
Start-up the other tasks
void vMainTask (void *pvParameters)
{
/* While running Setup(), there are
no other tasks yet */
Setup( );
xTaskCreateStack (vMacbTASK, ...)
xTaskCreateStack (vUsbTASK, ...)
xTaskCreateStack (vLoggingTASK, ...)
for( ; ; )
{
/* Do the normal work */
}
}
In order to be able to use vTaskDelay() in my Setup() function , I am creating all task at the same time, but Setup with higher priority. That way I am sure that it starts the first:
When I encountered a similar issue in my design, I chose to implement as Hein described. I felt this was better for the reader and eliminated the chance of a race condition. The way you describe requires internal knowledge of the OS, which high-level code should not rely on. For example, if a maintainer moved TaskCreate( mySetup ) after the other TaskCreates, then the outcome wouldn’t be clear even with knowledge of the priorities.