STM32 FreeRTOS Demonstrate access contention problems when using shared resources in a multitasking system
This exercise demonstrates the use of FreeRTOS on an STM32F401 microcontroller to implement priority-based preemptive multitasking. Two tasks control the blinking of a green and red LED, while a blue LED is used to indicate task interference during shared data access.
- RTOS: FreeRTOS with priority-based preemptive scheduling.
- LED Control:
- Green LED: Controlled by a task with normal priority.
- Red LED: Controlled by a task with above-normal priority.
- Blue LED: Indicates collisions in shared data access.
- Task Management: Demonstrates task scheduling, preemption, and shared resource handling.
- Collision Detection: Blue LED toggles when task interference occurs.
- Microcontroller: STM32F401.
- LEDs:
- Green LED: Connected to PA5.
- Red LED: Connected to PB0.
- Blue LED: Connected to PB7.
- Development Environment: STM32CubeIDE or compatible ARM GCC toolchain.
- HAL Library: STM32 HAL library for GPIO and system initialization.
- FreeRTOS: Real-Time Operating System for multitasking.
- Green LED: Connected to PA5 for visualizing the normal-priority task.
- Red LED: Connected to PB0 for visualizing the above-normal-priority task.
- Blue LED: Connected to PB7 for collision detection indication.
- Pull-down resistors are used for stabilization, with negative LED pins connected to ground.
- Toggles the green LED every 500 ms.
- Represents a lower-priority task, preempted by the Red LED Task when required.
- Toggles the red LED every 100 ms.
- Represents a higher-priority task that preempts the Green LED Task.
- Both tasks access a shared variable
start_flag
. - If a collision occurs, the Blue LED toggles to indicate interference.
- FreeRTOS kernel handles task scheduling.
- The Red LED Task preempts the Green LED Task due to its higher priority.
- The Blue LED highlights any collision during shared data access.
- Select the STM32F401 microcontroller.
- Enable GPIO pins for PA5, PB0, and PB7.
- Enable FreeRTOS middleware.
- Add two tasks:
- FlashGreenLEDTask: Normal priority.
- FlashRedLEDTask: Above-normal priority.
- Generate project code for STM32CubeIDE or your preferred IDE.
- Build the project and flash it to the STM32F401 using an ST-Link or compatible programmer.
- The green LED toggles every 500 ms.
- The red LED toggles every 100 ms, preempting the Green LED Task.
- The blue LED toggles when a collision is detected during shared data access.
