Browse Source

Retry SD card init if it fails

Petteri Aimonen 3 years ago
parent
commit
8660e5da1e
1 changed files with 13 additions and 9 deletions
  1. 13 9
      src/AzulSCSI.cpp

+ 13 - 9
src/AzulSCSI.cpp

@@ -1060,17 +1060,21 @@ int main(void)
 
   if(!SD.begin(SD_CONFIG))
   {
-    azlog("SD card init failed, sdErrorCode:", (int)SD.sdErrorCode(),
-           "sdErrorData:", (int)SD.sdErrorData());
-    blinkStatus(BLINK_ERROR_NO_SD_CARD);
-  }
-  else
-  {
-    uint64_t size = (uint64_t)SD.vol()->clusterCount() * SD.vol()->bytesPerCluster();
-    azlog("SD card init succeeded, FAT", (int)SD.vol()->fatType(),
-           " volume size: ", (int)(size / 1024 / 1024), " MB");
+    azlog("SD card init failed, sdErrorCode: ", (int)SD.sdErrorCode(),
+           " sdErrorData: ", (int)SD.sdErrorData());
+    
+    do
+    {
+      blinkStatus(BLINK_ERROR_NO_SD_CARD);
+      delay(5000);
+    } while (!SD.begin(SD_CONFIG));
+    azlog("SD card init succeeded after retry");
   }
 
+  uint64_t size = (uint64_t)SD.vol()->clusterCount() * SD.vol()->bytesPerCluster();
+  azlog("SD card init succeeded, FAT", (int)SD.vol()->fatType(),
+          " volume size: ", (int)(size / 1024 / 1024), " MB");
+
   readSCSIDeviceConfig();
   findHDDImages();