@@ -168,16 +168,20 @@ void beginSD()
168168
169169 if (settings.enableSD == true )
170170 {
171- // Max power up time is 250ms: https://www.kingston.com/datasheets/SDCIT-specsheet-64gb_en.pdf
172- // Max current is 200mA average across 1s, peak 300mA
173- delay (10 );
174-
175171 // Do a quick test to see if a card is present
176- if (sdPresent () == false )
172+ int tries = 0 ;
173+ int maxTries = 5 ;
174+ while (tries++ < maxTries)
177175 {
178- log_d (" SD card not detected" );
179- return ;
176+ if (sdPresent () == true ) break ;
177+ log_d (" SD present failed. Trying again %d out of %d" , tries + 1 , maxTries);
178+
179+ // Max power up time is 250ms: https://www.kingston.com/datasheets/SDCIT-specsheet-64gb_en.pdf
180+ // Max current is 200mA average across 1s, peak 300mA
181+ delay (10 );
180182 }
183+ if (tries == maxTries) return ;
184+
181185 // If an SD card is present, allow SdFat to take over
182186 log_d (" SD card detected" );
183187
@@ -189,8 +193,8 @@ void beginSD()
189193
190194 if (sd.begin (SdSpiConfig (pin_microSD_CS, SHARED_SPI, SD_SCK_MHZ (settings.spiFrequency ))) == false )
191195 {
192- int tries = 0 ;
193- int maxTries = 1 ;
196+ tries = 0 ;
197+ maxTries = 1 ;
194198 for ( ; tries < maxTries ; tries++)
195199 {
196200 log_d (" SD init failed. Trying again %d out of %d" , tries + 1 , maxTries);
@@ -315,6 +319,8 @@ void stopUART2Tasks()
315319
316320void beginFS ()
317321{
322+ #define FORMAT_LITTLEFS_IF_FAILED true
323+
318324 if (online.fs == false )
319325 {
320326 Serial.println (" Starting FS" );
0 commit comments