Parcourir la source

Fix SD hotswap regression

Michael McMaster il y a 3 ans
Parent
commit
e23a4134fd
2 fichiers modifiés avec 7 ajouts et 1 suppressions
  1. 6 0
      lib/SCSI2SD/src/firmware/bsp_driver_sd.c
  2. 1 1
      lib/SCSI2SD/src/firmware/sd.c

+ 6 - 0
lib/SCSI2SD/src/firmware/bsp_driver_sd.c

@@ -56,6 +56,12 @@ uint8_t BSP_SD_Init(void)
     {
         return MSD_ERROR;
     }
+
+    // Reset defaults. High-speed mode can be incorrectly set if user removed then
+    // inserted a new SD card and we re-run initialisation.
+    hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
+    hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
+
     SD_state = HAL_SD_Init(&hsd);
 #ifdef BUS_4BITS
     if (SD_state == HAL_OK)

+ 1 - 1
lib/SCSI2SD/src/firmware/sd.c

@@ -233,7 +233,7 @@ int sdInit()
             // power on
             if (!firstInit)
             {
-                for (int i = 0; cs && i < 50; ++i)
+                for (int i = 0; cs && (i < 50); ++i)
                 {
                     cs = HAL_GPIO_ReadPin(nSD_CD_GPIO_Port, nSD_CD_Pin) ? 0 : 1;
                     s2s_delay_ms(5);