Using Mutex before scheduler starts

On STM32F4 application, I need to synchronize access to a resource (SPI/Flash). So, I am going to use a mutex. However, before starting the scheduler, I need to access the resource to get some data. The synchronization code is there [xSemaphoreTake( h,10 ) / xSemaphoreGive( h )] At the beginning (before scheduler starts) all accesses are serial. Will this work as I use ticks in the call to take function? Thanks.

Using Mutex before scheduler starts

There is little point using the mutex before the scheduler has started, so I assume the reason you are doing it is because the same code runs both before and after the scheduler is running. I THINK that, as long as you have a block time of 0, then you SHOULD be ok, but am going from memory of the source code and haven’t actually tried it. Note that calling [nearly] any FreeRTOS API function before the scheduler has started will [deliberately] leave interrupts disabled.

Using Mutex before scheduler starts

I thought that the ticks are effective if there is another task using the resurce (already took the mutex) and ticks used are to give the the calling code a chance to wait. Since scheduler has not started, and access is serial, the tick has no effect since no other code is taking the mutex. Is this true?

Using Mutex before scheduler starts

Note that calling [nearly] any FreeRTOS API function before the scheduler has started will [deliberately] leave interrupts disabled.
I do have initialization code enables other interrupts. Does that mean if I use an API function before scheduler starts, I have to re-enable those IRQs?

Using Mutex before scheduler starts

Interrupts up to configMAXSYSCALLINTERRUPTPRIORITY will be left disabled. You can renable them by calling portENABLEINTERRUPTS() (again, I think that is the case, didn’t actually check the source code). Note calling portEXIT_CRITICAL() will NOT re-enable them.

Using Mutex before scheduler starts

To avoid all this complexity, do you recommend to create an initialization task and start scheduler. Then the initialization task initializes all resources, then delete itself? Thanks.

Using Mutex before scheduler starts

That is a common technique. Recent versions of FreeRTOS also have a startup hook – a function that runs once when the scheduler starts.

Using Mutex before scheduler starts

I am using FreeRTOS V8.2.1, do you recommend to upgrade?