A Quadcopter Flight Controller With a Custom RTOS

Post by Souleymane Dembele on Mar 23, 2025

This project is a research-grade quadcopter flight controller built from the firmware up on an STM32F405 (ARM Cortex-M4), including my own real-time operating system and a model-predictive-style attitude controller.

Firmware and RTOS

I wrote bare-metal drivers for the peripherals the controller needs: interrupts, timers, PWM, ADC/DAC, SPI, I2C, UART, and an ExpressLRS (LoRa) telemetry link with an interrupt-driven UART parser. On top of that sits a custom lightweight RTOS with a scheduler, semaphores, and inter-task communication. PWM outputs drive the motors through the ESCs.

Control and estimation

The attitude controller is a dual-rate lifted-model generalized predictive control (GPC) state-space design that reconciles two sensors sampled at different rates: an ICM20602 IMU at 1200 Hz and a BNO085 9-DOF sensor at 400 Hz. A Kalman filter fuses the two, and a real-time quaternion gives attitude.

I modeled the full six-degree-of-freedom UAV dynamics in MATLAB/Simulink and compared the dual-rate GPC against a double/inner-loop PID baseline. In simulation the GPC settled in 0.8 s versus 1.2 s for the PID, with 5% versus 12% overshoot and about half the RMS tracking error (0.03 versus 0.06), plus near-zero steady-state error across pitch, roll, and yaw. Initial hardware tests validated the simulation behavior.

Hardware co-design

I iterated hardware and software together: firmware came up first on an STM32F411 Nucleo, then on a custom v1 PCB (STM32F405) that integrates the sensors, power regulation, and a 16 MB (128 Mbit) external flash.

What I took from it

Real-time embedded systems end to end: deterministic scheduling and driver design under hard timing budgets, control theory and state estimation in C, and hardware/software co-design through a custom PCB bring-up.

View the full report (PDF)  ·  View the presentation (PDF)  ·  View the hardware / components doc (PDF)