Skip to content

Commit a3ce44e

Browse files
committed
Delete settings.enableSD - see issue #104
enableSD is redundant. If the microSD card is present, it needs to be powered up. Otherwise it will pull the SPI lines low, preventing the IMU from starting.
1 parent d51a4ba commit a3ce44e

File tree

5 files changed

+70
-82
lines changed

5 files changed

+70
-82
lines changed

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 67 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -645,58 +645,55 @@ void loop() {
645645
Serial1.print(outputData); //Print to TX pin
646646

647647
//Record to SD
648-
if (settings.logData == true)
648+
if ((settings.logData == true) && (online.microSD))
649649
{
650-
if (settings.enableSD && online.microSD)
650+
digitalWrite(PIN_STAT_LED, HIGH);
651+
uint32_t recordLength = sensorDataFile.write(outputData, strlen(outputData));
652+
if (recordLength != strlen(outputData)) //Record the buffer to the card
651653
{
652-
digitalWrite(PIN_STAT_LED, HIGH);
653-
uint32_t recordLength = sensorDataFile.write(outputData, strlen(outputData));
654-
if (recordLength != strlen(outputData)) //Record the buffer to the card
654+
if (settings.printDebugMessages == true)
655655
{
656-
if (settings.printDebugMessages == true)
657-
{
658-
SerialPrintf3("*** sensorDataFile.write data length mismatch! *** recordLength: %d, outputDataLength: %d\r\n", recordLength, strlen(outputData));
659-
}
656+
SerialPrintf3("*** sensorDataFile.write data length mismatch! *** recordLength: %d, outputDataLength: %d\r\n", recordLength, strlen(outputData));
660657
}
658+
}
659+
660+
//Force sync every 500ms
661+
if (bestMillis() - lastDataLogSyncTime > 500)
662+
{
663+
lastDataLogSyncTime = bestMillis();
664+
sensorDataFile.sync();
665+
if (settings.frequentFileAccessTimestamps == true)
666+
updateDataFileAccess(&sensorDataFile); // Update the file access time & date
667+
}
661668

662-
//Force sync every 500ms
663-
if (bestMillis() - lastDataLogSyncTime > 500)
669+
//Check if it is time to open a new log file
670+
uint64_t secsSinceLastFileNameChange = rtcMillis() - lastSDFileNameChangeTime; // Calculate how long we have been logging for
671+
secsSinceLastFileNameChange /= 1000ULL; // Convert to secs
672+
if ((settings.openNewLogFilesAfter > 0) && (((unsigned long)secsSinceLastFileNameChange) >= settings.openNewLogFilesAfter))
673+
{
674+
//Close existings files
675+
if (online.dataLogging == true)
664676
{
665-
lastDataLogSyncTime = bestMillis();
666677
sensorDataFile.sync();
667-
if (settings.frequentFileAccessTimestamps == true)
668-
updateDataFileAccess(&sensorDataFile); // Update the file access time & date
678+
updateDataFileAccess(&sensorDataFile); // Update the file access time & date
679+
sensorDataFile.close();
680+
strcpy(sensorDataFileName, findNextAvailableLog(settings.nextDataLogNumber, "dataLog"));
681+
beginDataLogging(); //180ms
682+
if (settings.showHelperText == true) printHelperText(false); //printHelperText to terminal and sensor file
669683
}
670-
671-
//Check if it is time to open a new log file
672-
uint64_t secsSinceLastFileNameChange = rtcMillis() - lastSDFileNameChangeTime; // Calculate how long we have been logging for
673-
secsSinceLastFileNameChange /= 1000ULL; // Convert to secs
674-
if ((settings.openNewLogFilesAfter > 0) && (((unsigned long)secsSinceLastFileNameChange) >= settings.openNewLogFilesAfter))
684+
if (online.serialLogging == true)
675685
{
676-
//Close existings files
677-
if (online.dataLogging == true)
678-
{
679-
sensorDataFile.sync();
680-
updateDataFileAccess(&sensorDataFile); // Update the file access time & date
681-
sensorDataFile.close();
682-
strcpy(sensorDataFileName, findNextAvailableLog(settings.nextDataLogNumber, "dataLog"));
683-
beginDataLogging(); //180ms
684-
if (settings.showHelperText == true) printHelperText(false); //printHelperText to terminal and sensor file
685-
}
686-
if (online.serialLogging == true)
687-
{
688-
serialDataFile.sync();
689-
updateDataFileAccess(&serialDataFile); // Update the file access time & date
690-
serialDataFile.close();
691-
strcpy(serialDataFileName, findNextAvailableLog(settings.nextSerialLogNumber, "serialLog"));
692-
beginSerialLogging();
693-
}
694-
695-
lastSDFileNameChangeTime = rtcMillis(); // Record the time of the file name change
686+
serialDataFile.sync();
687+
updateDataFileAccess(&serialDataFile); // Update the file access time & date
688+
serialDataFile.close();
689+
strcpy(serialDataFileName, findNextAvailableLog(settings.nextSerialLogNumber, "serialLog"));
690+
beginSerialLogging();
696691
}
697692

698-
digitalWrite(PIN_STAT_LED, LOW);
693+
lastSDFileNameChangeTime = rtcMillis(); // Record the time of the file name change
699694
}
695+
696+
digitalWrite(PIN_STAT_LED, LOW);
700697
}
701698

702699
if ((settings.useGPIO32ForStopLogging == true) && (stopLoggingSeen == true)) // Has the user pressed the stop logging button?
@@ -892,56 +889,51 @@ void beginSD()
892889
pin_config(PinName(PIN_MICROSD_CHIP_SELECT), g_AM_HAL_GPIO_OUTPUT); // Make sure the pin does actually get re-configured
893890
digitalWrite(PIN_MICROSD_CHIP_SELECT, HIGH); //Be sure SD is deselected
894891

895-
if (settings.enableSD == true)
896-
{
897-
// For reasons I don't understand, we seem to have to wait for at least 1ms after SPI.begin before we call microSDPowerOn.
898-
// If you comment the next line, the Artemis resets at microSDPowerOn when beginSD is called from wakeFromSleep...
899-
// But only on one of my V10 red boards. The second one I have doesn't seem to need the delay!?
900-
delay(5);
892+
// If the microSD card is present, it needs to be powered on otherwise the IMU will fail to start
893+
// (The microSD card will pull the SPI pins low, preventing communication with the IMU)
894+
895+
// For reasons I don't understand, we seem to have to wait for at least 1ms after SPI.begin before we call microSDPowerOn.
896+
// If you comment the next line, the Artemis resets at microSDPowerOn when beginSD is called from wakeFromSleep...
897+
// But only on one of my V10 red boards. The second one I have doesn't seem to need the delay!?
898+
delay(5);
901899

902-
microSDPowerOn();
900+
microSDPowerOn();
903901

904-
//Max power up time is 250ms: https://www.kingston.com/datasheets/SDCIT-specsheet-64gb_en.pdf
905-
//Max current is 200mA average across 1s, peak 300mA
906-
for (int i = 0; i < 10; i++) //Wait
902+
//Max power up time is 250ms: https://www.kingston.com/datasheets/SDCIT-specsheet-64gb_en.pdf
903+
//Max current is 200mA average across 1s, peak 300mA
904+
for (int i = 0; i < 10; i++) //Wait
905+
{
906+
checkBattery();
907+
delay(1);
908+
}
909+
910+
if (sd.begin(SD_CONFIG) == false) // Try to begin the SD card using the correct chip select
911+
{
912+
printDebug(F("SD init failed (first attempt). Trying again...\r\n"));
913+
for (int i = 0; i < 250; i++) //Give SD more time to power up, then try again
907914
{
908915
checkBattery();
909916
delay(1);
910917
}
911-
912918
if (sd.begin(SD_CONFIG) == false) // Try to begin the SD card using the correct chip select
913919
{
914-
printDebug(F("SD init failed (first attempt). Trying again...\r\n"));
915-
for (int i = 0; i < 250; i++) //Give SD more time to power up, then try again
916-
{
917-
checkBattery();
918-
delay(1);
919-
}
920-
if (sd.begin(SD_CONFIG) == false) // Try to begin the SD card using the correct chip select
921-
{
922-
SerialPrintln(F("SD init failed (second attempt). Is card present? Formatted?"));
923-
SerialPrintln(F("Please ensure the SD card is formatted correctly using https://www.sdcard.org/downloads/formatter/"));
924-
digitalWrite(PIN_MICROSD_CHIP_SELECT, HIGH); //Be sure SD is deselected
925-
online.microSD = false;
926-
return;
927-
}
928-
}
929-
930-
//Change to root directory. All new file creation will be in root.
931-
if (sd.chdir() == false)
932-
{
933-
SerialPrintln(F("SD change directory failed"));
920+
SerialPrintln(F("SD init failed (second attempt). Is card present? Formatted?"));
921+
SerialPrintln(F("Please ensure the SD card is formatted correctly using https://www.sdcard.org/downloads/formatter/"));
922+
digitalWrite(PIN_MICROSD_CHIP_SELECT, HIGH); //Be sure SD is deselected
934923
online.microSD = false;
935924
return;
936925
}
937-
938-
online.microSD = true;
939926
}
940-
else
927+
928+
//Change to root directory. All new file creation will be in root.
929+
if (sd.chdir() == false)
941930
{
942-
microSDPowerOff();
931+
SerialPrintln(F("SD change directory failed"));
943932
online.microSD = false;
933+
return;
944934
}
935+
936+
online.microSD = true;
945937
}
946938

947939
void enableCIPOpullUp() // updated for v2.1.0 of the Apollo3 core

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ void printHelperText(bool terminalOnly)
15411541
strcat(helperText, "\r\n");
15421542

15431543
SerialPrint(helperText);
1544-
if ((terminalOnly == false) && (settings.logData == true) && (online.microSD) && (settings.enableSD && online.microSD))
1544+
if ((terminalOnly == false) && (settings.logData == true) && (online.microSD))
15451545
sensorDataFile.print(helperText);
15461546
}
15471547

Firmware/OpenLog_Artemis/menuMain.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void menuMain()
2525

2626
SerialPrintln(F("h) Print Sensor Helper Text (and return to logging)"));
2727

28-
if (settings.enableSD && online.microSD)
28+
if (online.microSD)
2929
SerialPrintln(F("s) SD Card File Transfer"));
3030

3131
SerialPrintln(F("r) Reset all settings to default"));
@@ -61,7 +61,7 @@ void menuMain()
6161
menuDebug();
6262
else if (incoming == 's')
6363
{
64-
if (settings.enableSD && online.microSD)
64+
if (online.microSD)
6565
{
6666
//Close log files before showing sdCardMenu
6767
if (online.dataLogging == true)

Firmware/OpenLog_Artemis/nvm.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ void recordSystemSettingsToFile()
113113
settingsFile.println("logMaxRate=" + (String)settings.logMaxRate);
114114
settingsFile.println("enableRTC=" + (String)settings.enableRTC);
115115
settingsFile.println("enableIMU=" + (String)settings.enableIMU);
116-
settingsFile.println("enableSD=" + (String)settings.enableSD);
117116
settingsFile.println("enableTerminalOutput=" + (String)settings.enableTerminalOutput);
118117
settingsFile.println("logDate=" + (String)settings.logDate);
119118
settingsFile.println("logTime=" + (String)settings.logTime);
@@ -325,8 +324,6 @@ bool parseLine(char* str) {
325324
settings.enableRTC = d;
326325
else if (strcmp(settingName, "enableIMU") == 0)
327326
settings.enableIMU = d;
328-
else if (strcmp(settingName, "enableSD") == 0)
329-
settings.enableSD = d;
330327
else if (strcmp(settingName, "enableTerminalOutput") == 0)
331328
settings.enableTerminalOutput = d;
332329
else if (strcmp(settingName, "logDate") == 0)

Firmware/OpenLog_Artemis/settings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ struct struct_settings {
352352
bool logMaxRate = false;
353353
bool enableRTC = true;
354354
bool enableIMU = true;
355-
bool enableSD = true;
356355
bool enableTerminalOutput = true;
357356
bool logDate = true;
358357
bool logTime = true;

0 commit comments

Comments
 (0)