Hello everyone,
I’m currently developing a machine fault diagnosis system using FreeRTOS on an STM32F401RE board.
The system runs three main tasks as follows:
- Sensing Task – Collects 2048 acceleration samples from a USB-based accelerometer.
- Model Task – Performs inference using the collected data to determine whether the machine is normal or faulty.
- Communication Task – Displays the inference result on an LCD panel.
System Concept
The Sensing Task and Model Task share a global buffer, and The Model Task and Communication Task share another global variable for the model’s output.
Data integrity must be guaranteed:
The model should never read partially updated sensor data, and the communication task should not display outdated results.
Therefore, I want to ensure mutual exclusion and strict task sequencing.
To maintain responsiveness and ensure that results are always up-to-date, I’ve set task priorities as:
Communication Task > Model Task > Sensing Task
Intended Execution Flow
The system follows an event-driven pipeline rather than periodic scheduling:
- Sensing Task collects 2048 samples.
- Once data collection is complete, it notifies the Model Task.
- Model Task performs inference, then notifies the Communication Task.
- Communication Task displays the result and finally signals the Sensing Task to start the next cycle.
- The cycle repeats indefinitely.
In this architecture, only the Sensing Task remains active most of the time; the Model and Communication tasks stay blocked until they are explicitly triggered by the previous stage.
My Question
I’m trying to design the synchronization and data protection mechanisms properly in FreeRTOS.
Currently, I’m considering two options:
- Use binary semaphores for signaling between tasks, so each task wakes up only when its input data is ready.
- Use a mutex to protect the shared global buffers from concurrent access (for data consistency).
In other words,
Binary semaphore for task synchronization + Mutex for data consistency
I’d like to confirm if this is considered a good practice or if there’s a more appropriate design pattern in FreeRTOS for this kind of sequential, event-driven system.
Any guidance or feedback would be greatly appreciated.
Thank you in advance for your help!
P.S.
This post was translated from Korean using a generative AI tool.