README.md
December 13, 2024 ยท View on GitHub
FreeRTOS_Mutex Application Description
This application demonstrates the use of mutexes to serialize access to a shared resource.
The application has two threads:
-Thread1 : Prints messages counting from 1 to 10 ("Thread1 : This is message number x")
Blinks the green LED each 200ms
-Thread2 : Prints messages counting from 1 to 10 ("Thread2 : This is message number x")
Blinks the green LED each 600ms
The mutex is created before the threads using it are scheduled. Each thread will try to acquire it before outputting characters to the serial port. Once the mutex is acquired, the thread will proceed to printing its message, and then immediately releases it.
If the mutex is not used, the two threads will try to use "printf" at almost the same time. This will result in either thread winning over the other or both threads interrupting each other.
The user can observe the effect of not using a mutex to protect printf by setting the
EXAMPLE_USES_MUTEX define in Src/app_freertos.c to 0.
Expected success behavior
If the EXAMPLE_USES_MUTEX is set to 0, some messages will not be printed, or may be corrupted.
If the EXAMPLE_USES_MUTEX is set to 1, each thread will display 10 messages identified by the thread name
and the message number , for a total of 20 messages. Additional messages will be printed to displayed when
the mutex is acquired or released.
Success behavior is marked by toggling the green LED.
Error behaviors
On failure, the green LED is turned off and an error message is printed to the serial port.
Assumptions if any
None
Known limitations
None
Notes
None
FreeRTOS usage hints
The FreeRTOS heap size configTOTAL_HEAP_SIZE defined in FreeRTOSConfig.h is set accordingly to the OS resources memory requirements of the application with +10% margin and rounded to the upper Kbyte boundary.
For more details about FreeRTOS implementation on STM32Cube, please refer to UM1722 "Developing Applications on STM32Cube with RTOS".
Keywords
FreeRTOS, Mutex, Threading
Hardware and Software environment
-
This application runs on STM32U38xx devices.
-
This application has been tested with STMicroelectronics STM32U385RG-Q board MB1841-U385RGQ-D01 and can be easily tailored to any other supported device and development board.
-
This application uses USART1 to display output, the hyperterminal configuration is as follows:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- Stop Bit = 1
- Parity = None
- Flow control = None
How to use it ?
In order to make the program work, you must do the following :
- Open the project in your preferred toolchain
- Rebuild all files and load your image into target memory
- Run the application