Work in Progress
STM32 Microcontroller and FreeRTOS Development- PendSV (Pendable Service) Exception
- SVC (Supervisor Call) Exception
- SysTick Timer Exception
- Scheduling and Exception Handling on Cortex-M
- STM32/Cortex-M Interrupt Priorities
PendSV (Pendable Service) Exception
- Used by the RTOS to perform deferred context switches between tasks
- Usually pended by the SysTick handler or when a task explicitly yields
- Configured at the lowest interrupt priority so that context switching occurs only after higher-priority interrupt handlers have finished
- Triggered by software through the NVIC’s Interrupt Control and State Register, not directly by a peripheral
SVC (Supervisor Call) Exception
- Synchronously triggered by executing an SVC instruction
- Used to request privileged operating-system services
- In FreeRTOS Cortex-M ports, SVC 0 is executed by vPortStartFirstTask() to start the scheduler and restore the first task’s context
- In those ports, this startup call normally occurs only once; other ports, particularly MPU-enabled ones, may use SVC for additional services
SysTick Timer Exception
- Provides the FreeRTOS timebase at configTICK_RATE_HZ
- Runs at the lowest interrupt priority in typical Cortex-M ports
- Updates delays and timeouts on every tick
- Pends PendSV when task rescheduling is needed
Scheduling and Exception Handling on Cortex-M


STM32/Cortex-M Interrupt Priorities
On STM32 microcontrollers, FreeRTOS configures PendSV and SysTick at the lowest NVIC priority using configKERNEL_INTERRUPT_PRIORITY. Interrupts with a numeric priority value equal to or greater than configMAX_SYSCALL_INTERRUPT_PRIORITY may call only FromISR() APIs, while higher-priority interrupts with smaller numeric values must not call FreeRTOS APIs. The NVIC also supports nesting, allowing higher-priority interrupts to preempt lower-priority ones.

// FreeRTOSConfig.h
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#ifdef __NVIC_PRIO_BITS
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4
#endif
// Lowest priority allowed in priority-setting functions
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
// Priorities 0–4: High-priority ISRs; must not call FreeRTOS APIs
// Priorities 5–15: RTOS-aware ISRs; may call only xxxFromISR() APIs
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 Back to top of the page