-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSDcard.ino
126 lines (111 loc) · 4.1 KB
/
SDcard.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//HSPI MOSI=13, MISO=12, CLK=14, CS=25
//VSPI MOSI=23, MISO=19, CLK=18, CS=25
void getFileNames() {
Serial.println("Looking for files");
File root;
root = SD.open("/");
while (true) {
File entry = root.openNextFile();
if (! entry) {
// no more files
break;
}
char *pointerTobootloaderKey = strstr(entry.name(), bootloaderKey);//go find keyword
if (pointerTobootloaderKey != NULL) {
char *pointerToHiddenFile = strstr(entry.name(), hiddenFileKey);
if (pointerToHiddenFile == NULL) {//good not hidden file
Serial.print("Found Bootloader File: ");
strncpy(bootloaderName, entry.name(), sizeof(bootloaderName));
Serial.println(bootloaderName);
}
}
char *pointerTobootKey = strstr(entry.name(), bootKey);//go find keyword
if (pointerTobootKey != NULL) {
char *pointerToHiddenFile = strstr(entry.name(), hiddenFileKey);
if (pointerToHiddenFile == NULL) {//good not hidden file
Serial.print("Found Boot File: ");
strncpy(bootName, entry.name(), sizeof(bootName));
Serial.println(bootName);
}
}
char *pointerToPartitionsKey = strstr(entry.name(), partitionsKey);//go find keyword
if (pointerToPartitionsKey != NULL) {
char *pointerToHiddenFile = strstr(entry.name(), hiddenFileKey);
if (pointerToHiddenFile == NULL) {//good not hidden file
Serial.print("Found Partitions File: ");
strncpy(partitionsName, entry.name(), sizeof(partitionsName));
Serial.println(partitionsName);
}
}
char *pointerToFirmwareKey = strstr(entry.name(), firmwareKey);//go find keyword
if (pointerToFirmwareKey != NULL) {
char *pointerToHiddenFile = strstr(entry.name(), hiddenFileKey);
if (pointerToHiddenFile == NULL) {//good not hidden file
Serial.print("Found Firmware File: ");
strncpy(firmwareName, entry.name(), sizeof(firmwareName));
Serial.println(firmwareName);
}
}
char *pointerToFirmwareSecondKey = strstr(entry.name(), firmwareSecondKey);//go find keyword
if (pointerToFirmwareSecondKey != NULL) {
char *pointerToHiddenFile = strstr(entry.name(), hiddenFileKey);
if (pointerToHiddenFile == NULL) {//good not hidden file
Serial.print("Found Firmware File: ");
strncpy(firmwareName, entry.name(), sizeof(firmwareName));
Serial.println(firmwareName);
}
}
char *pointerToSPIFFSKey = strstr(entry.name(), SPIFFSKey);//go find keyword
if (pointerToSPIFFSKey != NULL) {
char *pointerToHiddenFile = strstr(entry.name(), hiddenFileKey);
if (pointerToHiddenFile == NULL) {//good not hidden file
Serial.print("Found SPIFFS File: ");
strncpy(spiffsName, entry.name(), sizeof(spiffsName));
Serial.println(spiffsName);
flashSPIFFS = true;
}
}
Serial.println(entry.name());
// if (entry.isDirectory()) {
// Serial.println("/");
// //printDirectory(entry, numTabs + 1);
// } else {
// // files have sizes, directories do not
// Serial.print("\t\t");
// Serial.println(entry.size(), DEC);
// }
entry.close();
}
}
void initSDcard() {
//spiSD.begin(14, 12, 13, SD_CS); //SCK,MISO,MOSI,SS //HSPI1
spiSD.begin(18, 19, 23, SD_CS_pin); //SCK,MISO,MOSI,SS //HSPI1
while (!SD.begin( SD_CS_pin, spiSD ))
{
Serial.println("Card Mount Failed");
delay(1000);
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
getFileNames();
if (bootName[0] == NULL || bootloaderName[0] == NULL || partitionsName[0] == NULL || firmwareName[0] == NULL) {
Serial.println("ERROR - not all files found!!!");
while (1) {
}
}
}