src directory - GaloisInc/betaflight GitHub Wiki

Intro

This document is meant to describe the directories in src.There are four sub-folders :

src/link

This directory contains linker scripts (.ld files) for each of the micro controller models supported by Betaflight. These linker scripts describe the location and size of blocks of memory in the target. They can be used to describe which memory regions may be used by the linker, and which memory regions it must avoid. This is also where we have placed the linker script for the K210 (riscv_flash_k210.ld). More on linker scripts here : Linker Scripts

src/test

Contains Betaflight’s unit tests.

src/utils

Contains dfuse-pack python utility . Dfu-util - Device Firmware Upgrade Utilities. DFU is intended to download and upload firmware to devices connected over USB. More on that here : dfu-util

src/main

Betaflight’s primary code related to drivers,peripherals and setup. It is probably the folder that developers will visit most often to add, remove and configure.

  • src/main/config: Contains source code for initial configuration of the flight controller. Much of this code is run directly after the flight controller is powered up, and handles initialization of configuration settings prior to flight. Several key files are:

    • Config.c - general configuration

    • Config_eeprom.c - sets up an "EEPROM" abstraction that get written/read to/from flash

    • Config_streamer.c - primarily writing the configurations to flash and verifying the CRC checks

  • src/main/drivers: Contains source code for all of Betaflight’s drivers, including software and peripheral hardware drivers.

  • src/main/fc: Short for ‘flight controller’, this folder contains flight-critical code responsible for keeping the drone airborne. A key file within this folder is init.c, which is responsible for the flight controller’s boot procedure.

  • src/main/pg: Short for ‘parameter groups’, this folder contains code for each of Betaflight’s ‘parameter groups’. Parameter groups is a data structure in Betaflight to store (and at a later point transfer) firmware configuration data.” For more details see parametergroup.md.

  • src/main/startup: Contains startup (.s) files for Betaflight-supported microcontrollers. These are files used to boot the microcontroller, and put it into the correct state for program execution. startup_riscv_k210.s, found at the top of the folder, is the startup file for the K210 microcontroller. Generally, developers shouldn’t need to alter anything in the startup files, these are written and provided by the manufacturer.

  • src/main/target/<TARGET>: This is another folder developers will visit quite often. Within this folder there is a sub-folder for each flight control board (AKA flight controller) that is supported by Betaflight. We created the ‘MAIXBIT’ folder for our RISC-V board. Within each board’s folder there are (at least) the same three files:

Visit the hyperlinks above for more details about each.

Also, at the bottom of the ‘target’ folder there is a file called ‘common_pre.h’. This file is used to set certain flags based on enabled features within Betaflight. The file provides a standard list of features to Betaflight, which will then be included in the final executable. For more information see the common_pre.h document.

  • src/main/main.c: Program execution begins on board power-up, and where it stays until the board is powered down.

  • src/main/platform.h: This is another important standalone file. Platform.h is responsible for including microcontroller model-specific driver header files. These files are needed to boot model-specific microcontroller peripherals such as SPI, GPIO, DMA, etc. Without these files, the microcontroller would be pretty useless.

⚠️ **GitHub.com Fallback** ⚠️