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/>.
28 #include "blackbox/blackbox.h"
30 #include "build/build_config.h"
31 #include "build/debug.h"
32 #include "build/debug_pin.h"
35 #include "cms/cms_types.h"
37 #include "common/axis.h"
38 #include "common/color.h"
39 #include "common/maths.h"
40 #include "common/printf_serial.h"
42 #include "config/config.h"
43 #include "config/config_eeprom.h"
44 #include "config/feature.h"
46 #include "drivers/accgyro/accgyro.h"
47 #include "drivers/adc.h"
48 #include "drivers/bus.h"
49 #include "drivers/bus_i2c.h"
50 #include "drivers/bus_quadspi.h"
51 #include "drivers/bus_spi.h"
52 #include "drivers/buttons.h"
53 #include "drivers/camera_control.h"
54 #include "drivers/compass/compass.h"
55 #include "drivers/dma.h"
56 #include "drivers/exti.h"
57 #include "drivers/flash.h"
58 #include "drivers/inverter.h"
59 #include "drivers/io.h"
60 #include "drivers/light_led.h"
61 #include "drivers/mco.h"
62 #include "drivers/nvic.h"
63 #include "drivers/persistent.h"
64 #include "drivers/pin_pull_up_down.h"
65 #include "drivers/pwm_esc_detect.h"
66 #include "drivers/pwm_output.h"
67 #include "drivers/rx/rx_pwm.h"
68 #include "drivers/sensor.h"
69 #include "drivers/serial.h"
70 #include "drivers/serial_softserial.h"
71 #include "drivers/serial_uart.h"
72 #include "drivers/sdcard.h"
73 #include "drivers/sdio.h"
74 #include "drivers/sound_beeper.h"
75 #include "drivers/system.h"
76 #include "drivers/time.h"
77 #include "drivers/timer.h"
78 #include "drivers/transponder_ir.h"
79 #include "drivers/usb_io.h"
81 #include "drivers/usb_msc.h"
83 #include "drivers/vtx_common.h"
84 #include "drivers/vtx_rtc6705.h"
85 #include "drivers/vtx_table.h"
87 #include "fc/board_info.h"
88 #include "fc/dispatch.h"
90 #include "fc/rc_controls.h"
91 #include "fc/runtime_config.h"
95 #include "flight/failsafe.h"
96 #include "flight/imu.h"
97 #include "flight/mixer.h"
98 #include "flight/pid.h"
99 #include "flight/pid_init.h"
100 #include "flight/servos.h"
102 #include "io/asyncfatfs/asyncfatfs.h"
103 #include "io/beeper.h"
104 #include "io/dashboard.h"
105 #include "io/displayport_frsky_osd.h"
106 #include "io/displayport_max7456.h"
107 #include "io/displayport_msp.h"
108 #include "io/flashfs.h"
109 #include "io/gimbal.h"
111 #include "io/ledstrip.h"
112 #include "io/pidaudio.h"
113 #include "io/piniobox.h"
114 #include "io/rcdevice_cam.h"
115 #include "io/serial.h"
116 #include "io/servos.h"
117 #include "io/transponder_ir.h"
119 #include "io/vtx_control.h"
120 #include "io/vtx_rtc6705.h"
121 #include "io/vtx_smartaudio.h"
122 #include "io/vtx_tramp.h"
124 #include "msc/emfat_file.h"
125 #ifdef USE_PERSISTENT_MSC_RTC
126 #include "msc/usbd_storage.h"
130 #include "msp/msp_serial.h"
135 #include "pg/beeper.h"
136 #include "pg/beeper_dev.h"
137 #include "pg/bus_i2c.h"
138 #include "pg/bus_spi.h"
139 #include "pg/bus_quadspi.h"
140 #include "pg/flash.h"
142 #include "pg/motor.h"
143 #include "pg/pinio.h"
144 #include "pg/piniobox.h"
145 #include "pg/pin_pull_up_down.h"
148 #include "pg/rx_pwm.h"
149 #include "pg/rx_spi.h"
150 #include "pg/sdcard.h"
152 #include "pg/vtx_io.h"
155 #include "rx/spektrum.h"
157 #include "scheduler/scheduler.h"
159 #include "sensors/acceleration.h"
160 #include "sensors/barometer.h"
161 #include "sensors/battery.h"
162 #include "sensors/boardalignment.h"
163 #include "sensors/compass.h"
164 #include "sensors/esc_sensor.h"
165 #include "sensors/gyro.h"
166 #include "sensors/gyro_init.h"
167 #include "sensors/initialisation.h"
169 #include "telemetry/telemetry.h"
171 #ifdef USE_HARDWARE_REVISION_DETECTION
172 #include "hardware_revision.h"
175 #ifdef TARGET_PREINIT
176 void targetPreInit(void);
179 uint8_t systemState
= SYSTEM_STATE_INITIALISING
;
181 #ifdef BUS_SWITCH_PIN
182 void busSwitchInit(void)
184 IO_t busSwitchResetPin
= IO_NONE
;
186 busSwitchResetPin
= IOGetByTag(IO_TAG(BUS_SWITCH_PIN
));
187 IOInit(busSwitchResetPin
, OWNER_SYSTEM
, 0);
188 IOConfigGPIO(busSwitchResetPin
, IOCFG_OUT_PP
);
191 IOLo(busSwitchResetPin
);
196 static void configureSPIAndQuadSPI(void)
199 spiPinConfigure(spiPinConfig(0));
207 #ifdef USE_SPI_DEVICE_1
210 #ifdef USE_SPI_DEVICE_2
213 #ifdef USE_SPI_DEVICE_3
216 #ifdef USE_SPI_DEVICE_4
219 #ifdef USE_SPI_DEVICE_5
222 #ifdef USE_SPI_DEVICE_6
228 quadSpiPinConfigure(quadSpiConfig(0));
230 #ifdef USE_QUADSPI_DEVICE_1
231 quadSpiInit(QUADSPIDEV_1
);
233 #endif // USE_QUAD_SPI
237 static void sdCardAndFSInit()
239 sdcard_init(sdcardConfig());
244 static void swdPinsInit(void)
246 IO_t io
= IOGetByTag(DEFIO_TAG_E(PA13
)); // SWDIO
247 if (IOGetOwner(io
) == OWNER_FREE
) {
248 IOInit(io
, OWNER_SWD
, 0);
250 io
= IOGetByTag(DEFIO_TAG_E(PA14
)); // SWCLK
251 if (IOGetOwner(io
) == OWNER_FREE
) {
252 IOInit(io
, OWNER_SWD
, 0);
258 #ifdef SERIAL_PORT_COUNT
264 // initialize IO (needed for all IO operations)
267 #ifdef USE_HARDWARE_REVISION_DETECTION
268 detectHardwareRevision();
271 #if defined(USE_TARGET_CONFIG)
272 // Call once before the config is loaded for any target specific configuration required to support loading the config
273 targetConfiguration();
276 #ifdef USE_BRUSHED_ESC_AUTODETECT
277 // Opportunistically use the first motor pin of the default configuration for detection.
278 // We are doing this as with some boards, timing seems to be important, and the later detection will fail.
279 ioTag_t motorIoTag
= timerioTagGetByUsage(TIM_USE_MOTOR
, 0);
282 detectBrushedESC(motorIoTag
);
287 FLASH_INIT_ATTEMPTED
= (1 << 0),
288 SD_INIT_ATTEMPTED
= (1 << 1),
289 SPI_AND_QSPI_INIT_ATTEMPTED
= (1 << 2),
291 uint8_t initFlags
= 0;
293 #ifdef CONFIG_IN_SDCARD
296 // Config in sdcard presents an issue with pin configuration since the pin and sdcard configs for the
297 // sdcard are in the config which is on the sdcard which we can't read yet!
299 // FIXME We need to add configuration somewhere, e.g. bootloader image or reserved flash area, that can be read by the firmware.
300 // it's currently possible for the firmware resource allocation to be wrong after the config is loaded if the user changes the settings.
301 // This would cause undefined behaviour once the config is loaded. so for now, users must NOT change sdio/spi configs needed for
302 // the system to boot and/or to save the config.
304 // note that target specific SDCARD/SDIO/SPI/QUADSPI configs are
305 // also not supported in USE_TARGET_CONFIG/targetConfigure() when using CONFIG_IN_SDCARD.
309 // IMPORTANT: all default flash and pin configurations must be valid for the target after pgResetAll() is called.
310 // Target designers must ensure other devices connected the same SPI/QUADSPI interface as the flash chip do not
311 // cause communication issues with the flash chip. e.g. use external pullups on SPI/QUADSPI CS lines.
314 #ifdef TARGET_BUS_INIT
315 #error "CONFIG_IN_SDCARD and TARGET_BUS_INIT are mutually exclusive"
320 #ifdef USE_SDCARD_SPI
321 configureSPIAndQuadSPI();
322 initFlags
|= SPI_AND_QSPI_INIT_ATTEMPTED
;
326 initFlags
|= SD_INIT_ATTEMPTED
;
328 if (!sdcard_isInserted()) {
329 failureMode(FAILURE_SDCARD_REQUIRED
);
332 while (afatfs_getFilesystemState() != AFATFS_FILESYSTEM_STATE_READY
) {
335 if (afatfs_getFilesystemState() == AFATFS_FILESYSTEM_STATE_FATAL
) {
336 failureMode(FAILURE_SDCARD_INITIALISATION_FAILED
);
340 #endif // CONFIG_IN_SDCARD
342 #ifdef CONFIG_IN_EXTERNAL_FLASH
344 // Config on external flash presents an issue with pin configuration since the pin and flash configs for the
345 // external flash are in the config which is on a chip which we can't read yet!
347 // FIXME We need to add configuration somewhere, e.g. bootloader image or reserved flash area, that can be read by the firmware.
348 // it's currently possible for the firmware resource allocation to be wrong after the config is loaded if the user changes the settings.
349 // This would cause undefined behaviour once the config is loaded. so for now, users must NOT change flash/pin configs needed for
350 // the system to boot and/or to save the config.
352 // note that target specific FLASH/SPI/QUADSPI configs are
353 // also not supported in USE_TARGET_CONFIG/targetConfigure() when using CONFIG_IN_EXTERNAL_FLASH.
357 // IMPORTANT: all default flash and pin configurations must be valid for the target after pgResetAll() is called.
358 // Target designers must ensure other devices connected the same SPI/QUADSPI interface as the flash chip do not
359 // cause communication issues with the flash chip. e.g. use external pullups on SPI/QUADSPI CS lines.
363 #ifdef TARGET_BUS_INIT
364 #error "CONFIG_IN_EXTERNAL_FLASH and TARGET_BUS_INIT are mutually exclusive"
367 configureSPIAndQuadSPI();
368 initFlags
|= SPI_AND_QSPI_INIT_ATTEMPTED
;
371 #ifndef USE_FLASH_CHIP
372 #error "CONFIG_IN_EXTERNAL_FLASH requires USE_FLASH_CHIP to be defined."
375 bool haveFlash
= flashInit(flashConfig());
378 failureMode(FAILURE_EXTERNAL_FLASH_INIT_FAILED
);
380 initFlags
|= FLASH_INIT_ATTEMPTED
;
382 #endif // CONFIG_IN_EXTERNAL_FLASH
386 ensureEEPROMStructureIsValid();
388 bool readSuccess
= readEEPROM();
390 #if defined(USE_BOARD_INFO)
391 initBoardInformation();
394 if (!readSuccess
|| !isEEPROMVersionValid() || strncasecmp(systemConfig()->boardIdentifier
, TARGET_BOARD_IDENTIFIER
, sizeof(TARGET_BOARD_IDENTIFIER
))) {
398 systemState
|= SYSTEM_STATE_CONFIG_LOADED
;
404 #ifdef USE_BRUSHED_ESC_AUTODETECT
405 // Now detect again with the actually configured pin for motor 1, if it is not the default pin.
406 ioTag_t configuredMotorIoTag
= motorConfig()->dev
.ioTags
[0];
408 if (configuredMotorIoTag
&& configuredMotorIoTag
!= motorIoTag
) {
409 detectBrushedESC(configuredMotorIoTag
);
413 debugMode
= systemConfig()->debug_mode
;
415 #ifdef TARGET_PREINIT
419 #if !defined(USE_FAKE_LED)
420 ledInit(statusLedConfig());
428 #if defined(USE_BUTTONS)
432 delayMicroseconds(10); // allow configuration to settle // XXX Could be removed, too?
434 // Allow EEPROM reset with two-button-press without power cycling in DEBUG build
436 #define EEPROM_RESET_PRECONDITION true
438 #define EEPROM_RESET_PRECONDITION (!isMPUSoftReset())
441 if (EEPROM_RESET_PRECONDITION
) {
442 #if defined(BUTTON_A_PIN) && defined(BUTTON_B_PIN)
443 // two buttons required
444 uint8_t secondsRemaining
= 5;
445 bool bothButtonsHeld
;
447 bothButtonsHeld
= buttonAPressed() && buttonBPressed();
448 if (bothButtonsHeld
) {
449 if (--secondsRemaining
== 0) {
451 #ifdef USE_PERSISTENT_OBJECTS
452 persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON
, RESET_NONE
);
459 } while (bothButtonsHeld
);
463 #undef EEPROM_RESET_PRECONDITION
465 #endif // USE_BUTTONS
467 // Note that spektrumBind checks if a call is immediately after
468 // hard reset (including power cycle), so it should be called before
469 // systemClockSetHSEValue and OverclockRebootIfNecessary, as these
470 // may cause soft reset which will prevent spektrumBind not to execute
471 // the bind procedure.
473 #if defined(USE_SPEKTRUM_BIND)
474 if (featureIsEnabled(FEATURE_RX_SERIAL
)) {
475 switch (rxConfig()->serialrx_provider
) {
476 case SERIALRX_SPEKTRUM1024
:
477 case SERIALRX_SPEKTRUM2048
:
479 // Spektrum satellite binding if enabled on startup.
480 // Must be called before that 100ms sleep so that we don't lose satellite's binding window after startup.
481 // The rest of Spektrum initialization will happen later - via spektrumInit()
482 spektrumBind(rxConfigMutable());
488 #if defined(STM32F4) || defined(STM32G4)
489 // F4 has non-8MHz boards
490 // G4 for Betaflight allow 24 or 27MHz oscillator
491 systemClockSetHSEValue(systemConfig()->hseMhz
* 1000000U);
495 OverclockRebootIfNecessary(systemConfig()->cpu_overclock
);
498 // Configure MCO output after config is stable
500 // Note that mcoConfigure must be augmented with an additional argument to
501 // indicate which device instance to configure when MCO and MCO2 are both supported
503 #if defined(STM32F4) || defined(STM32F7)
504 // F4 and F7 support MCO on PA8 and MCO2 on PC9, but only MCO2 is supported for now
505 mcoConfigure(MCODEV_2
, mcoConfig(MCODEV_2
));
506 #elif defined(STM32G4)
507 // G4 only supports one MCO on PA8
508 mcoConfigure(MCODEV_1
, mcoConfig(MCODEV_1
));
510 #error Unsupported MCU
515 timerInit(); // timer must be initialized before any channel is allocated
518 #ifdef BUS_SWITCH_PIN
522 #if defined(USE_UART) && !defined(SIMULATOR_BUILD)
523 uartPinConfigure(serialPinConfig());
526 #if defined(AVOID_UART1_FOR_PWM_PPM)
527 serialInit(featureIsEnabled(FEATURE_SOFTSERIAL
),
528 featureIsEnabled(FEATURE_RX_PPM
) || featureIsEnabled(FEATURE_RX_PARALLEL_PWM
) ? SERIAL_PORT_USART1
: SERIAL_PORT_NONE
);
529 #elif defined(AVOID_UART2_FOR_PWM_PPM)
530 serialInit(featureIsEnabled(FEATURE_SOFTSERIAL
),
531 featureIsEnabled(FEATURE_RX_PPM
) || featureIsEnabled(FEATURE_RX_PARALLEL_PWM
) ? SERIAL_PORT_USART2
: SERIAL_PORT_NONE
);
532 #elif defined(AVOID_UART3_FOR_PWM_PPM)
533 serialInit(featureIsEnabled(FEATURE_SOFTSERIAL
),
534 featureIsEnabled(FEATURE_RX_PPM
) || featureIsEnabled(FEATURE_RX_PARALLEL_PWM
) ? SERIAL_PORT_USART3
: SERIAL_PORT_NONE
);
536 serialInit(featureIsEnabled(FEATURE_SOFTSERIAL
), SERIAL_PORT_NONE
);
539 mixerInit(mixerConfig()->mixerMode
);
541 uint16_t idlePulse
= motorConfig()->mincommand
;
542 if (featureIsEnabled(FEATURE_3D
)) {
543 idlePulse
= flight3DConfig()->neutral3d
;
545 if (motorConfig()->dev
.motorPwmProtocol
== PWM_TYPE_BRUSHED
) {
546 idlePulse
= 0; // brushed motors
549 /* Motors needs to be initialized soon as posible because hardware initialization
550 * may send spurious pulses to esc's causing their early initialization. Also ppm
551 * receiver may share timer with motors so motors MUST be initialized here. */
552 motorDevInit(&motorConfig()->dev
, idlePulse
, getMotorCount());
553 systemState
|= SYSTEM_STATE_MOTORS_READY
;
560 else if (featureIsEnabled(FEATURE_RX_PPM
)) {
561 ppmRxInit(ppmConfig());
565 else if (featureIsEnabled(FEATURE_RX_PARALLEL_PWM
)) {
566 pwmRxInit(pwmConfig());
571 beeperInit(beeperDevConfig());
573 /* temp until PGs are implemented. */
574 #if defined(USE_INVERTER) && !defined(SIMULATOR_BUILD)
575 initInverters(serialPinConfig());
579 #ifdef TARGET_BUS_INIT
584 // Depending on compilation options SPI/QSPI initialisation may already be done.
585 if (!(initFlags
& SPI_AND_QSPI_INIT_ATTEMPTED
)) {
586 configureSPIAndQuadSPI();
587 initFlags
|= SPI_AND_QSPI_INIT_ATTEMPTED
;
590 #if defined(USE_SDCARD_SDIO) && !defined(CONFIG_IN_SDCARD) && defined(STM32H7)
596 /* MSC mode will start after init, but will not allow scheduler to run,
597 * so there is no bottleneck in reading and writing data */
599 if (mscCheckBootAndReset() || mscCheckButton()) {
600 ledInit(statusLedConfig());
603 if (blackboxConfig()->device
== BLACKBOX_DEVICE_SDCARD
) {
604 if (sdcardConfig()->mode
) {
605 if (!(initFlags
& SD_INIT_ATTEMPTED
)) {
607 initFlags
|= SD_INIT_ATTEMPTED
;
613 #if defined(USE_FLASHFS)
614 // If the blackbox device is onboard flash, then initialize and scan
615 // it to identify the log files *before* starting the USB device to
616 // prevent timeouts of the mass storage device.
617 if (blackboxConfig()->device
== BLACKBOX_DEVICE_FLASH
) {
621 // There's no more initialisation to be done, so enable DMA where possible for SPI
625 if (mscStart() == 0) {
628 systemResetFromMsc();
633 #ifdef USE_PERSISTENT_MSC_RTC
634 // if we didn't enter MSC mode then clear the persistent RTC value
635 persistentObjectWrite(PERSISTENT_OBJECT_RTC_HIGH
, 0);
636 persistentObjectWrite(PERSISTENT_OBJECT_RTC_LOW
, 0);
640 i2cHardwareConfigure(i2cConfig(0));
642 // Note: Unlike UARTs which are configured when client is present,
643 // I2C buses are initialized unconditionally if they are configured.
645 #ifdef USE_I2C_DEVICE_1
648 #ifdef USE_I2C_DEVICE_2
651 #ifdef USE_I2C_DEVICE_3
654 #ifdef USE_I2C_DEVICE_4
659 #endif // TARGET_BUS_INIT
661 #ifdef USE_HARDWARE_REVISION_DETECTION
662 updateHardwareRevision();
665 #ifdef USE_VTX_RTC6705
666 bool useRTC6705
= rtc6705IOInit(vtxIOConfig());
669 #ifdef USE_CAMERA_CONTROL
674 adcInit(adcConfig());
677 initBoardAlignment(boardAlignment());
679 if (!sensorsAutodetect()) {
680 // if gyro was not detected due to whatever reason, notify and don't arm.
682 #if defined(USE_UNIFIED_TARGET)
683 && isSystemConfigured()
686 indicateFailure(FAILURE_MISSING_ACC
, 2);
688 setArmingDisabled(ARMING_DISABLED_NO_GYRO
);
691 systemState
|= SYSTEM_STATE_SENSORS_READY
;
693 // Set the targetLooptime based on the detected gyro sampleRateHz and pid_process_denom
694 gyroSetTargetLooptime(pidConfig()->pid_process_denom
);
696 // Validate and correct the gyro config or PID loop time if needed
697 validateAndFixGyroConfig();
699 // Now reset the targetLooptime as it's possible for the validation to change the pid_process_denom
700 gyroSetTargetLooptime(pidConfig()->pid_process_denom
);
702 // Finally initialize the gyro filtering
705 pidInit(currentPidProfile
);
715 if (isMixerUsingServos()) {
716 //pwm_params.useChannelForwarding = featureIsEnabled(FEATURE_CHANNEL_FORWARDING);
717 servoDevInit(&servoConfig()->dev
);
723 pinioInit(pinioConfig());
726 #ifdef USE_PIN_PULL_UP_DOWN
727 pinPullupPulldownInit();
731 pinioBoxInit(pinioBoxConfig());
738 for (int i
= 0; i
< 10; i
++) {
741 #if defined(USE_BEEPER)
743 if (!(beeperConfig()->beeper_off_flags
& BEEPER_GET_FLAG(BEEPER_SYSTEM_INIT
))) {
762 if (featureIsEnabled(FEATURE_GPS
)) {
770 if (featureIsEnabled(FEATURE_LED_STRIP
)) {
775 #ifdef USE_ESC_SENSOR
776 if (featureIsEnabled(FEATURE_ESC_SENSOR
)) {
781 #ifdef USE_USB_DETECT
782 usbCableDetectInit();
785 #ifdef USE_TRANSPONDER
786 if (featureIsEnabled(FEATURE_TRANSPONDER
)) {
788 transponderStartRepeating();
789 systemState
|= SYSTEM_STATE_TRANSPONDER_ENABLED
;
793 #ifdef USE_FLASH_CHIP
794 if (!(initFlags
& FLASH_INIT_ATTEMPTED
)) {
795 flashInit(flashConfig());
796 initFlags
|= FLASH_INIT_ATTEMPTED
;
805 if (blackboxConfig()->device
== BLACKBOX_DEVICE_SDCARD
) {
806 if (sdcardConfig()->mode
) {
807 if (!(initFlags
& SD_INIT_ATTEMPTED
)) {
809 initFlags
|= SD_INIT_ATTEMPTED
;
818 if (mixerConfig()->mixerMode
== MIXER_GIMBAL
) {
819 accStartCalibration();
822 gyroStartCalibration(false);
824 baroStartCalibration();
827 #if defined(USE_VTX_COMMON) || defined(USE_VTX_CONTROL)
831 #ifdef USE_VTX_CONTROL
834 #if defined(USE_VTX_COMMON)
838 #ifdef USE_VTX_SMARTAUDIO
846 #ifdef USE_VTX_RTC6705
847 if (!vtxCommonDevice() && useRTC6705
) { // external VTX takes precedence when configured.
852 #endif // VTX_CONTROL
856 // TODO - not implemented yet
860 batteryInit(); // always needs doing, regardless of features.
864 #endif // USE_RCDEVICE
866 #ifdef USE_PERSISTENT_STATS
875 * CMS, display devices and OSD
881 #if (defined(USE_OSD) || (defined(USE_MSP_DISPLAYPORT) && defined(USE_CMS)))
882 displayPort_t
*osdDisplayPort
= NULL
;
883 osdDisplayPortDevice_e osdDisplayPortDevice
= OSD_DISPLAYPORT_DEVICE_NONE
;
887 //The OSD need to be initialised after GYRO to avoid GYRO initialisation failure on some targets
889 if (featureIsEnabled(FEATURE_OSD
)) {
890 osdDisplayPortDevice_e device
= osdConfig()->displayPortDevice
;
894 case OSD_DISPLAYPORT_DEVICE_AUTO
:
897 #if defined(USE_FRSKYOSD)
898 // Test OSD_DISPLAYPORT_DEVICE_FRSKYOSD first, since an FC could
899 // have a builtin MAX7456 but also an FRSKYOSD connected to an
901 case OSD_DISPLAYPORT_DEVICE_FRSKYOSD
:
902 osdDisplayPort
= frskyOsdDisplayPortInit(vcdProfile()->video_system
);
903 if (osdDisplayPort
|| device
== OSD_DISPLAYPORT_DEVICE_FRSKYOSD
) {
904 osdDisplayPortDevice
= OSD_DISPLAYPORT_DEVICE_FRSKYOSD
;
910 #if defined(USE_MAX7456)
911 case OSD_DISPLAYPORT_DEVICE_MAX7456
:
912 // If there is a max7456 chip for the OSD configured and detected then use it.
913 if (max7456DisplayPortInit(vcdProfile(), &osdDisplayPort
) || device
== OSD_DISPLAYPORT_DEVICE_MAX7456
) {
914 osdDisplayPortDevice
= OSD_DISPLAYPORT_DEVICE_MAX7456
;
920 #if defined(USE_CMS) && defined(USE_MSP_DISPLAYPORT) && defined(USE_OSD_OVER_MSP_DISPLAYPORT)
921 case OSD_DISPLAYPORT_DEVICE_MSP
:
922 osdDisplayPort
= displayPortMspInit();
923 if (osdDisplayPort
|| device
== OSD_DISPLAYPORT_DEVICE_MSP
) {
924 osdDisplayPortDevice
= OSD_DISPLAYPORT_DEVICE_MSP
;
930 // Other device cases can be added here
932 case OSD_DISPLAYPORT_DEVICE_NONE
:
937 // osdInit will register with CMS by itself.
938 osdInit(osdDisplayPort
, osdDisplayPortDevice
);
940 if (osdDisplayPortDevice
== OSD_DISPLAYPORT_DEVICE_NONE
) {
941 featureDisableImmediate(FEATURE_OSD
);
946 #if defined(USE_CMS) && defined(USE_MSP_DISPLAYPORT)
947 // If BFOSD is not active, then register MSP_DISPLAYPORT as a CMS device.
948 if (!osdDisplayPort
) {
949 cmsDisplayPortRegister(displayPortMspInit());
954 // Dashbord will register with CMS by itself.
955 if (featureIsEnabled(FEATURE_DASHBOARD
)) {
957 #ifdef USE_OLED_GPS_DEBUG_PAGE_ONLY
958 dashboardShowFixedPage(PAGE_GPS
);
960 dashboardResetPageCycling();
961 dashboardEnablePageCycling();
967 // Telemetry will initialise displayport and register with CMS by itself.
968 if (featureIsEnabled(FEATURE_TELEMETRY
)) {
973 setArmingDisabled(ARMING_DISABLED_BOOT_GRACE_TIME
);
975 // On F4/F7 allocate SPI DMA streams before motor timers
976 #if defined(STM32F4) || defined(STM32F7)
978 // Attempt to enable DMA on all SPI busses
988 // On H7/G4 allocate SPI DMA streams after motor timers as SPI DMA allocate will always be possible
989 #if defined(STM32H7) || defined(STM32G4)
991 // Attempt to enable DMA on all SPI busses
1002 systemState
|= SYSTEM_STATE_READY
;