Skip to content

Commit

Permalink
Particle Gen3 support with POSIX open flags
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed Dec 28, 2018
1 parent f0c65da commit 7417ee9
Show file tree
Hide file tree
Showing 464 changed files with 26,302 additions and 14,331 deletions.
46 changes: 15 additions & 31 deletions README.md
Expand Up @@ -5,42 +5,26 @@ SdFat requires Arduino 1.6x or greater.

Key changes:

The SPI divisor has been replaced by SPISettings in the begin() call.
Support for multiple SPI ports now uses a pointer to a SPIClass object.

See the STM32Test example.
```
bool begin(uint8_t csPin = SS, SPISettings spiSettings = SPI_FULL_SPEED);
explicit SdFat(SPIClass* spiPort);
\\ or
explicit SdFatEX(SPIClass* spiPort);
```

Several macros have been defined for backward compatibility.

```
#define SD_SCK_MHZ(maxMhz) SPISettings(1000000UL*maxMhz, MSBFIRST, SPI_MODE0)
// SPI divisor constants
/** Set SCK to max possible rate. */
#define SPI_FULL_SPEED SD_SCK_MHZ(50)
/** Set SCK rate to F_CPU/3 for Due */
#define SPI_DIV3_SPEED SD_SCK_HZ(F_CPU/3)
/** Set SCK rate to F_CPU/4. */
#define SPI_HALF_SPEED SD_SCK_HZ(F_CPU/4)
// ...
```
Open flags now follow POSIX conventions. O_RDONLY is the same as O_READ and O_WRONLY is the
same as O_WRITE. One and only one of of the mode flags, O_RDONLY, O_RDWR, or
O_WRONLY is required.

Open flags for Particle Gen3 and ARM boards are now defined by fcntl.h.
See SdFatConfig.h for options.

There are two new classes, SdFatEX and SdFatSoftSpiEX.
Support for particle Gen3 devices.

Teensy 3.5/3.6 SDIO support has been added. Try the TeensySdioDemo example.
Many other example will work with Teensy SDIO if you use the SdFatSdio classes
and call begin with no parameters.
New cluster allocation algorithm.

```
SdFatSdio sd;
....
if (!sd.begin()) {
// Handle failure.
}
```
Please read changes.txt and the html documentation in the extras folder for more information.

Please report problems as issues.
Expand All @@ -53,6 +37,6 @@ html/index.html and read the Main Page. Next go to the Classes tab and
read the documentation for the classes SdFat, SdFatEX, SdBaseFile,
SdFile, File, StdioStream, ifstream, ofstream, and others.

Please continue by reading the html documentation.
Please continue by reading the html documentation in SdFat/extras/html

Updated 26 Apr 2017
Updated 28 Dec 2018
2 changes: 1 addition & 1 deletion examples/#attic/fgetsRewrite/fgetsRewrite.ino
Expand Up @@ -66,7 +66,7 @@ void demoFgets() {
//------------------------------------------------------------------------------
void makeTestFile() {
// create or open test file
SdFile wrfile("fgets.txt", O_WRITE | O_CREAT | O_TRUNC);
SdFile wrfile("fgets.txt", O_WRONLY | O_CREAT | O_TRUNC);

// check for open error
if (!wrfile.isOpen()) {
Expand Down
6 changes: 3 additions & 3 deletions examples/DirectoryFunctions/DirectoryFunctions.ino
Expand Up @@ -53,7 +53,7 @@ void setup() {

int rootFileCount = 0;
sd.vwd()->rewind();
while (file.openNext(sd.vwd(), O_READ)) {
while (file.openNext(sd.vwd(), O_RDONLY)) {
if (!file.isHidden()) {
rootFileCount++;
}
Expand All @@ -73,7 +73,7 @@ void setup() {
cout << F("Created Folder1\n");

// Create a file in Folder1 using a path.
if (!file.open("Folder1/file1.txt", O_CREAT | O_WRITE)) {
if (!file.open("Folder1/file1.txt", O_WRONLY | O_CREAT)) {
error("create Folder1/file1.txt failed");
}
file.close();
Expand All @@ -86,7 +86,7 @@ void setup() {
cout << F("chdir to Folder1\n");

// Create File2.txt in current directory.
if (!file.open("File2.txt", O_CREAT | O_WRITE)) {
if (!file.open("File2.txt", O_WRONLY | O_CREAT)) {
error("create File2.txt failed");
}
file.close();
Expand Down
6 changes: 3 additions & 3 deletions examples/LongFileName/LongFileName.ino
Expand Up @@ -41,10 +41,10 @@ void setup() {
Serial.println();

// List files in root directory.
if (!dirFile.open("/", O_READ)) {
if (!dirFile.open("/", O_RDONLY)) {
sd.errorHalt("open root failed");
}
while (n < nMax && file.openNext(&dirFile, O_READ)) {
while (n < nMax && file.openNext(&dirFile, O_RDONLY)) {

// Skip directories and hidden files.
if (!file.isSubDir() && !file.isHidden()) {
Expand Down Expand Up @@ -81,7 +81,7 @@ void loop() {
return;
}
Serial.println(i);
if (!file.open(&dirFile, dirIndex[i], O_READ)) {
if (!file.open(&dirFile, dirIndex[i], O_RDONLY)) {
sd.errorHalt(F("open"));
}
Serial.println();
Expand Down
4 changes: 2 additions & 2 deletions examples/LowLatencyLogger/LowLatencyLogger.ino
Expand Up @@ -197,7 +197,7 @@ void binaryToCsv() {
strcpy(csvName, binName);
strcpy(&csvName[BASE_NAME_SIZE + 3], "csv");

if (!csvFile.open(csvName, O_WRITE | O_CREAT | O_TRUNC)) {
if (!csvFile.open(csvName, O_WRONLY | O_CREAT | O_TRUNC)) {
error("open csvFile failed");
}
binFile.rewind();
Expand Down Expand Up @@ -338,7 +338,7 @@ void openBinFile() {
}
binFile.close();
strcpy(binName, name);
if (!binFile.open(binName, O_READ)) {
if (!binFile.open(binName, O_RDONLY)) {
Serial.println(F("open failed"));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/LowLatencyLoggerADXL345/LowLatencyLogger.ino
Expand Up @@ -197,7 +197,7 @@ void binaryToCsv() {
strcpy(csvName, binName);
strcpy(&csvName[BASE_NAME_SIZE + 3], "csv");

if (!csvFile.open(csvName, O_WRITE | O_CREAT | O_TRUNC)) {
if (!csvFile.open(csvName, O_WRONLY | O_CREAT | O_TRUNC)) {
error("open csvFile failed");
}
binFile.rewind();
Expand Down Expand Up @@ -338,7 +338,7 @@ void openBinFile() {
}
binFile.close();
strcpy(binName, name);
if (!binFile.open(binName, O_READ)) {
if (!binFile.open(binName, O_RDONLY)) {
Serial.println(F("open failed"));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/LowLatencyLoggerMPU6050/LowLatencyLogger.ino
Expand Up @@ -197,7 +197,7 @@ void binaryToCsv() {
strcpy(csvName, binName);
strcpy(&csvName[BASE_NAME_SIZE + 3], "csv");

if (!csvFile.open(csvName, O_WRITE | O_CREAT | O_TRUNC)) {
if (!csvFile.open(csvName, O_WRONLY | O_CREAT | O_TRUNC)) {
error("open csvFile failed");
}
binFile.rewind();
Expand Down Expand Up @@ -338,7 +338,7 @@ void openBinFile() {
}
binFile.close();
strcpy(binName, name);
if (!binFile.open(binName, O_READ)) {
if (!binFile.open(binName, O_RDONLY)) {
Serial.println(F("open failed"));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/OpenNext/OpenNext.ino
Expand Up @@ -35,7 +35,7 @@ void setup() {
// Warning, openNext starts at the current position of sd.vwd() so a
// rewind may be neccessary in your application.
sd.vwd()->rewind();
while (file.openNext(sd.vwd(), O_READ)) {
while (file.openNext(sd.vwd(), O_RDONLY)) {
file.printFileSize(&Serial);
Serial.write(' ');
file.printModifyDateTime(&Serial);
Expand Down
2 changes: 1 addition & 1 deletion examples/PrintBenchmark/PrintBenchmark.ino
Expand Up @@ -65,7 +65,7 @@ void loop() {
char fileName[13] = "bench0.txt";
fileName[5] = '0' + test;
// open or create file - truncate existing file.
if (!file.open(fileName, O_CREAT | O_TRUNC | O_RDWR)) {
if (!file.open(fileName, O_RDWR | O_CREAT | O_TRUNC)) {
error("open failed");
}
maxLatency = 0;
Expand Down
12 changes: 7 additions & 5 deletions examples/STM32Test/STM32Test.ino
Expand Up @@ -9,13 +9,15 @@
// set ENABLE_EXTENDED_TRANSFER_CLASS non-zero to use faster EX classes

// Use first SPI port
SdFat sd1(1);
// SdFatEX sd1(1);
SdFat sd1;
// SdFatEX sd1;
const uint8_t SD1_CS = PA4; // chip select for sd1

// Use second SPI port
SdFat sd2(2);
// SdFatEX sd2(2);
SPIClass SPI_2(2);
SdFat sd2(&SPI_2);
// SdFatEX sd2(&SPI_2);

const uint8_t SD2_CS = PB12; // chip select for sd2

const uint8_t BUF_DIM = 100;
Expand Down Expand Up @@ -120,7 +122,7 @@ void setup() {

// create or open /Dir2/copy.bin and truncate it to zero length
SdFile file2;
if (!file2.open("copy.bin", O_WRITE | O_CREAT | O_TRUNC)) {
if (!file2.open("copy.bin", O_WRONLY | O_CREAT | O_TRUNC)) {
sd2.errorExit("file2");
}
Serial.println(F("Copying test.bin to copy.bin"));
Expand Down
2 changes: 1 addition & 1 deletion examples/SoftwareSpi/SoftwareSpi.ino
Expand Up @@ -36,7 +36,7 @@ void setup() {
sd.initErrorHalt();
}

if (!file.open("SoftSPI.txt", O_CREAT | O_RDWR)) {
if (!file.open("SoftSPI.txt", O_RDWR | O_CREAT)) {
sd.errorHalt(F("open failed"));
}
file.println(F("This line was printed using software SPI."));
Expand Down
2 changes: 1 addition & 1 deletion examples/StdioBench/StdioBench.ino
Expand Up @@ -53,7 +53,7 @@ void setup() {
for (uint8_t dataType = 0; dataType < 5; dataType++) {
for (uint8_t fileType = 0; fileType < 2; fileType++) {
if (!fileType) {
if (!printFile.open("print.txt", O_CREAT | O_RDWR | O_TRUNC)) {
if (!printFile.open("print.txt", O_RDWR | O_CREAT | O_TRUNC)) {
Serial.println(F("open fail"));
return;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/Timestamp/Timestamp.ino
Expand Up @@ -96,7 +96,7 @@ void setup(void) {
sd.remove("stamp.txt");

// create a new file with default timestamps
if (!file.open("default.txt", O_CREAT | O_WRITE)) {
if (!file.open("default.txt", O_WRONLY | O_CREAT)) {
error("open default.txt failed");
}
cout << F("\nOpen with default times\n");
Expand All @@ -119,7 +119,7 @@ void setup(void) {
SdFile::dateTimeCallback(dateTime);

// create a new file with callback timestamps
if (!file.open("callback.txt", O_CREAT | O_WRITE)) {
if (!file.open("callback.txt", O_WRONLY | O_CREAT)) {
error("open callback.txt failed");
}
cout << ("\nOpen with callback times\n");
Expand Down Expand Up @@ -151,7 +151,7 @@ void setup(void) {
SdFile::dateTimeCallbackCancel();

// create a new file with default timestamps
if (!file.open("stamp.txt", O_CREAT | O_WRITE)) {
if (!file.open("stamp.txt", O_WRONLY | O_CREAT)) {
error("open stamp.txt failed");
}
// set creation date time
Expand Down
2 changes: 1 addition & 1 deletion examples/TwoCards/TwoCards.ino
Expand Up @@ -117,7 +117,7 @@ void setup() {

// create or open /Dir2/copy.bin and truncate it to zero length
SdFile file2;
if (!file2.open("copy.bin", O_WRITE | O_CREAT | O_TRUNC)) {
if (!file2.open("copy.bin", O_WRONLY | O_CREAT | O_TRUNC)) {
sd2.errorExit("file2");
}
Serial.println(F("Copying test.bin to copy.bin"));
Expand Down
2 changes: 1 addition & 1 deletion examples/VolumeFreeSpace/VolumeFreeSpace.ino
Expand Up @@ -62,7 +62,7 @@ void setup() {
printFreeSpace();

cout << F("Create and write to ") << TEST_FILE << endl;
if (!file.open(TEST_FILE, O_WRITE | O_CREAT)) {
if (!file.open(TEST_FILE, O_WRONLY | O_CREAT)) {
sd.errorHalt(F("Create failed"));
}
file.print(F("Cause a cluster to be allocated"));
Expand Down
4 changes: 2 additions & 2 deletions examples/bench/bench.ino
Expand Up @@ -110,7 +110,7 @@ void loop() {
while (!Serial.available()) {
SysCall::yield();
}

cout << F("chipSelect: ") << int(chipSelect) << endl;
cout << F("FreeStack: ") << FreeStack() << endl;

#if USE_SDIO
Expand All @@ -131,7 +131,7 @@ void loop() {
cidDmp();

// open or create file - truncate existing file.
if (!file.open("bench.dat", O_CREAT | O_TRUNC | O_RDWR)) {
if (!file.open("bench.dat", O_RDWR | O_CREAT | O_TRUNC)) {
error("open failed");
}

Expand Down
2 changes: 1 addition & 1 deletion examples/dataLogger/dataLogger.ino
Expand Up @@ -99,7 +99,7 @@ void setup() {
error("Can't create file name");
}
}
if (!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) {
if (!file.open(fileName, O_WRONLY | O_CREAT | O_EXCL)) {
error("file.open");
}
// Read any Serial data.
Expand Down
4 changes: 2 additions & 2 deletions examples/fgets/fgets.ino
Expand Up @@ -17,7 +17,7 @@ void demoFgets() {
char line[25];
int n;
// open test file
SdFile rdfile("fgets.txt", O_READ);
SdFile rdfile("fgets.txt", O_RDONLY);

// check for open error
if (!rdfile.isOpen()) {
Expand All @@ -41,7 +41,7 @@ void demoFgets() {
//------------------------------------------------------------------------------
void makeTestFile() {
// create or open test file
SdFile wrfile("fgets.txt", O_WRITE | O_CREAT | O_TRUNC);
SdFile wrfile("fgets.txt", O_WRONLY | O_CREAT | O_TRUNC);

// check for open error
if (!wrfile.isOpen()) {
Expand Down
4 changes: 2 additions & 2 deletions examples/rename/rename.ino
Expand Up @@ -46,7 +46,7 @@ void setup() {
}
}
// create a file and write one line to the file
SdFile file("Name1.txt", O_WRITE | O_CREAT);
SdFile file("Name1.txt", O_WRONLY | O_CREAT);
if (!file.isOpen()) {
error("Name1.txt");
}
Expand Down Expand Up @@ -92,7 +92,7 @@ void setup() {
}

// open file for append in new location and add a line
if (!file.open("dir2/DIR3/NAME3.txt", O_WRITE | O_APPEND)) {
if (!file.open("dir2/DIR3/NAME3.txt", O_WRONLY | O_APPEND)) {
error("dir2/DIR3/NAME3.txt");
}
file.println("A line for dir2/DIR3/NAME3.txt");
Expand Down
8 changes: 4 additions & 4 deletions extras/MainPage/SdFatmainpage.h
@@ -1,5 +1,5 @@
/**
* Copyright (c) 20011-2017 Bill Greiman
* Copyright (c) 20011-2018 Bill Greiman
* This file is part of the SdFat library for SD memory cards.
*
* MIT License
Expand All @@ -24,7 +24,7 @@
*/
/**
\mainpage Arduino %SdFat Library
<CENTER>Copyright &copy; 2012, 2013, 2014, 2015, 2016 by William Greiman
<CENTER>Copyright &copy 2012-2018 by William Greiman
</CENTER>
\section Intro Introduction
Expand Down Expand Up @@ -222,7 +222,7 @@ the bug or problem.
The two example programs QuickStart, and SdInfo are useful for troubleshooting.
A message like this from SdInfo with erorCode 0X1 indicates the SD card
A message like this from SdInfo with errorCode 0X1 indicates the SD card
is not seen by SdFat. This is often caused by a wiring error and reformatting
the card will not solve the problem.
<PRE>
Expand Down Expand Up @@ -294,7 +294,7 @@ An application which writes to a file using print(), println() or
write() must close the file or call sync() at the appropriate time to
force data and directory information to be written to the SD Card.
Applications must use care calling sync() sync()
Applications must use care calling sync()
since 2048 bytes of I/O is required to update file and
directory information. This includes writing the current data block, reading
the block that contains the directory entry for update, writing the directory
Expand Down

0 comments on commit 7417ee9

Please sign in to comment.