Skip to content

Commit f9ca28a

Browse files
committed
Fix new file create bug.
The newFileName array was too small. The unit would attempt to find a new file name and then record a much larger file name into the array corrupting the RAM. This was regularly called when the unit was awaking between power cycles and seems to be the main culprit behind the lack of logging in issue #2. It doesn't seem to be related to exFat or variability between cards.
1 parent ef33b88 commit f9ca28a

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Firmware/OpenLog_Artemis/logging.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
void msg(const char * message)
33
{
44
Serial.println(message);
5-
if(online.microSD)
5+
if (online.microSD)
66
sensorDataFile.println(message);
77
}
88

@@ -17,15 +17,16 @@ char* findNextAvailableLog(int &newFileNumber, const char *fileLeader)
1717
newFileNumber--; //Check if last log file was empty
1818

1919
//Search for next available log spot
20-
static char newFileName[13];
20+
static char newFileName[40];
2121
while (1)
2222
{
2323
sprintf(newFileName, "%s%05u.TXT", fileLeader, newFileNumber); //Splice the new file number into this file name
2424

2525
if (sd.exists(newFileName) == false) break; //File name not found so we will use it.
2626

2727
//File exists so open and see if it is empty. If so, use it.
28-
newFile.open(newFileName, O_READ);
28+
//newFile = sd.open(newFileName, O_READ);
29+
newFile.open(newFileName, O_READ); //exFat
2930
if (newFile.size() == 0) break; // File is empty so we will use it.
3031

3132
newFile.close(); // Close this existing file we just opened.

Firmware/OpenLog_Artemis/lowerPower.ino

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ void goToSleep()
7777
if (online.dataLogging == true)
7878
{
7979
sensorDataFile.sync();
80-
//sensorDataFile.close(); //No need to close files. https://forum.arduino.cc/index.php?topic=149504.msg1125098#msg1125098
80+
sensorDataFile.close(); //No need to close files. https://forum.arduino.cc/index.php?topic=149504.msg1125098#msg1125098
8181
}
8282
if (online.serialLogging == true)
8383
{
8484
serialDataFile.sync();
85-
//serialDataFile.close();
85+
serialDataFile.close();
8686
}
8787

8888
Serial.flush(); //Finish any prints
@@ -108,14 +108,16 @@ void goToSleep()
108108
am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_UART0);
109109
am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_UART1);
110110

111-
112111
//Disable all pads
113112
for (int x = 0 ; x < 50 ; x++)
114113
am_hal_gpio_pinconfig(x, g_AM_HAL_GPIO_DISABLE);
115114

116115
//We can't leave these power control pins floating
117116
imuPowerOff();
118-
microSDPowerOff();
117+
//microSDPowerOff();
118+
119+
//Testing file record issues
120+
microSDPowerOn();
119121

120122
//Keep Qwiic bus powered on if user desires it
121123
if (settings.powerDownQwiicBusBetweenReads == true)
@@ -191,12 +193,8 @@ void wakeFromSleep()
191193

192194
beginSD(); //285 - 293ms
193195

194-
//loadSettings(); //50 - 250ms
195-
196196
beginQwiic();
197197

198-
//analogReadResolution(14); //Increase from default of 10
199-
200198
beginDataLogging(); //180ms
201199

202200
beginSerialLogging(); //20 - 99ms

Firmware/OpenLog_Artemis/nvm.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void recordSettingsToFile()
4646
if (sd.exists("OLA_settings.cfg"))
4747
sd.remove("OLA_settings.cfg");
4848

49-
FsFile settingsFile;
49+
//File settingsFile; //FAT16/32
50+
FsFile settingsFile; //exFat
5051
if (settingsFile.open("OLA_settings.cfg", O_CREAT | O_APPEND | O_WRITE) == false)
5152
{
5253
Serial.println("Failed to create settings file");
@@ -116,7 +117,8 @@ bool loadSettingsFromFile()
116117
{
117118
if (sd.exists("OLA_settings.cfg"))
118119
{
119-
FsFile settingsFile;
120+
//File settingsFile; //FAT16/32
121+
FsFile settingsFile; //exFat
120122
if (settingsFile.open("OLA_settings.cfg", O_READ) == false)
121123
{
122124
Serial.println("Failed to open settings file");

0 commit comments

Comments
 (0)