130mm quad with simple C++ firmware, Part II: The firmware

This is a follow-up to yesterday's post.  As promised, I wanted to provide some information about the C++ firmware running on this little quadcopter.

Following in the Baseflight / Cleanflight / Raceflight / Betaflight naming tradition of the 32-bit Multwii lineage, I call this firmware "Hackflight".  Hackflight is simple C++ firmware for inexpensive quadcopter flight controllers. It is geared toward people like me who want to tinker with flight-control firmware, and use it to teach students about ideas like inertial measurement and PID tuning. 

If you are in the 99% percent of users who just want to get your vehicle flying without getting into firmware hacking, I would stay away from Hackflight. Go with Cleanflight (great for getting started when you're on a budget) or the Ardupilot suite (the gold standard for sophisticated mission planning with waypoint navigation and the like). In addition to big user communities and loads of great features, these platforms have safety mechanisms that Hackflight lacks, which will help avoid injury to you and damage to your vehicle.

Hackflight currently works only on STM32F103 flight-controller boards (Naze32 and clones like Flip32, MultiRC, etc.) The original Hackflight idea was to write firmware for flight controllers built from the Arduino / Teensy hardware. As you'll see, the code follows the Arduino design pattern of a startup() routine that calls the init() method of a few objects (IMURCPIDBoard) and a loop routine that calls the update() method and other methods of those objects. But with all the features you can now get onboard an inexpensive STM32F103 board (barometer, magnetometer, flash RAM), there seems little point in building your own board, unless you're interested in hardware hacking. So Hackflight currently supports only the STM32F103 boards, while keeping the Arduino design principles. The code provides abstraction (through the Board class) that should make it easy to use on other boards.

For more info and download, see the github repository.

Views: 2968

Comment by Georacer on May 18, 2016 at 12:41am

Hello Simon,

Are there any resources or bits of information on the compilation toolchain and the flashing procedure of the board?

Comment by Phillip Schmidt on May 18, 2016 at 7:23am

Very cool... I really need to get back to work on my bare bones quad control software.  It functions well already but needs some cleaning up before I put it on my github.  And now I want build a little quad like.

Comment by Simon D. Levy on May 18, 2016 at 12:26pm

@Georacer: Take a look at the instructions on the repository, if you haven't already.  I'm just using the GNU ARM toolchain with a makefile.  "make flash" does it all: compiles the source into object code, links the object code into an ELF binary, converts the ELF to HEX, flashes the HEX to the board.  I tried the Windows-based toolchain (Keil, Eclipse, etc.) a few months ago, but found it way too complicated for my needs.  So stick to Linux-based tools: gcc / make / vim.  I'm still a newbie at STM32 hacking, so my understanding doesn't go much deeper than that ;^)

Comment by Georacer on May 18, 2016 at 2:12pm

That's exactly what I asked for. Thanks!

Comment by Fouad on December 26, 2018 at 1:52am

Nice work.

Do you still have the initial version that was intended to run on the teensy ? I was thinking of utilizing it for as a starting point for a rover rc car controller?

Comment by Simon D. Levy on January 6, 2019 at 1:04am

Thanks, Fouad!  The current firmware runs on Arduino-based boards.  Instead of Teensy, I'd recommend using an STM32L4-based board, like the Butterfly from Tlera Corp., so you can get both Arduino compatibility and floating-point co-processing. Check out the new build wiki to see how to set it up.  


You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2020   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service