From e0f2b89828a70f930386497039824f0fc24f8135 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Wed, 5 May 2021 21:22:17 +0200 Subject: [PATCH 1/2] Indicate failure when CONFIG_IN_SDCARD is used and no SD card is inserted. --- src/main/drivers/system.h | 1 + src/main/fc/init.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/main/drivers/system.h b/src/main/drivers/system.h index 0122eb504..a79428079 100644 --- a/src/main/drivers/system.h +++ b/src/main/drivers/system.h @@ -42,6 +42,7 @@ typedef enum { FAILURE_SDCARD_READ_FAILED, FAILURE_SDCARD_WRITE_FAILED, FAILURE_SDCARD_INITIALISATION_FAILED, + FAILURE_SDCARD_REQUIRED, } failureMode_e; #define WARNING_FLASH_DURATION_MS 50 diff --git a/src/main/fc/init.c b/src/main/fc/init.c index eee71bd7a..900c96cde 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -374,6 +374,10 @@ void init(void) sdCardAndFSInit(); initFlags |= SD_INIT_ATTEMPTED; + if (!sdcard_isInserted()) { + failureMode(FAILURE_SDCARD_REQUIRED); + } + while (afatfs_getFilesystemState() != AFATFS_FILESYSTEM_STATE_READY) { afatfs_poll(); From 5eec605290c041bdebf7580108116118630d2be5 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Wed, 5 May 2021 22:37:09 +0200 Subject: [PATCH 2/2] Force reset the SDMMC peripheral to prevent SD card initialization failure. * Observed on EXST targets. Reference: https://community.st.com/s/question/0D53W00000MBn2mSAD/stm32h743-sdmmc-write-problem --- src/main/drivers/sdio_h7xx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/drivers/sdio_h7xx.c b/src/main/drivers/sdio_h7xx.c index 9d8dd1890..d069ad8b2 100644 --- a/src/main/drivers/sdio_h7xx.c +++ b/src/main/drivers/sdio_h7xx.c @@ -168,8 +168,14 @@ void HAL_SD_MspInit(SD_HandleTypeDef* hsd) } if (sdioHardware->instance == SDMMC1) { + __HAL_RCC_SDMMC1_CLK_DISABLE(); + __HAL_RCC_SDMMC1_FORCE_RESET(); + __HAL_RCC_SDMMC1_RELEASE_RESET(); __HAL_RCC_SDMMC1_CLK_ENABLE(); } else if (sdioHardware->instance == SDMMC2) { + __HAL_RCC_SDMMC2_CLK_DISABLE(); + __HAL_RCC_SDMMC2_FORCE_RESET(); + __HAL_RCC_SDMMC2_RELEASE_RESET(); __HAL_RCC_SDMMC2_CLK_ENABLE(); }