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

Files at this revision

API Documentation at this revision

Comitter:
DieterGraef
Date:
Sat Apr 16 13:01:50 2016 +0000
Parent:
26:8f15aa3b052b
Commit message:
Changed hard locking mechanism to watchdog , solved issue with the sleep mode of SD cards

Changed in this revision

SDFileSystem.cpp Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.h Show annotated file Show diff for this revision Revisions of this file
--- 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)
--- a/SDFileSystem.h	Wed Apr 13 08:51:27 2016 +0000
+++ b/SDFileSystem.h	Sat Apr 16 13:01:50 2016 +0000
@@ -183,6 +183,7 @@
     bool m_WriteValidation;
     int m_Status;
     HAL_SD_CardInfoTypedef m_CardInfo;
+    HAL_SD_TransferStateTypedef m_CardStatus;
     //Internal methods
     void onCardRemoval();
     void checkSocket();