SDFileSystem for STM32F746NG DISCOVERY with 4bit SDMMC interface on fixed pins

Dependencies:   FATFileSystem

Dependents:   DISCO-F746NG_SDFileSystem uzairkhan DISCO-F746NG_Scope_copy

Fork of SDFileSystem by Neil Thiessen

Revision:
27:8d192c180436
Parent:
26:8f15aa3b052b
--- a/SDFileSystem.cpp	Wed Apr 13 08:51:27 2016 +0000
+++ b/SDFileSystem.cpp	Sat Apr 16 13:01:50 2016 +0000
@@ -24,8 +24,8 @@
     : FATFileSystem(name), m_Cd(PC_13)
 {
     //Initialize the member variables
+    void* h;
     uint8_t initstat;
-    void* h;
     m_CardType = CARD_NONE;
     m_Crc = true;
     m_LargeFrames = false;
@@ -188,18 +188,32 @@
     checkSocket();
 
     //Return the disk status
-    return m_Status;
+    return m_Status;     //Check the card socket
+    checkSocket();
+    if (m_Status){return m_Status;}
+    m_CardStatus=BSP_SD_GetStatus();
+    //Return the disk status
+    return m_CardStatus;
 }
 
 int SDFileSystem::disk_read(uint8_t* buffer, uint32_t sector, uint32_t count)
 {
     int retval;
+    uint32_t wdog;
     //Make sure the card is initialized before proceeding
     if (m_Status & STA_NOINIT)
         return RES_NOTRDY;
+    wdog=HAL_GetTick();
     __DSB();
     __ISB();
-    while(BSP_SD_Get_Busy()==1){;}
+    while(BSP_SD_Get_Busy()==1)
+     {
+       if((HAL_GetTick()-wdog)>64)
+        {
+         BSP_SD_Clear_Busy();
+         return  RES_ERROR;
+        }
+      }
     BSP_SD_Set_Busy();
     //Read a single block, or multiple blocks
     if (count > 1) {
@@ -224,12 +238,21 @@
 int SDFileSystem::disk_write(const uint8_t* buffer, uint32_t sector, uint32_t count)
 {
     int retval;
+    uint32_t wdog;
     //Make sure the card is initialized before proceeding
     if (m_Status & STA_NOINIT)
         return RES_NOTRDY;
+    wdog=HAL_GetTick();
     __DSB();
     __ISB();
-    while(BSP_SD_Get_Busy()==1){;}
+    while(BSP_SD_Get_Busy()==1)
+    {
+      if((HAL_GetTick()-wdog)>64)
+       {
+        BSP_SD_Clear_Busy();
+        return  RES_ERROR;
+       }
+    }   
     BSP_SD_Set_Busy();
     //Make sure the card isn't write protected before proceeding
     if (m_Status & STA_PROTECT)