Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Using Mutex before scheduler starts

Posted by alsaleem on July 27, 2017

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

Posted by rtel on July 27, 2017

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

Posted by alsaleem on July 27, 2017

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

Posted by alsaleem on July 27, 2017

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

Posted by rtel on July 27, 2017

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

Posted by alsaleem on July 27, 2017

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

Posted by rtel on July 27, 2017

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

Posted by alsaleem on July 27, 2017

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


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


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner