2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
23 #include "build/version.h"
27 The purpose of this file is to enable / disable any firmware "gates" for features and drivers
28 that require hardware resources that are either available or not available after the target.h
31 It should also be used to define anything that should be defined (and is required), but is not
32 already, to some sort of defaults.
34 CLOUD_BUILD and CORE_BUILD should not be referenced here.
36 NOTE: for 4.5 we will be removing any conditions related to specific MCU types, instead
37 these should be defined in the target.h or in a file that is imported by target.h (in the
38 case of common settings for a given MCU group)
42 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
43 #define DEFAULT_AUX_CHANNEL_COUNT MAX_AUX_CHANNEL_COUNT
45 #define DEFAULT_AUX_CHANNEL_COUNT 6
49 #if defined(ITCM_RAM_OPTIMISATION) && !defined(DEBUG)
50 #define FAST_CODE __attribute__((section(".tcm_code"))) __attribute__((optimize(ITCM_RAM_OPTIMISATION)))
52 #define FAST_CODE __attribute__((section(".tcm_code")))
54 // Handle case where we'd prefer code to be in ITCM, but it won't fit on the F745
56 #define FAST_CODE_PREF
58 #define FAST_CODE_PREF __attribute__((section(".tcm_code")))
60 #define FAST_CODE_NOINLINE NOINLINE
63 #define FAST_CODE_PREF
64 #define FAST_CODE_NOINLINE
65 #endif // USE_ITCM_RAM
68 #define CCM_CODE __attribute__((section(".ccm_code")))
74 #define FAST_DATA_ZERO_INIT __attribute__ ((section(".fastram_bss"), aligned(4)))
75 #define FAST_DATA __attribute__ ((section(".fastram_data"), aligned(4)))
77 #define FAST_DATA_ZERO_INIT
79 #endif // USE_FAST_DATA
82 BEGIN HARDWARE INCLUSIONS
84 Simplified options for the moment, i.e. adding USE_MAG or USE_BARO and the entire driver suite is added.
85 In the future we can move to specific drivers being added only - to save flash space.
88 #if defined(USE_MAG) && !defined(USE_FAKE_MAG)
89 #define USE_MAG_DATA_READY_SIGNAL
90 #define USE_MAG_HMC5883
91 #define USE_MAG_SPI_HMC5883
92 #define USE_MAG_QMC5883
93 #define USE_MAG_LIS3MDL
94 #define USE_MAG_AK8963
95 #define USE_MAG_MPU925X_AK8963
96 #define USE_MAG_SPI_AK8963
97 #define USE_MAG_AK8975
100 #if defined(USE_RX_CC2500)
102 #if !defined(USE_RX_SPI)
106 #define USE_RX_CC2500_SPI_PA_LNA
107 #define USE_RX_CC2500_SPI_DIVERSITY
109 #define USE_RX_SFHSS_SPI
110 #define USE_RX_REDPINE_SPI
112 #define USE_RX_FRSKY_SPI_D
113 #define USE_RX_FRSKY_SPI_X
114 #define USE_RX_FRSKY_SPI
115 #define USE_RX_FRSKY_SPI_TELEMETRY
117 #define USE_RX_FLYSKY
118 #define USE_RX_FLYSKY_SPI_LED
119 #define USE_RX_SPEKTRUM
120 #define USE_RX_SPEKTRUM_TELEMETRY
122 #endif // defined(USE_RX_CC2500)
124 /* END HARDWARE INCLUSIONS */
126 #if defined(USE_VTX_RTC6705_SOFTSPI)
127 #define USE_VTX_RTC6705
131 #undef USE_ESC_SENSOR
134 #ifndef USE_ESC_SENSOR
135 #undef USE_ESC_SENSOR_TELEMETRY
138 // XXX Followup implicit dependencies among DASHBOARD, display_xxx and USE_I2C.
139 // XXX This should eventually be cleaned up.
141 #undef USE_I2C_OLED_DISPLAY
145 #define USE_I2C_OLED_DISPLAY
149 // Remove USE_BARO_BMP280 and USE_BARO_MS5611 if USE_I2C is not defined.
150 #if !defined(USE_I2C)
151 #if defined(USE_BARO_BMP280)
152 #undef USE_BARO_BMP280
154 #if defined(USE_BARO_MS5611)
155 #undef USE_BARO_MS5611
159 // Add VARIO if BARO or GPS is defined. Remove when none defined.
160 #if defined(USE_BARO) || defined(USE_GPS)
168 #if defined(USE_BARO) && !defined(BARO_EOC_PIN)
169 #define BARO_EOC_PIN NONE
172 #if !defined(USE_SERIALRX)
173 #undef USE_SERIALRX_CRSF
174 #undef USE_SERIALRX_IBUS
175 #undef USE_SERIALRX_JETIEXBUS
176 #undef USE_SERIALRX_SBUS
177 #undef USE_SERIALRX_SPEKTRUM
178 #undef USE_SERIALRX_SUMD
179 #undef USE_SERIALRX_SUMH
180 #undef USE_SERIALRX_XBUS
181 #undef USE_SERIALRX_FPORT
184 #if !defined(USE_TELEMETRY)
185 #undef USE_TELEMETRY_CRSF
186 #undef USE_TELEMETRY_GHST
187 #undef USE_TELEMETRY_FRSKY_HUB
188 #undef USE_TELEMETRY_HOTT
189 #undef USE_TELEMETRY_IBUS
190 #undef USE_TELEMETRY_IBUS_EXTENDED
191 #undef USE_TELEMETRY_JETIEXBUS
192 #undef USE_TELEMETRY_LTM
193 #undef USE_TELEMETRY_MAVLINK
194 #undef USE_TELEMETRY_SMARTPORT
195 #undef USE_TELEMETRY_SRXL
197 #ifdef USE_SERIALRX_FPORT
198 #ifndef USE_TELEMETRY
199 #define USE_TELEMETRY
201 #ifndef USE_TELEMETRY_SMARTPORT
202 #define USE_TELEMETRY_SMARTPORT
207 #if !defined(USE_SERIALRX_CRSF)
208 #undef USE_TELEMETRY_CRSF
209 #undef USE_CRSF_LINK_STATISTICS
213 #if !defined(USE_RX_EXPRESSLRS) && !defined(USE_SERIALRX_CRSF)
214 #undef USE_RX_RSSI_DBM
217 #if !defined(USE_SERIALRX_GHST)
218 #undef USE_TELEMETRY_GHST
221 #if !defined(USE_TELEMETRY_CRSF) || !defined(USE_CMS)
222 #undef USE_CRSF_CMS_TELEMETRY
225 #if !defined(USE_TELEMETRY_CRSF)
229 #if !defined(USE_SERIALRX_JETIEXBUS)
230 #undef USE_TELEMETRY_JETIEXBUS
233 #if !defined(USE_TELEMETRY_IBUS)
234 #undef USE_TELEMETRY_IBUS_EXTENDED
237 // If USE_SERIALRX_SPEKTRUM was dropped by a target, drop all related options
238 #ifndef USE_SERIALRX_SPEKTRUM
239 #undef USE_SPEKTRUM_BIND
240 #undef USE_SPEKTRUM_BIND_PLUG
241 #undef USE_SPEKTRUM_REAL_RSSI
242 #undef USE_SPEKTRUM_FAKE_RSSI
243 #undef USE_SPEKTRUM_RSSI_PERCENT_CONVERSION
244 #undef USE_SPEKTRUM_VTX_CONTROL
245 #undef USE_SPEKTRUM_VTX_TELEMETRY
246 #undef USE_TELEMETRY_SRXL
249 #if !defined(USE_CMS) || !defined(USE_TELEMETRY_SRXL)
250 #undef USE_SPEKTRUM_CMS_TELEMETRY
253 #if defined(USE_SERIALRX_SBUS) || defined(USE_SERIALRX_FPORT)
254 #define USE_SBUS_CHANNELS
257 #if !defined(USE_TELEMETRY_SMARTPORT) && !defined(USE_TELEMETRY_CRSF) && !defined(USE_TELEMETRY_GHST)
258 #undef USE_MSP_OVER_TELEMETRY
261 #if !defined(USE_RX_MSP) && defined(USE_RX_MSP_OVERRIDE)
262 #undef USE_RX_MSP_OVERRIDE
265 /* If either VTX_CONTROL or VTX_COMMON is undefined then remove common code and device drivers */
266 #if !defined(USE_VTX_COMMON) || !defined(USE_VTX_CONTROL)
267 #undef USE_VTX_COMMON
268 #undef USE_VTX_CONTROL
270 #undef USE_VTX_SMARTAUDIO
275 // Burst dshot to default off if not configured explicitly by target
276 #ifndef ENABLE_DSHOT_DMAR
277 #define ENABLE_DSHOT_DMAR DSHOT_DMAR_OFF
280 // Some target doesn't define USE_ADC which USE_ADC_INTERNAL depends on
282 #undef USE_ADC_INTERNAL
286 #define USE_FLASH_TOOLS
290 #if (defined(USE_FLASH_W25M512) || defined(USE_FLASH_W25Q128FV)) && !defined(USE_FLASH_M25P16)
291 #define USE_FLASH_M25P16
294 #if defined(USE_FLASH_W25M02G) && !defined(USE_FLASH_W25N01G)
295 #define USE_FLASH_W25N01G
298 #if (defined(USE_FLASH_M25P16) || defined(USE_FLASH_W25N01G)) && !defined(USE_FLASH_W25M)
299 #define USE_FLASH_W25M
302 #if defined(USE_FLASH_M25P16) || defined(USE_FLASH_W25M) || defined(USE_FLASH_W25N01G) || defined(USE_FLASH_W25Q128FV)
303 #define USE_FLASH_CHIP
306 #if defined(USE_SPI) && (defined(USE_FLASH_M25P16) || defined(USE_FLASH_W25M512) || defined(USE_FLASH_W25N01G) || defined(USE_FLASH_W25M02G))
307 #define USE_FLASH_SPI
310 #if defined(USE_QUADSPI) && (defined(USE_FLASH_W25Q128FV) || defined(USE_FLASH_W25N01G))
311 #define USE_FLASH_QUADSPI
314 #if defined(USE_OCTOSPI) && (defined(USE_FLASH_W25Q128FV))
315 #define USE_FLASH_OCTOSPI
318 #ifndef USE_FLASH_CHIP
319 #undef USE_FLASH_TOOLS
323 #if (!defined(USE_SDCARD) && !defined(USE_FLASHFS)) || !defined(USE_BLACKBOX)
327 #if !defined(USE_SDCARD)
328 #undef USE_SDCARD_SDIO
329 #undef USE_SDCARD_SPI
332 #if !defined(USE_VCP)
333 #undef USE_USB_CDC_HID
337 #if defined(USE_USB_CDC_HID) || defined(USE_USB_MSC)
338 #define USE_USB_ADVANCED_PROFILES
341 #if !defined(USE_OSD)
342 #undef USE_RX_LINK_QUALITY_INFO
343 #undef USE_OSD_PROFILES
344 #undef USE_OSD_STICK_OVERLAY
345 #undef USE_RX_LINK_UPLINK_POWER
348 // Older ACC/GYRO sensors use MPU6500 driver
349 #if !defined(USE_ACC_MPU6500) && (defined(USE_ACC_ICM20601) || defined(USE_ACC_ICM20602) || defined(USE_ACC_ICM20608G))
350 #define USE_ACC_MPU6500
352 #if !defined(USE_ACC_SPI_MPU6500) && (defined(USE_ACC_SPI_MPU9250) || defined(USE_ACC_SPI_ICM20601) || defined(USE_ACC_SPI_ICM20602) || defined(USE_ACC_SPI_ICM20608G))
353 #define USE_ACC_SPI_MPU6500
355 #if !defined(USE_GYRO_MPU6500) && (defined(USE_GYRO_ICM20601) || defined(USE_GYRO_ICM20602) || defined(USE_GYRO_ICM20608G))
356 #define USE_GYRO_MPU6500
358 #if !defined(USE_GYRO_SPI_MPU6500) && (defined(USE_GYRO_SPI_ICM20601) || defined(USE_GYRO_SPI_ICM20602) || defined(USE_GYRO_SPI_ICM20608G))
359 #define USE_GYRO_SPI_MPU6500
362 // Generate USE_SPI_GYRO or USE_I2C_GYRO
363 #if defined(USE_GYRO_L3G4200D) || defined(USE_GYRO_MPU3050) || defined(USE_GYRO_MPU6000) || defined(USE_GYRO_MPU6050) || defined(USE_GYRO_MPU6500)
367 #if defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_SPI_MPU6000) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU9250) || defined(USE_GYRO_L3GD20) || defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) || defined(USE_ACCGYRO_BMI270)
371 #ifndef SIMULATOR_BUILD
381 // CX10 is a special case of SPI RX which requires XN297
382 #if defined(USE_RX_CX10)
386 // Setup crystal frequency on F4 for backward compatibility
387 // Should be set to zero for generic targets to ensure USB is working
388 // when unconfigured for targets with non-standard crystal.
389 // Can be set at runtime with with CLI parameter 'system_hse_mhz'.
390 #ifndef SYSTEM_HSE_MHZ
391 #define SYSTEM_HSE_MHZ 0
394 // Number of pins that needs pre-init
396 #ifndef SPI_PREINIT_COUNT
397 // 2 x 8 (GYROx2, BARO, MAG, MAX, FLASHx2, RX)
398 #define SPI_PREINIT_COUNT 16
406 #if (!defined(USE_FLASHFS) || !defined(USE_RTC_TIME) || !defined(USE_USB_MSC) || !defined(USE_PERSISTENT_OBJECTS))
407 #undef USE_PERSISTENT_MSC_RTC
410 #if !defined(USE_SERIAL_4WAY_BLHELI_BOOTLOADER) && !defined(USE_SERIAL_4WAY_SK_BOOTLOADER)
411 #undef USE_SERIAL_4WAY_BLHELI_INTERFACE
412 #elif !defined(USE_SERIAL_4WAY_BLHELI_INTERFACE) && (defined(USE_SERIAL_4WAY_BLHELI_BOOTLOADER) || defined(USE_SERIAL_4WAY_SK_BOOTLOADER))
413 #ifndef USE_SERIAL_4WAY_BLHELI_INTERFACE
414 #define USE_SERIAL_4WAY_BLHELI_INTERFACE
418 #if defined(USE_RX_PWM) || defined(USE_DSHOT) || defined(USE_LED_STRIP) || defined(USE_TRANSPONDER) || defined(USE_BEEPER) || defined(USE_SERIAL_4WAY_BLHELI_INTERFACE)
419 #ifndef USE_PWM_OUTPUT
420 #define USE_PWM_OUTPUT
424 #if !defined(USE_LED_STRIP)
425 #undef USE_LED_STRIP_STATUS_MODE
428 #if defined(USE_MAX7456) || defined(USE_FRSKYOSD) || defined(USE_MSP_DISPLAYPORT)
429 #ifndef USE_VIDEO_SYSTEM
430 #define USE_VIDEO_SYSTEM
434 #if defined(USE_LED_STRIP) && !defined(USE_LED_STRIP_STATUS_MODE)
435 #define USE_WS2811_SINGLE_COLOUR
438 #if defined(SIMULATOR_BUILD) || defined(UNIT_TEST)
439 // This feature uses 'arm_math.h', which does not exist for x86.
440 #undef USE_DYN_NOTCH_FILTER
444 #undef USE_CMS_FAILSAFE_MENU
448 #undef USE_DSHOT_TELEMETRY
449 #undef USE_DSHOT_BITBANG
452 #ifndef USE_DSHOT_TELEMETRY
453 #undef USE_RPM_FILTER
454 #undef USE_DSHOT_TELEMETRY_STATS
457 #if !defined(USE_BOARD_INFO)
461 #if !defined(USE_ACC)
462 #undef USE_GPS_RESCUE
463 #undef USE_ACRO_TRAINER
466 #if (!defined(USE_GPS_RESCUE) || !defined(USE_CMS_FAILSAFE_MENU))
467 #undef USE_CMS_GPS_RESCUE_MENU
475 #if defined(USE_DMA_SPEC)
476 #define USE_TIMER_DMA
478 #undef USE_TIMER_MGMT
481 #if defined(USE_TIMER_MGMT)
485 #if !defined(USE_RANGEFINDER)
486 #undef USE_RANGEFINDER_HCSR04
487 #undef USE_RANGEFINDER_SRF10
488 #undef USE_RANGEFINDER_HCSR04_I2C
489 #undef USE_RANGEFINDER_VL53L0X
490 #undef USE_RANGEFINDER_UIB
491 #undef USE_RANGEFINDER_TF
494 #ifndef USE_GPS_RESCUE
495 #undef USE_CMS_GPS_RESCUE_MENU
498 // TODO: Remove this once HAL support is fixed for ESCSERIAL
503 #if defined(CONFIG_IN_RAM) || defined(CONFIG_IN_FILE) || defined(CONFIG_IN_EXTERNAL_FLASH) || defined(CONFIG_IN_SDCARD) || defined(CONFIG_IN_MEMORY_MAPPED_FLASH)
505 #define EEPROM_SIZE 4096
507 extern uint8_t eepromData
[EEPROM_SIZE
];
508 #define __config_start (*eepromData)
509 #define __config_end (*ARRAYEND(eepromData))
511 #ifndef CONFIG_IN_FLASH
512 #define CONFIG_IN_FLASH
514 extern uint8_t __config_start
; // configured via linker script when building binaries.
515 extern uint8_t __config_end
;
518 #if defined(USE_EXST) && !defined(RAMBASED)
519 #define USE_FLASH_BOOT_LOADER
522 #if defined(USE_FLASH_MEMORY_MAPPED)
523 #if !defined(USE_RAM_CODE)
527 #define MMFLASH_CODE RAM_CODE
528 #define MMFLASH_CODE_NOINLINE RAM_CODE NOINLINE
530 #define MMFLASH_DATA FAST_DATA
531 #define MMFLASH_DATA_ZERO_INIT FAST_DATA_ZERO_INIT
534 #define MMFLASH_CODE_NOINLINE
536 #define MMFLASH_DATA_ZERO_INIT
540 // RAM_CODE for methods that need to be in RAM, but don't need to be in the fastest type of memory.
541 // Note: if code is marked as RAM_CODE it *MUST* be in RAM, there is no alternative unlike functions marked with FAST_CODE/CCM_CODE
542 #define RAM_CODE __attribute__((section(".ram_code")))
545 #if !defined(USE_RPM_FILTER)
549 #ifndef USE_ITERM_RELAX
550 #undef USE_ABSOLUTE_CONTROL
553 #if defined(USE_RX_EXPRESSLRS)
554 // ELRS depends on CRSF telemetry
555 #if !defined(USE_TELEMETRY)
556 #define USE_TELEMETRY
558 #if !defined(USE_TELEMETRY_CRSF)
559 #define USE_TELEMETRY_CRSF
561 #if !defined(USE_CRSF_LINK_STATISTICS)
562 #define USE_CRSF_LINK_STATISTICS
564 #if !defined(USE_SERIALRX_CRSF)
565 #define USE_SERIALRX_CRSF
569 #if defined(USE_RX_SPI) || defined(USE_SERIALRX_SRXL2)
574 #undef USE_GPS_PLUS_CODES