0
0
FreeRTOSprogramming~10 mins

FreeRTOS architecture overview - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - FreeRTOS architecture overview
Start FreeRTOS Kernel
Initialize Hardware & Resources
Create Tasks & Queues
Start Scheduler
Scheduler Chooses Task
Task Runs
Task Blocks or Yields
Scheduler Chooses Next Task
Idle Task Runs
Repeat Scheduling Cycle
This flow shows how FreeRTOS starts, creates tasks, runs the scheduler, and switches between tasks.
Execution Sample
FreeRTOS
void main(void) {
  xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL);
  vTaskStartScheduler();
}

void Task1(void *pvParameters) {
  for(;;) { /* Task code */ }
}
This code creates one task and starts the FreeRTOS scheduler to run it.
Execution Table
StepActionScheduler StateRunning TaskNotes
1System startsScheduler not runningNoneKernel initialized
2Create Task1Scheduler not runningNoneTask1 added to ready list
3Start SchedulerScheduler runningTask1Scheduler picks highest priority task
4Task1 runsScheduler runningTask1Task1 executes its loop
5Task1 blocks or yieldsScheduler runningIdle TaskNo ready tasks, idle runs
6Idle Task runsScheduler runningIdle TaskCPU idle until next event
7Task1 ready againScheduler runningTask1Scheduler switches back to Task1
8Repeat cycleScheduler runningTask1 or IdleContinuous scheduling
9System shutdownScheduler stoppedNoneScheduler stops, system halts
💡 Scheduler runs indefinitely until system shutdown or reset
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 5After Step 7Final
Scheduler StateNot runningNot runningRunningRunningRunningRunning
Running TaskNoneNoneTask1Idle TaskTask1Task1 or Idle
Task1 StateNot createdReadyRunningBlocked/YieldedReadyRunning or Blocked
Key Moments - 3 Insights
Why does the Idle Task run after Task1 blocks or yields?
When Task1 blocks or yields (see step 5 in execution_table), no other tasks are ready, so the scheduler runs the Idle Task to keep the CPU busy.
What happens if no tasks are created before starting the scheduler?
If no tasks exist, the scheduler runs only the Idle Task indefinitely, as shown in the scheduler state after step 3.
Does the scheduler stop automatically?
No, the scheduler runs indefinitely until the system is shut down or reset, as noted in the exit_note.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the running task immediately after starting the scheduler?
AIdle Task
BTask1
CNone
DScheduler
💡 Hint
Check step 3 in the execution_table where the scheduler starts and picks Task1.
At which step does the scheduler run the Idle Task?
AStep 4
BStep 5
CStep 6
DStep 7
💡 Hint
Look at the execution_table rows where the running task is Idle Task.
If Task1 never blocks or yields, which task runs continuously?
ATask1
BScheduler
CIdle Task
DNo task runs
💡 Hint
Refer to variable_tracker showing Task1 state during continuous running.
Concept Snapshot
FreeRTOS starts by initializing hardware and creating tasks.
The scheduler runs and picks the highest priority ready task.
Tasks run until they block, yield, or complete.
When no tasks are ready, the Idle Task runs.
The scheduler runs indefinitely managing task switching.
Full Transcript
FreeRTOS architecture begins with system start and hardware initialization. Tasks are created and added to the ready list. When the scheduler starts, it picks the highest priority ready task to run. Tasks execute their code until they block or yield, at which point the scheduler selects the next ready task. If no tasks are ready, the Idle Task runs to keep the CPU busy. This cycle repeats indefinitely until the system shuts down or resets.