0
0
ARM Architectureknowledge~10 mins

PendSV and SysTick exceptions in ARM Architecture - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - PendSV and SysTick exceptions
SysTick Timer Counts Down
SysTick Exception Triggered
SysTick Handler Executes
PendSV Exception Set Pending
PendSV Exception Triggered
PendSV Handler Executes
Context Switch or Deferred Task
Return
SysTick counts down and triggers its exception, which can set PendSV pending. PendSV runs later to handle context switching or deferred tasks.
Execution Sample
ARM Architecture
void SysTick_Handler() {
  // Set PendSV pending
  SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
}

void PendSV_Handler() {
  // Perform context switch
  // Context switching code here
}
SysTick handler sets PendSV pending; PendSV handler performs context switch.
Analysis Table
StepEventActionException TriggeredHandler ExecutedResult
1SysTick timer reaches zeroSysTick exception triggeredSysTickSysTick_HandlerPendSV exception set pending
2PendSV exception pendingPendSV exception triggered after SysTickPendSVPendSV_HandlerContext switch performed
3Context switchedReturn to new task contextNoneNoneSystem continues with new task
💡 PendSV handler completes context switch; no more exceptions pending
State Tracker
VariableStartAfter Step 1After Step 2Final
SysTick_CountNon-zeroZero (trigger)ZeroReloaded after interrupt
PendSV_PendingFalseTrue (set by SysTick)False (handled)False
Current_TaskTask ATask ATask B (switched)Task B
Key Insights - 2 Insights
Why does SysTick set PendSV pending instead of doing the context switch directly?
SysTick_Handler sets PendSV pending to defer the context switch to a lower priority handler, avoiding interrupt nesting and ensuring safe switching (see execution_table step 1 and 2).
When exactly does PendSV execute after being set pending?
PendSV executes after all higher priority exceptions finish, here after SysTick_Handler completes (see execution_table step 2).
Visual Quiz - 3 Questions
Test your understanding
According to the execution_table, what happens immediately after SysTick exception triggers?
ASystem returns to main task
BPendSV exception is set pending
CContext switch is performed
DSysTick timer reloads
💡 Hint
Look at execution_table row 1, 'Result' column
At which step does the actual context switch occur?
AStep 2
BStep 1
CStep 3
DAfter Step 3
💡 Hint
Check execution_table 'Handler Executed' and 'Result' columns
If PendSV was not set pending by SysTick, what would change in the variable_tracker?
ASysTick_Count would not reach zero
BCurrent_Task would switch earlier
CPendSV_Pending would remain False after Step 1
DNo change in variables
💡 Hint
See variable_tracker row for PendSV_Pending after Step 1
Concept Snapshot
PendSV and SysTick exceptions work together for task switching.
SysTick triggers regularly and sets PendSV pending.
PendSV runs later at lower priority to switch tasks safely.
This avoids nested interrupts and keeps system stable.
SysTick counts down; PendSV handles context switch.
Full Transcript
In ARM architecture, the SysTick timer counts down and triggers the SysTick exception when it reaches zero. The SysTick handler runs and sets the PendSV exception as pending. PendSV is a special exception designed to run at a low priority. It executes after higher priority exceptions finish, allowing it to perform context switching or deferred tasks safely. This separation avoids nested interrupts and keeps the system stable. The execution flow starts with SysTick triggering, then PendSV pending is set, and finally PendSV runs to switch the current task context. Variables like SysTick_Count, PendSV_Pending, and Current_Task change accordingly during this process.