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.