Coder Social home page Coder Social logo

Comments (1)

hyx0329 avatar hyx0329 commented on June 9, 2024

Here's my current workaound

EDIT: I won't mind if someone just pick this and make a pr. But I doubt that having 2 types of time limits in a single function is appropriate.

diff --git a/shared-module/sdcardio/SDCard.c b/shared-module/sdcardio/SDCard.c
index 20c5afef0e..fc886964de 100644
--- a/shared-module/sdcardio/SDCard.c
+++ b/shared-module/sdcardio/SDCard.c
@@ -210,18 +210,26 @@ STATIC mp_rom_error_text_t init_card_v1(sdcardio_sdcard_obj_t *self) {
     return MP_ERROR_TEXT("timeout waiting for v1 card");
 }
 
+#define INIT_CARD_V2_ERROR_RETRY 5
 STATIC mp_rom_error_text_t init_card_v2(sdcardio_sdcard_obj_t *self) {
+    int early_error = 0;
     for (int i = 0; i < CMD_TIMEOUT; i++) {
         uint8_t ocr[4];
         common_hal_time_delay_ms(50);
-        cmd(self, 58, 0, ocr, sizeof(ocr), false, true);
-        cmd(self, 55, 0, NULL, 0, true, true);
-        if (cmd(self, 41, 0x40000000, NULL, 0, true, true) == 0) {
+        if (cmd(self, 58, 0, ocr, sizeof(ocr), false, true) >= 0
+            && cmd(self, 55, 0, NULL, 0, true, true) != -ETIMEDOUT
+            && cmd(self, 41, 0x40000000, NULL, 0, true, true) == 0) {
+
             cmd(self, 58, 0, ocr, sizeof(ocr), false, true);
             if ((ocr[0] & 0x40) != 0) {
                 self->cdv = 1;
             }
             return NULL;
+        } else {
+            early_error++;
+            if (early_error >= INIT_CARD_V2_ERROR_RETRY) {
+                break;
+            }
         }
     }
     return MP_ERROR_TEXT("timeout waiting for v2 card");

from circuitpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.