Compiling Betaflight/Cleanflight firmware for your multirotor

cleanflight betaflight custom firmware
Share:

About

In this tutorial, we’ll compile our own Cleanflight/Betaflight firmware. You might ask yourself why do I want to compile the firmware on my own instead of just using the already compiled .hex files from Cleanflight/Betaflight? Well if you are okay with the original firmware you might as well use the precompiled files. But what if you want to add/remove some features or write some of your own code? You can do that by modifying the source code, which you then have to compile into a .hex file.

You will need Linux to compile the firmware. In this post, I will only cover the compilation part. If you would like to know how to set up Linux on Windows check out this post and you if want to know how to add/remove features from  Cleanflight/Betaflight then check out this one.

Firmware Compilation

First, open up the terminal. The GCC(compiler) should already be installed, but you can check using the following command.
  1. arm-none-eabi-gcc --version
If GCC is not installed, install it by using this command.
  1. sudo apt-get install gcc-arm-none-eabi

Next, let’s get the files from Github.

Cleanflight repo. https://github.com/cleanflight/cleanflight.git
Betaflight repo. https://github.com/betaflight/betaflight.git

Using the cd command move wherever you want the files to be downloaded to. Then download them using git.

  1. cd /home/"yourusername"/
  2. git clone https://github.com/cleanflight/cleanflight.git
Move them into the newly created folder.
  1. cd cleanflight
Try to compile.  Set the target to whatever board you are compiling the firmware for.
  1. make TARGET=NAZE //or TARGET="any other board"

You might get the following error:

make/tools.mk:296: *** **ERROR** your arm-none-eabigcc is ‘4.9.3’, but ‘6.3.1’ is expected. Override with ‘GCC_REQUIRED_VERSION’ in make/local.mk or run ‘make arm_sdk_install’ to install the right version automatically in the tools folder of this repo. Stop.

More about the error.

https://github.com/cleanflight/cleanflight/issues/2791
https://github.com/betaflight/betaflight/issues/1424

If you do indeed get the error do the following to fix it.

  1. make arm_sdk_install
Retry make.
  1. make TARGET=NAZE
Some messages about missing python might appear. If so let’s install python…. just to be sure.
  1. sudo apt-get install python
Clean the previous make.
  1. make clean TARGET=NAZE
  2. //or just
  3. make clean
Make again.
  1. make TARGET=NAZE
Data about the build is given at the end of the compilation after running make.

Moded or custom build flash size(text+data) is recommended to be kept smaller than the original build.
Same goes for (static)RAM usage(data+bss).

Source: https://github.com/cleanflight/cleanflight/blob/master/docs/Customized%20Version.md

Firmware .HEX file is now located in the obj folder. If you are using ubuntu subsystem in Windows 10, do the following to get .hex file to your windows desktop.
  1. cp obj/cleanflight_2.5.0_NAZE.hex /mnt/c/Users/"Username"/Desktop/
Or you could just use file explorer to access it.(not recommended by Microsoft)
  1. C:\Users\"Windows User"\AppData\Local\lxss\home\"Linux User"\cleanflight\obj
In Cleanflight choose the .hex file you just compiled and flash it.
In this tutorial, we only compiled the firmware. If you want to know how to modify it by adding/removing features check out this post I made.
Share:

Comments

  1. Hi thanks for your great tutorial.
    I’m in preliminary research for a project and need some guidance.
    I want to use an NAZE32 module and Cleanflight to build a quadcopter with the feature that it has wheels and motors for moving on the ground. Is it possible to modify the Cleanflight code so that this module can handle the device in two ways? (Switch between flight mode and ground motion)

    1. It should be possible but it would require a lot of effort as you would have to get familiar with the Cleanflight source code. What I think would be easier is to make a separate controller for the ground part and then switch between the two. You would send the pitch, yaw, roll, throttle and arming signals to both. But you would enable the ground controller when the flight controller was disarmed and disable it when the flight controller would be armed. When the ground controller would be enabled it would translate the pitch, yaw, roll, throttle signals into PWM signals for the wheel motors.

Leave a Reply

Your email address will not be published.

The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger