Skip to content

Firmware

Now that your environment is ready, it’s time to get your hands dirty with the drone’s code.

In this section, you will learn how to download, configure, and compile the firmware that runs on the Crazyflie, getting everything ready to test your own code on the real drone.


Visual Studio Code

We will use Visual Studio Code as our IDE.

  1. Download and install Visual Studio Code from its official website.

Repository

Before you start programming, we need to bring the firmware code to your machine. We’ll do this in two steps: first, you create a copy (fork) of the repository, and then you donwload (clone) that copy to your computer.

Fork

  1. Create a fork of the repository that contains the firmware into your GitHub account.

Clone

  1. Open Visual Studio Code.

  2. Open a terminal window by clicking Terminal > New Terminal(1).

    1. You can also use the shortcut Ctrl + Shift + '.

    Important

    If you are using Windows, Visual Studio Code opens a PowerShell terminal by default. You must initialize the WSL terminal first:

    wsl
    

  3. Clone your forked repository and initialize all Git submodules(1):

    1. Git submodules are like “repositories inside repositories”, and they are initialize with the the --recursive flag.
    git clone --recursive https://github.com/username/quadcontrol-firmware.git
    

    Important

    You must replace username with your GitHub username.

  4. Open the project folder by clicking File > Open Folder....

Structure

The repository is composed of two folders and two files:

Firmware

Let’s take a closer look at each one:

  • crazyflie-firmware – Folder that contains the Crazyflie firmware, which we use as a submodule
  • src – Folder that contains the programs we will develop throughout the course
  • Kbuild – File that defines which program will be compiled
  • radio.config – File that defines the radio channel used to communicate with the Crazyflie

The src folder contains a subfolder called examples with two example programs: led_blink.c and hello_world.c. Open these files to see some very simple example programs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include "FreeRTOS.h"      // FreeRTOS core definitions (needed for task handling and timing)
#include "task.h"          // FreeRTOS task functions (e.g., vTaskDelay)
#include "led.h"           // LED functions (e.g., ledSet)

// Main application loop
void appMain(void *param)
{
    // Infinite loop (runs continuously while the quadcopter is powered on)
    while (true)
    {
        // Turn on left green led
        ledSet(LED_GREEN_L, true);
        // Wait for 100 milliseconds (2 Hz loop)
        vTaskDelay(pdMS_TO_TICKS(500));
        // Turn off left green led
        ledSet(LED_GREEN_L, false);
        // Wait for 100 milliseconds (2 Hz loop)
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include "FreeRTOS.h"      // FreeRTOS core definitions (needed for task handling and timing)
#include "task.h"          // FreeRTOS task functions (e.g., vTaskDelay)
#include "debug.h"         // Debug printing functions (e.g., DEBUG_PRINT)

// Main application loop
void appMain(void *param)
{
    // Infinite loop (runs continuously while the quadcopter is powered on)
    while (true)
    {
        // Print message to console
        DEBUG_PRINT("Hello world!\n");
        // Wait for 100 milliseconds (2 Hz loop)
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}

We define which program will be compiled through the Kbuild file:

Kbuild
1
obj-y += src/examples/led_blink.o

As we develop new programs, don’t forget to update the Kbuild file with the name of the program you want to compile.

Important

Note that the file extension here is .o, not .c. What matters is that the program name matches exactly.


Configure

Now that you have the firmware on your machine, let’s adjust some important configurations. These settings ensure everything is properly aligned with your Crazyflie before compiling the code.

Radio Channel

  1. Open the radio.config file.

  2. Change the radio channel according to your Crazyflie configuration:

    radio.config
    1
    RADIO_CHANNEL=1
    

Bypass the Stabilizer

  1. Navigate to crazyflie-firmware/src/modules/src and open the stabilizer.c file.

  2. Comment out lines 223–226, 326, and 356, as shown below(1):

    1. We do this to bypass the proprietary Crazyflie control algorithm. It will continue running in the background, but its commands will be ignored so that we can use our own control logic.
    stabilizer.c
    
    

    221
    222
    223
    224
    225
    226
    227
    static void setMotorRatios(const motors_thrust_pwm_t* motorPwm)
    {
    // motorsSetRatio(MOTOR_M1, motorPwm->motors.m1);
    // motorsSetRatio(MOTOR_M2, motorPwm->motors.m2);
    // motorsSetRatio(MOTOR_M3, motorPwm->motors.m3);
    // motorsSetRatio(MOTOR_M4, motorPwm->motors.m4);
    }
    
    326
        //stateEstimator(&state, stabilizerStep);
    
    355
    356
    357
        } else {
            // motorsStop();
        }
    

Select the Hardware Platform

  1. Configure the firmware for the Crazyflie 2.1 Brushless platform by running the following command in the terminal:

    make cf21bl_defconfig
    

Compile and Upload

With the firmware properly configured, it’s time to turn it into something the drone can understand. We will compile and upload it to the Crazyflie. This process will be repeated every time you want to test a new version of your program.

Build

  1. Compile the firmware:
    make
    

Flash

  1. Upload the firmware to the Crazyflie:

    make cload
    

    Important

    • The Crazyflie 2.1 Brushless must be powered on
    • The Crazyradio PA must be connected to a USB port

Connect and Test

All set! Now let’s connect to the drone using the Crazyflie Client and verify that your code is running correctly. If everything is working as expected, you’ll see messages appearing in the console — and your drone will officially be under your control.

  1. Open the Crazyflie Client:

    cfclient
    

    Important

    If you are using Windows, this is the only command that must be run in PowerShell terminal instead of WSL.

  2. Click on Scan button

  3. Select the corresponding Crazyflie.

  4. Click on Connect button

  5. Verify that the quadcopter is responding (battery voltage, sensor status, etc.).

  6. Click on View > Toolboxes > Console

  7. Check whether messages from your code appear (for example, "Hello world!").

If no messages appear, you are most likely still running the led_blink.c program instead of hello_world.c. Update your Kbuild file to point to the correct program, then recompile and flash the firmware again.