My contribution. For this CMU embedded systems course project, I developed the RTOS kernel, boot code, device drivers, carrier PCB, PID control, and system integration.
Overview
I built a preemptive RTOS on an STM32 Cortex-M4, from the ARM reset vector and exception handlers to the scheduler and device drivers. To exercise it on hardware, I ran a motor-control loop, interrupt-driven UART telemetry, and LCD updates as concurrent tasks on a small vehicle.
Kernel and drivers
I wrote the system bootloader in ARMv7-M assembly to initialize the exception vector table and stack pointers, then built bare-metal C drivers using MMIO for PWM, ADC, I2C, and interrupt-driven UART.
Preemptive multitasking uses the ARM Cortex-M exception model with separate process and kernel stacks for each thread. Thread code runs on PSP; exception handlers use MSP. SysTick tracks thread budgets and pends PendSV. Its assembly wrapper saves PSP and the remaining registers, while the C handler records that kernel frame in the thread control block (TCB) and selects the next runnable thread. The same wrapper then restores the selected context before exception return.
SysTick requests PendSV. Selection and restoration happen within that one handler before Thread B resumes.
OverviewThe complete context switchFollow one handoff from Thread A to Thread B.
Task priorities are assigned by a rate-monotonic scheduler validated against the utilization bound, with an SVC path bridging user and kernel space, newlib support for printf and malloc, and priority-inheritance mutexes (HLP/IPCP) to bound priority inversion.
Scheduling on the bench
The selected PID, UART, and LCD parameters produce 71.25% modeled utilization, below the 77.98% rate-monotonic utilization bound for three tasks. The simulator below reconstructs that task set so you can explore the analytical schedulability margin.
Modeled task utilization
71.25% across PID, UART, and LCD threads
Schedulability bound
77.98% for three tasks
Scheduling result
Analytically schedulable under the selected RMS task parameters
Vehicle carrier board PCB layoutAdjust the schedulerPointerClick the −/+ controls to change task timing.TouchTap the −/+ controls to change task timing.KeyboardTab to each control and press Enter or Space.
Test platform
I designed a two-layer carrier board in Autodesk Fusion to connect the STM32 Nucleo to the vehicle hardware. It distributes 5 V and 3.3 V through LM1084 regulators and routes signals to the L298 H-bridges, quadrature encoders, servos, and I²C LCD.
Carrier board for the STM32 Nucleo, with connections for power, motor drivers, encoders, and the LCD.
Motor-control workload
The vehicle used EXTI interrupts to decode quadrature encoder signals and hardware-timer PWM to drive the motors. With the PID loop running alongside UART telemetry and LCD updates, I measured less than 10% average wheel-speed error from the target using encoder telemetry over UART.