From 8730a8efeae1581d20a28a6e11d06fa711ce8a1c Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Fri, 1 Oct 2021 03:21:04 +1300 Subject: [PATCH] Fixed SPI SD card support on H7 targets with SDIO support enabled. --- src/main/fc/init.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/fc/init.c b/src/main/fc/init.c index bb47da4efd..8e302d2fc2 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -401,16 +401,6 @@ void init(void) dbgPinInit(); #endif -#ifdef USE_SDCARD - // Ensure the SD card is initialised before the USB MSC starts to avoid a race condition -#if !defined(CONFIG_IN_SDCARD) && defined(STM32H7) && defined(USE_SDCARD_SDIO) // H7 only for now, likely should be applied to F4/F7 too - sdioPinConfigure(); - SDIO_GPIO_Init(); - initFlags |= SD_INIT_ATTEMPTED; - sdCardAndFSInit(); -#endif -#endif - #ifdef USE_BRUSHED_ESC_AUTODETECT // Now detect again with the actually configured pin for motor 1, if it is not the default pin. ioTag_t configuredMotorIoTag = motorConfig()->dev.ioTags[0]; @@ -597,6 +587,11 @@ void init(void) initFlags |= SPI_AND_QSPI_INIT_ATTEMPTED; } +#if defined(USE_SDCARD_SDIO) && !defined(CONFIG_IN_SDCARD) && defined(STM32H7) + sdioPinConfigure(); + SDIO_GPIO_Init(); +#endif + #ifdef USE_USB_MSC /* MSC mode will start after init, but will not allow scheduler to run, * so there is no bottleneck in reading and writing data */ @@ -604,6 +599,10 @@ void init(void) if (mscCheckBootAndReset() || mscCheckButton()) { ledInit(statusLedConfig()); +#ifdef USE_SDCARD + sdCardAndFSInit(); +#endif + #if defined(USE_FLASHFS) // If the blackbox device is onboard flash, then initialize and scan // it to identify the log files *before* starting the USB device to @@ -805,8 +804,8 @@ void init(void) if (blackboxConfig()->device == BLACKBOX_DEVICE_SDCARD) { if (sdcardConfig()->mode) { if (!(initFlags & SD_INIT_ATTEMPTED)) { - initFlags |= SD_INIT_ATTEMPTED; sdCardAndFSInit(); + initFlags |= SD_INIT_ATTEMPTED; } } }