]> localhost Git - SCSI2SD-V6.git/commitdiff
Fix issue with SCSI timeouts if writes take too long
authorMichael McMaster <michael@codesrc.com>
Mon, 3 May 2021 06:03:26 +0000 (16:03 +1000)
committerMichael McMaster <michael@codesrc.com>
Mon, 3 May 2021 06:03:26 +0000 (16:03 +1000)
src/firmware/bsp_driver_sd.c
src/firmware/bsp_driver_sd.h
src/firmware/disk.c

index fe2601c43d29abd2236267d722a2c6437789d14a..5c561bfe456e98e3f2dfc5c1685ffe784e277d4c 100755 (executable)
@@ -192,6 +192,7 @@ __weak void BSP_SD_DetectCallback(void)
   * @param  NumOfBlocks: Number of SD blocks to read 
   * @retval SD status
   */
+/*
 uint8_t BSP_SD_ReadBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks)
 {
   if(HAL_SD_ReadBlocks_DMA(&hsd, pData, BlockAddr, NumOfBlocks) != HAL_OK)  
@@ -199,7 +200,7 @@ uint8_t BSP_SD_ReadBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBloc
     return MSD_ERROR;
   }
   return MSD_OK;
-}
+}*/
 
 /**
   * @brief  Writes block(s) to a specified address in an SD card, in polling mode. 
@@ -208,14 +209,14 @@ uint8_t BSP_SD_ReadBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBloc
   * @param  NumOfBlocks: Number of SD blocks to write
   * @retval SD status
   */
-uint8_t BSP_SD_WriteBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks)
+/*uint8_t BSP_SD_WriteBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks)
 {
   if(HAL_SD_WriteBlocks_DMA(&hsd, pData, BlockAddr, NumOfBlocks) != HAL_OK)  
   {
     return MSD_ERROR;
   }
   return MSD_OK;
-}
+}*/
 
 /**
   * @brief  Reads block(s) from a specified address in an SD card, in DMA mode. 
@@ -283,7 +284,16 @@ uint8_t BSP_SD_WriteBlocks_DMA(uint8_t *pData, uint64_t BlockAddr, uint32_t NumO
       SD_state = MSD_OK;
     }
 
-    while (HAL_SD_GetCardState(&hsd) == HAL_SD_CARD_PROGRAMMING) {}
+    HAL_SD_CardStateTypeDef cardState = HAL_SD_GetCardState(&hsd);
+    while (cardState == HAL_SD_CARD_PROGRAMMING || cardState == HAL_SD_CARD_RECEIVING) 
+    {
+        // Wait while the SD card is writing buffer to flash
+        // The card may remain in the RECEIVING state (even though it's programming) if
+        // it has buffer space to receive more data available.
+
+        cardState = HAL_SD_GetCardState(&hsd);
+    }
+
   }
   
   return SD_state; 
index d476214305a6f9b787ff22736e1de4472a7d4f06..8d216411c7aba337d7a4724d2d4270b7438c865c 100755 (executable)
@@ -88,8 +88,8 @@ uint8_t BSP_SD_Init(void);
 uint8_t BSP_SD_ITConfig(void);
 void BSP_SD_DetectIT(void);
 __weak void BSP_SD_DetectCallback(void);
-uint8_t BSP_SD_ReadBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks);
-uint8_t BSP_SD_WriteBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks);
+//uint8_t BSP_SD_ReadBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks);
+//uint8_t BSP_SD_WriteBlocks(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks);
 uint8_t BSP_SD_ReadBlocks_DMA(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks);
 uint8_t BSP_SD_WriteBlocks_DMA(uint8_t *pData, uint64_t BlockAddr, uint32_t NumOfBlocks);
 //uint8_t BSP_SD_Erase(uint64_t StartAddr, uint64_t EndAddr);
index 7c4c5bce2047ec47c3535449d95f096d20f011c7..b853fea5b31e0e260a0b98e0a1b336c22b8c4f2c 100755 (executable)
@@ -859,6 +859,16 @@ void scsiDiskPoll()
                                        // Wait while keeping BSY.\r
                                }\r
 \r
+                HAL_SD_CardStateTypeDef cardState = HAL_SD_GetCardState(&hsd);\r
+                while ((cardState == HAL_SD_CARD_PROGRAMMING || cardState == HAL_SD_CARD_RECEIVING) &&\r
+                                       s2s_elapsedTime_ms(dmaFinishTime) < 180)\r
+                {\r
+                    // Wait while the SD card is writing buffer to flash\r
+                    // The card may remain in the RECEIVING state (even though it's programming) if\r
+                    // it has buffer space to receive more data available.\r
+                    cardState = HAL_SD_GetCardState(&hsd);\r
+                }\r
+\r
                                if (i + sectors >= totalSDSectors &&\r
                                        !underrun &&\r
                                        (!parityError || !enableParity))\r
@@ -878,9 +888,14 @@ void scsiDiskPoll()
                                {\r
                                        // Wait while keeping BSY.\r
                                }\r
-                while (HAL_SD_GetCardState(&hsd) == HAL_SD_CARD_PROGRAMMING) \r
+\r
+                cardState = HAL_SD_GetCardState(&hsd);\r
+                while (cardState == HAL_SD_CARD_PROGRAMMING || cardState == HAL_SD_CARD_RECEIVING) \r
                 {\r
                     // Wait while the SD card is writing buffer to flash\r
+                    // The card may remain in the RECEIVING state (even though it's programming) if\r
+                    // it has buffer space to receive more data available.\r
+                    cardState = HAL_SD_GetCardState(&hsd);\r
                 }\r
 \r
                                if (underrun && (!parityError || !enableParity))\r