Common_pre.h - GaloisInc/betaflight GitHub Wiki

Purpose of this document

This document is meant to describe the purpose of and the content found within common_pre.h. Common_pre.h is located as a standalone file at the bottom of src/main/target.

common_pre.h

This is the first file where developers can specify which features are activated for a flight controller. Common_pre.h specifies the features enabled depending on the memory flash size of the flight controller, and several other conditions. Features are enabled by defining certain flags (macros). These flags are then checked throughout the Betaflight code base to control the flow of program execution.

For example: if the flag USE_SERIALRX_IBUS is defined, Betaflight will execute a specific section of code; but if USE_SERIALRX_SBUS is defined, Betaflight will execute another section of code. The feature flags are a way to organize which parts of the code get run.

The first interesting part is where common_pre.h specifies the features that get activated for all flight controllers. For example:

#define USE_CLI
#define USE_PPM
#define USE_PWM
#define SERIAL_RX
#define USE_SERIALRX_CRSF       // Team Black Sheep Crossfire protocol
#define USE_SERIALRX_IBUS       // FlySky and Turnigy receivers
#define USE_SERIALRX_SBUS       // Frsky and Futaba receivers
#define USE_SERIALRX_SPEKTRUM   // SRXL, DSM2 and DSMX protocol
#define USE_SERIALRX_SUMD       // Graupner Hott protocol
#define USE_SERIALRX_SUMH       // Graupner legacy protocol
#define USE_SERIALRX_XBUS       // JR

The next part are features enabled if your memory flash size is bigger than 64 megabits:

#if (FLASH_SIZE > 64)
#define BLACKBOX
#define LED_STRIP
#define TELEMETRY
#define TELEMETRY_FRSKY
#define TELEMETRY_HOTT
#define TELEMETRY_LTM
#define TELEMETRY_SMARTPORT
#define USE_RESOURCE_MGMT
#define USE_SERVOS
#endif

And bigger than 128 megabits:

#if (FLASH_SIZE > 128)
#define GPS
#define CMS
#define TELEMETRY_CRSF
#define TELEMETRY_IBUS
#define TELEMETRY_JETIEXBUS
#define TELEMETRY_MAVLINK
#define TELEMETRY_SRXL
#define USE_DASHBOARD
#define USE_MSP_DISPLAYPORT
#define USE_RX_MSP
#define USE_SERIALRX_JETIEXBUS
#define USE_SENSOR_NAMES
#define VTX_COMMON
#define VTX_CONTROL
#define VTX_SMARTAUDIO
#define VTX_TRAMP
#endif

Feature flags can also be activated based on the computing capacity of the flight controller, or the model of the processor. For example:

#ifdef STM32H7
#define USE_ITCM_RAM
#define USE_FAST_RAM
#define USE_DSHOT
#define USE_DSHOT_TELEMETRY
#define USE_DSHOT_TELEMETRY_STATS
#define USE_RPM_FILTER
#define USE_DYN_IDLE
#define USE_GYRO_DATA_ANALYSE
#define USE_ADC_INTERNAL
#define USE_USB_CDC_HID
#define USE_DMA_SPEC
#define USE_TIMER_MGMT
#define USE_PERSISTENT_OBJECTS
#define USE_DMA_RAM
#endif

Note: As per the instruction of Betaflight devs, this file should not be modified. But it's useful to see what features you can activate or deactivate in your custom build.

However, there is a file where developers may enable more flags or disable flags enabled in common_pre.h. This can be done within the target’s unique target.h file, located in src/main/target/<Target_Flight_Controller>/target.h. For more details about target.h please refer to the target.h document.