This project implements a basic task scheduler in C on the STM32F407 Discovery board. The scheduler is designed using a round-robin strategy and includes task delay management and support for idle task execution. Inspired by Kiran Nayak's Udemy course, this implementation adds a custom priority override feature to give more control over task execution order.
- Fully Preemptive Round-Robin Scheduling: Each task is given CPU time in turn, interrupted every 1 ms by a system tick.
- Task Delay Mechanism: Tasks can block themselves for a number of ticks, freeing up the CPU for others.
- Idle Task: Executes when no other tasks are ready to run.
- Custom Task Priority (Custom Addition): One task can be configured to be of priority and hence is allowed to preempt others if it's ready.
- Efficient Context Switching:
SysTickinterrupt drives the 1 ms system tick.- Tasks are unblocked when delay expires.
PendSVis used to perform the context switch, ensuring minimal ISR latency and deterministic task switching.
SysTick (every 1 ms)↓Update task block counters↓Are any tasks unblocked?↓Yes ──► Set PendSV Pending↓PendSV Handler↓Context Switch to next ready task
- STM32F407 Discovery Board
- STM32CubeIDE
- C Programming Language
- Four user-defined tasks blink the on-board LEDs (Green, Orange, Blue, Red) with different delays.
- Tasks voluntarily yield the CPU after execution using a delay function.
- The idle task runs only when all others are delayed.
- A configurable prioritized task (set in code) always executes first if it’s ready.
- Clone the repository and open the project in STM32CubeIDE.
- Connect your STM32F407 Discovery board via ST-Link.
- Build and flash the firmware to the target.
- Observe the LED behavior as per task scheduling logic.
Core/
├── Inc/ # Header files (main.h)
├── Src/ # Source files (main.c)
Startup/
└── startup_stm32f407xx.s
- Building a fully preemptive task scheduler from scratch on ARM Cortex-M.
- Leveraging
SysTickfor precise periodic interrupts to drive task scheduling. - Implementing context switching using the
PendSVexception to defer low-priority context changes. - Deepened understanding of STM32, interrupt handling, and register-level control.
- Managing task states: ready, running, blocked, and idle with custom delay and priority logic.
This project is licensed under the MIT License – see the LICENSE file for details.