Skip to content

MrudulaSatya/STM32F4_task_scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STM32F4 Task Scheduler (Round Robin with Task Delay and Priority Support)

Platform Language IDE License

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.

Features

  • 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:
    • SysTick interrupt drives the 1 ms system tick.
    • Tasks are unblocked when delay expires.
    • PendSV is used to perform the context switch, ensuring minimal ISR latency and deterministic task switching.

How It Works

 SysTick (every 1 ms) 
Update task block counters
Are any tasks unblocked?
Yes ──► Set PendSV Pending
PendSV Handler
Context Switch to next ready task

Hardware & Tools

  • STM32F407 Discovery Board
  • STM32CubeIDE
  • C Programming Language

Behavior

  • 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.

Getting Started

  1. Clone the repository and open the project in STM32CubeIDE.
  2. Connect your STM32F407 Discovery board via ST-Link.
  3. Build and flash the firmware to the target.
  4. Observe the LED behavior as per task scheduling logic.

Directory Structure

Core/
├── Inc/ # Header files (main.h)
├── Src/ # Source files (main.c)
Startup/
└── startup_stm32f407xx.s

Learnings

  • Building a fully preemptive task scheduler from scratch on ARM Cortex-M.
  • Leveraging SysTick for precise periodic interrupts to drive task scheduling.
  • Implementing context switching using the PendSV exception 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.

License

This project is licensed under the MIT License – see the LICENSE file for details.

About

This project implements a basic task scheduler using a round-robin strategy in C on the STM32F407 Discovery board. Inspired by Kiran Nayak's Udemy course, this implementation adds a custom priority override feature to give more control over task execution order.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors