top of page

STM32 Drone programming
from scratch
for manual mode

About course

This is the only course that explains high-performance drone firmware programming from scratch based on a 32-bit ARM Cortex microcontroller. Through this course, you can learn and implement the features of drone control system step by step from GPIO, sensor interface to motor control with PID controller NOT USING OPEN SOURCE SW/HW SUCH AS PIXHAWK OR ARDUPILOT. And you will experience development process of embedded applications.

Even beginners can easily follow the course.

MH-FC V2.2 and drone parts are required.

All source code are available on github.

• Processor: 32-bit ARM Cortex M4 based STM32F405

• Programming language: C

• IDE: STM32CubeIDE with HAL and LL driver

• OS: No OS (Bare-metal firmware programming)

Students' achievements

by 문종현

https://youtu.be/CtUlfx7citM?si=PlCtiVuuPn6u5zfm
https://youtu.be/CtUlfx7citM?si=odse3BkoKFGHqf1E
https://youtu.be/dN4kq8P6NUw?si=vQFGzavR_RTMRHCY

by apple_tree
https://youtu.be/qRTFE24HJog?si=sZ0GpkY-uVJ1I3Ik

by 두두
https://youtu.be/ntbjqhkzIsg?si=PIqKwzLvA8EoaTt8
https://youtu.be/W47sjXk10Gs?si=QlukRJZMo0HbBDKm

by Gyuseob Choi
https://youtu.be/SfsFDs0deLY?si=sQBWvtbnEh6AKAHz

by HY's Embedded LAB
https://youtu.be/nBKHbC1idSg?si=ADbVrwXJVXKICirr

Course description

※ This course has been dubbed in Korean and supports English subtitles. Auto-translation is available.

※ This course consists of 51 sessions, 12 chapters, divided into 3 parts. (Total 31 hours)
※ All text in the course materials have been written
in Korean.

Do you want to build your own high-performance drone flight controller?

Do you want to add specific features to your drone?

Is the architecture of drone open source such as ArduPilot or PX4 too difficult to study?

→ Here is the easiest way in the world to develop your own drone firmware!

→ You can build a high-performance drone flight control system based on 32-bit ARM Cortex-M microcontrollers with this course from very scratch!!

In this course, all source code and hardware assembly is explained step by step so that even non-majors, entry level engineers and students can easily follow this course. If you follow all of this course, you can make your own high-performance drone.
Unlike other drone programming courses, this course focused on the embedded system development process with bare-metal firmware programming.

It is the easiest way to understand the process of a drone flight control system development because it implements all the features one by one without using open source.
Moreover, flight performance of the drone developed in this course is not inferior to that of commercial products such as Pixhawk or Ardupilot, so it can be applied to research or industrial applications beyond simple educational drones.

MH-FC V2.2 can be applied not only to drones but also to all moving unmanned systems such as a self-driving car!


To take this course, same drone parts as the course are required.

You can buy MH-FC V2.2  here and drone parts here.

You can also buy the drone parts by yourself. Check "Drone components list for M-HIVE online course.pdf" file here.

It is highly recommended to purchase the same products on the list.

(Note: If the parts are different, they may not work as course)

The course consists of 3 parts and 12 chapters. (51 sessions)

 

• Chapter 0. Course introduction


In Part 1. Flight control system basics
• Chapter 1. Setting up the development environment for STM32
• Chapter 2. Sensor interface
• Chapter 3. GPS data receiving and parsing
• Chapter 4. Transmit
ter and receiver, data receiving, decoding and parsing
• Chapter 5. Drone assembly
• Chapter 6. Driving BLDC motors


In Part2. Communication and additional features
• Chapter 7. Ad
ditional features - EEPROM, battery voltage checker, BNO080 calibration, gyro offset removal
• Chapter 8. Radio data communication (FC↔GCS)
• Chapter 9. Safety features - sensor connection check, throttle stick position check, Fail-safe motor stop, low battery alarm


Part 3. Flight Control based on PID Controllers
• Chapter 10. Preparations for PID control
• Chapter 11. Roll, pitch axis PID control (Double loop cascade PID control)
• Chapter 12. Heading control (Single loop PID control)

• Chapter 13. Course conclusion

In this course, STM32F405, a 32-bit ARM Cortex-M4 microcontroller, is used as a core processor, BNO080 9-axis and ICM-20602 6-axis sensor for attitude and heading measurement, the LPS22HH barometric pressure sensor for altitude measurement.

It also covers receiving u-blox M8N GPS data for outdoor autonomous flight. (However, altitude control and GPS position control are not covered in this course)

The purpose of this course is to develop a high-performance drone flight controller, but it explains embedded system development process in more depth.
This course explains from sensor interface, which is the most basic step for drone flight, to PID control for attitude control.
The process for developing embedded applications is intensively explained, and they are combined to complete the drone flight control system.

We will always do my best to provide informative video courses.

ChrisP

M-HIVE

What you'll learn

• 32-bit ARM Cortex-M4 STM32F4 based high-performance drone control system firmware programming
• How to configure peripherals, generate and build source code for STM32 with STM32CubeIDE and CubeMX
• Sensor interface, motor driving, radio data transmission, flight control and its all source code

• How to use STM32F4 HAL and LL driver (mainly LL used)
• Embedded system bare-metal firmware development process

• Self-made drone FC firmware development
• 9-axis (BNO080) and 6-axis (ICM-20602) sensor, barometric pressure sensor (LPS22HH) interface
• u-blox M8N interface and data parsing (UBX protocol message decoding)
• FlySky FS-iA6B receiver interface and data parsing, FS-i6 transmitter configuration (iBus protocol message decoding)
• How to setup a quadcoptor drone
• PWM generation using TIM peripheral of STM32

• ESC calibration and ESC protocols (Standard PWM, Oneshot, Multishot, Dshot)
• BLDC motor driving using Oneshot125 protocol
• 3DR telemetry configuration
• Transmission and reception of drone status information (sensor data, FS-i6 transmitter data, battery voltage, PID control gain, etc.)
• Additional features - storing PID gains in EEPROM, battery voltage checker and low battery alarm
• Safety features - sensor connection check, throttle stick position check, Fail-safe motor stop
• Drone flight control technique - PID control in self-leveling mode
• Single loop PID control theory and experiment
• Double loop PID (Cascade PID) control theory and experiment

Who is this course for?

• Those who want to implement the entire drone control system step by step, from sensor interface to the flight control

• Those who want to develop embedded application using STM32

• Those who want to study autonomous vehicle system

• Those who want to build your own flight controller

• Students majoring in electronics, communications, controls, mechanics, and dynamics

• Those who want to experience the embedded system development process

• Engineers who want to learn sensor interface and various message protocols such as UBX, iBus(similar with S-Bus)

• Those who want to jump up from Arduino or 8-bit MCU to 32-bit MCU

• Those who want to learn the basic principles of PID control and implement PID controllers

• Those who want to practice high-level embedded system projects

• Drone-related research institutes and educational institutions

• Those who are working on projects related to unmanned vehicles

Course contents (51 sessions and 12 chapters)

(Click session titles to see each session detail on YouTube)

Course overview

Course introduction
(Introduction to the course structure and hardware parts)
0-1. Course in
troduction and hardware parts
0-2. Contents introduction and install STM32CubeIDE

Part 1. Flight control system basics


Chapter 1. Setting up the development environment for STM32
(Building a debug environment for STM32F4 development.)
1-1. Blink debug LED (GPIO)
1-2. Generating tone with a buzzer (
TIM-PWM)
1-3. Communicat
ion with PC (UART)

Chapter 2. Sensor interface
(Receiving data from the BNO080 9DOF, ICM-20602 6DOF, and LPS22HH barometric pressure sensor used for flight control and verifying it with serial plotter.)
2-1. BNO080 9-axis sensor (3-axis rotation angle, SPI)
2-2. ICM-20602 6-axis sensor (3-axis gyro, SPI)
2-3. LPS22HH barom
etric pressure sensor (Barometric altitude, SPI)

Chapter 3. GPS data receiving and parsing
(Setting up u-blox M8N GNSS module (using u-center), receiving data (UBX p
rotocol) and verifying latitude and longitude information.)
3-1. u-blox M8N GPS NMEA data reception (UART)
3-2. M8N configurations and UBX message reception (using u-center)
3-3. UBX message structure analysis
3-4. UBX message receiving, decoding and parsing
3-5. Writing M8N configuration code

Chapter 4. Transmitter and receiver, data receiving, decoding and parsing
(Analyzing and decoding i-Bus data from Flysky's FS-i6 transmitter through the FS-iA6B receiver)
4-1. Flysky FS-i6 / iA6B setup i-Bus data reception
4-2. i-Bus protocol analysis and checksum verification
4-3. i-Bus message decoding and parsing
4-4. FS-i6 i-Bus Fail-safe
4-5. FS-i6X i-Bus Fail-safe (FS-i6X users must watch this!)

Chapter 5. Drone assembly
(Wiring, soldering and assembling the motors, ESCs, BEC, FC, receiver, etc, to the QAV210 drone frame)
5. Drone parts assembly

Chapter 6. Driving BLDC motors
(Learning various ESC protocols (Oneshot, Multishot, Dshot, etc.), generating Oneshot125 signal using TIM-PWM peripheral, and control motors.)
6-1. ESC protocols (Standard PWM, Oneshot, Multishot, Etc.)
6-2. Oneshot125 PWM generation
6-3. BLDC motor speed control and ESC calibration
6-4. Motor speed comparison and optional ESC calibration

Part 2. Communication and additional features

 

Chapter 7. Additional features
(Learning and implementing additi
onal features useful for drone flight control systems)
7-1. AT24C08 EEPROM R/W
7-2. EEPROM data management protocol
7-3. Battery voltage check and low battery alarm
7-4. BNO080 calibration
7-5. ICM-20602 gyro DC offset removal

Chapter 8. Radio data communication
(Defining and implementing wireless communication protocol between FC and GCS)
8-1. 3DR telemetry configuration and radio data communication
8-2. Introduction to the ground control station
8-3. FC ↔ GCS data communication protocol
8-4. FC data transmission: ID 0x10 AHRS data with delay (1/2)
8-4. FC data transmission: ID 0x10 AHRS data with timer (2/2)
8-5. FC data transmission: ID 0x11 GPS and FC status data
8-6. FC data transmission: ID 0x00 to 0x05 PID gain data
8-7. FC data reception: ID 0x00 to 0x05 PID gain setting data
8-8. FC data reception: ID 0x10 PID gain request data

Chapter 9. Safety features
(Implementing safety features to avoid accidents that may occur during booting time and flight)
9-1. Checking for sensor connection and PID gain load status
9-2. Checking for throttle and SWA when FC booting and arming
9-3. Fail-safe motor stop and low battery alarm

Introduction to a drone simulator - FPV FreeRider Recharged

Drone Flight Test with MH-FC V2.2 designed by M-HIVE


Part 3. Flight control based on PID controllers

 

Chapter 10. Preparations for PID control
(Preparing for flight control and learning about PID control theory)
10-1. Preparations for PID control
10-2. Single loop PID control - Theory (1/2)
10-2. Single loop PID control - Implementation (2/2)
10-3. Double loop cascade PID control - Theory (1/2)
10-3. Double loop cascade PID control - Implementation (2/2)

Chapter 11. Roll, pitch axis PID control (Cascade PID control)
(Implementing each of roll and pitch axis double loop cascade PID controller and experiment)
11. Roll and pitch axis double loop PID control

Chapter 12. Heading control (Single loop PID control)
(Implementing each of yaw angle controller and angular rate controller)
12-1. Yaw axis angular rate single loop PID control
12-2. Yaw axis heading angle single loop PID control

Chapter 13. Course conclusion - COMPLETED
(Hardware and software struc
ture review and course conclusion)
13-1. Conclusion (1/2) (H/W and S/W review, safety rules, and battery management tips)
13-2. Conclusion (2/2) (How to find drone zones, GPS assembly and altitude hold based on barometer demo)

Hardware / Drone parts

MH-FC V2_edited.jpg
MH-FC V2.2 flight controller QAV210 drone frame kit

MH-FC V2.2 specifications

• STM32F405R MCU (64LQFP, 32-bit ARM Cortex-M4, 168MHz, single-precision FPU)
• BNO080 9-axis sensor (gyro, acc, mag, ARM Cortex-M0+ running MotionEngine software)
• ICM-20602 6-axis sensor (gyro and acc)

• LPS22HH barometric pressure sensor (barometric altimeter)
• AT24C08 EEPROM (data storage for PID gain)
• LEDs for power indicator and firmware debug
• Buzzer for FC state indicator and firmware debug
• Built-in battery voltage checker circuit

• Dimensions(mm): W36 x D36 x H15mm (Height including connectors and a buzzer)
• PCB thickness: 1.2mm
• Weight: 6g (only FC)
 Input voltage: Vin: 5V (FC power supply), VBAT: 12.6V MAX (battery voltage measurement)

See detail

Drone parts

• MH-FC V2.2

• ST-LINK V2 fimware downloader/debugger

 USB to UART

• QAV210 frame kit

• MATEK PDB XT-60 BEC 3-4S 5V 12V output

• READYTOSKY MT2204 2300kV BLDC motor CW x 2 CCW x 2

• LITTLEBEE BLHeli_s 2-6S 30A ESC Multishot Oneshot support

• 5045 3 blades propeller CW x 2 CCW x 2 (orange, green)

• Anti vibration standoff and rubber ring x 4 each

• FLYSKY FS-i6 mode 2 (left throttle) transmitter / FS-iA6B receiver

• u-blox M8N GPS module with a holder

• HOLYBRO radio telemetry 100mW 433MHz or 915MHz pair

• 5inch propeller guard x 4 (orange or red, green)

• INFINITY 1500mAh 3S LIPO battery XT-60 30C

See detail

STM32 drone programming from scratch course complete package
KakaoTalk_20230924_003050966_10.jpg

What are the requirements or prerequisites for taking your course?

• MH-FC V2.2 flight controller is needed!! If you don't have it, you can't proceed! You can buy it here.
• Drone parts are also needed. You can buy them here or yourself. Check "Drone components list for M-HIVE online course.pdf" file here. It is highly recommended to purchase the same products on the list.
(Note: If the parts are different, they may not work as course)
• Windows PC and STM32CubeIDE. (macOS and Linux supported)
• C programming language novi
ce or intermediate level required. (But entry level OK)
• STM32 or any
microcontrollers development experience required.
• Basic circuit knowledge required. (But not essential)

• Soldering experience required.

Welcome Message

Hello I'm ChrisP.

Thank you for joining our course.

Drone development is really dangerous project, so you must keep your safety very carefully. In particular, there is a high probability of accidents in flight control parts that need to be experimented with propellers!!!! I hope you can safely complete the entire progress and have fun flight.

So, let's get started!

Congratulations Message (After complete the course)


Congratulations on completing all courses!

You did really good job!! It wouldn't have been easy to follow this course.

Now you have your own flight controller. With a little more study, you are able to add specific features you want. The features implemented in this course can be applied not only to drone but also to all other embedded applications. Therefore, please be sure to remember the contents of this course.

I hope this course was useful, helpful and informative to you to understand embedded system development process.

Then, have fun and safe flight.

 

ChrisP

M-HIVE

bottom of page