Skip to content

Commit 33c41d1

Browse files
committed
Modify SD quick tests to prevent false negatives
1 parent 4177e83 commit 33c41d1

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

316320
void beginFS()
317321
{
322+
#define FORMAT_LITTLEFS_IF_FAILED true
323+
318324
if (online.fs == false)
319325
{
320326
Serial.println("Starting FS");

Firmware/RTK_Surveyor/SD.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool sdPresent(void)
4848

4949
//Sending clocks while card power stabilizes...
5050
deselectCard(); // always make sure
51-
for (byte i = 0; i < 10; i++) // send several clocks while card power stabilizes
51+
for (byte i = 0; i < 30; i++) // send several clocks while card power stabilizes
5252
xchg(0xff);
5353

5454
//Sending CMD0 - GO IDLE...
@@ -106,7 +106,7 @@ byte sdSendCommand(byte command, unsigned long arg)
106106
if (command == SD_SEND_IF_COND) crc = 0x87; // special case, have to use different CRC
107107
xchg(crc); // send final byte
108108

109-
for (int i = 0; i < 10; i++) // loop until timeout or response
109+
for (int i = 0; i < 30; i++) // loop until timeout or response
110110
{
111111
response = xchg(0xFF);
112112
if ((response & 0x80) == 0) break; // high bit cleared means we got a response

0 commit comments

Comments
 (0)