Few bug fixes to wait for SD card to be finished
[SCSI2SD-V6.git] / src / firmware / disk.c
index 1f849eca17c93349584e3918c5bce3823053264a..7c4c5bce2047ec47c3535449d95f096d20f011c7 100755 (executable)
@@ -635,7 +635,8 @@ void scsiDiskPoll()
                                (prep - i < buffers) &&\r
                                (prep < totalSDSectors) &&\r
                                ((totalSDSectors - prep) >= sdPerScsi) &&\r
-                               (likely(!useSlowDataCount) || scsiPhyComplete()))\r
+                               (likely(!useSlowDataCount) || scsiPhyComplete()) &&\r
+                               (HAL_SD_GetState(&hsd) != HAL_SD_STATE_BUSY)) // rx complete but IRQ not fired yet.\r
                        {\r
                                // Start an SD transfer if we have space.\r
                                uint32_t startBuffer = prep % buffers;\r
@@ -714,6 +715,11 @@ void scsiDiskPoll()
                }\r
                __enable_irq();\r
 \r
+               while (HAL_SD_GetState(&hsd) == HAL_SD_STATE_BUSY)\r
+               {\r
+                       // Wait while keeping BSY.\r
+               }\r
+\r
                if (scsiDev.phase == DATA_IN)\r
                {\r
                        scsiDev.phase = STATUS;\r