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
arm-none-eabi-gcc --version
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.
cd /home/"yourusername"/ git clone https://github.com/cleanflight/cleanflight.git
cd cleanflight
make TARGET=NAZE //or TARGET="any other board"
You might get the following error:
make/tools.mk:296: *** **ERROR** your arm-none-eabi–gcc 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.
make arm_sdk_install
make TARGET=NAZE
sudo apt-get install python
make clean TARGET=NAZE //or just make clean
make TARGET=NAZE
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
cp obj/cleanflight_2.5.0_NAZE.hex /mnt/c/Users/"Username"/Desktop/
C:\Users\"Windows User"\AppData\Local\lxss\home\"Linux User"\cleanflight\obj
What if cleanflight does not link (elf is 657 bytes bigger than Flash) for NAZE target?
Hi. If the file is 657 bytes bigger than the original file(the one before your modification) it’s probably ok.
However, if it is 657 bytes bigger than the flash memory size of the microcontroller on the NAZE board that’s a problem as all the code can’t be uploaded. To fix it you just have to remove some features to free up some space.
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)
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.