Embedded STM32 GPS Navigation

DIY Return-to-Home Drone

Custom-built quadcopter with an STM32 BluePill flight controller implementing GPS-based Return-to-Home (RTH). Features a PID control loop for stable flight, IMU sensor fusion (accelerometer + gyroscope), and autonomous waypoint navigation โ€” all running on a bare-metal ARM Cortex-M3 at 72 MHz.

STM32
ARM Cortex-M3
GPS
Return-to-Home
PID
Flight Control
6-DOF
IMU Fusion
View on Hackster Related: COVID Drone ๐Ÿ† โ†’
Flight Control System
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ RC Radio โ”‚ โ”‚ Receiver โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ PPM/SBUS โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ GPS โ”‚ โ”‚ โ”‚ IMU โ”‚ โ”‚ Module โ”‚ โ”‚ โ”‚ MPU6050 โ”‚ โ”‚ (UART) โ”‚ โ”‚ โ”‚ (I2C) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ STM32 BluePill โ”‚ โ”‚ ARM Cortex-M3 โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Sensor โ”‚ โ”‚ โ”‚ โ”‚ Fusion โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ PID Controlโ”‚ โ”‚ โ”‚ โ”‚ (Roll/Pitchโ”‚ โ”‚ โ”‚ โ”‚ /Yaw/Alt) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ RTH Logic โ”‚ โ”‚ โ”‚ โ”‚ GPSโ†’Home โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ PWM โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ” โ”‚ ESC 1 โ”‚ โ”‚ ESC 2 โ”‚ โ”‚ESC 3/4โ”‚ โ”‚ Motor โ”‚ โ”‚ Motor โ”‚ โ”‚Motors โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Key Design Decisions
๐ŸŽฎ

STM32 BluePill as FC

The STM32F103C8T6 (BluePill) provides 72 MHz ARM Cortex-M3, multiple timers for PWM generation, hardware I2C/UART for sensors, and DMA โ€” all at under $2. Enough compute for a 1 kHz PID loop with GPS processing.

๐Ÿงญ

GPS RTH Algorithm

Stores home coordinates on arm. On signal loss or RTH trigger, calculates bearing and distance to home using Haversine formula, then commands heading and altitude hold until within landing radius.

๐Ÿ”„

Complementary Filter Fusion

Fuses accelerometer and gyroscope data with a complementary filter โ€” gyro for fast attitude changes, accelerometer for long-term drift correction. Simpler than Kalman with acceptable performance for hobby flight.

โš™๏ธ

Cascaded PID Loops

Separate PID controllers for roll, pitch, yaw rate, and altitude. Rate PIDs run at 1 kHz using gyro data; angle PIDs at 250 Hz using fused attitude. Manual tuning via serial console.

Hardware & Software
ComponentTechnologyPurpose
Flight ControllerSTM32F103 (BluePill)72 MHz ARM Cortex-M3 MCU
IMUMPU60506-DOF accel + gyro via I2C
GPSNEO-6M UART ModulePosition fix for RTH navigation
ESCSimonK / BLHeliBrushless motor speed control
Motors2212 920KV BrushlessQuad-rotor propulsion
RadioPPM/SBUS ReceiverManual control input
FrameworkBare-metal C / HALReal-time flight firmware
FrameF450 Quadcopter FrameAirframe structure
Related Projects