Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Setup() with delay() functionality, before creating Task

Posted by vr6073 on October 26, 2014

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?


Setup() with delay() functionality, before creating Task

Posted by heinbali01 on October 26, 2014


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 */


Regards, Hein

Setup() with delay() functionality, before creating Task

Posted by vr6073 on October 30, 2014

Thank you, Hein,

I am testing another way to do it:

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:

xTaskCreate(mySetup, "mySetup", STACK_SIZE, NULL, tskIDLE_PRIORITY+2, NULL);

xTaskCreate(Task1, "Task1", STACK_SIZE, NULL, tskIDLE_PRIORITY+1, &xTasksHandle1);

xTaskCreate(AxisControl, "Task2", STACK_SIZE, NULL, tskIDLE_PRIORITY+1, &xTasksHandle2);

In the body of Setup, I suspend all others Tasks. At the end of Setup, I resume all other tasks and delete Setup Task.

void mySetup(void * pvParameters) {


for (;;) {
doing things, and using 
vTaskDelay() delays
// Resume the suspended tasks.

// Delete Setup task (ourselves).


It is working right now...

Setup() with delay() functionality, before creating Task

Posted by markwrichardson on October 30, 2014

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.

Anyone else have preferences they use ?


Setup() with delay() functionality, before creating Task

Posted by vr6073 on October 30, 2014

I've been studying the Hein's code again, and it's really good. I had misunderstood.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists