| ### Warning: This beta version is now out of date. Use standard version of SdFat. | |||||
| ### Warning: This beta is for testing with Particle IoT mesh 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. | |||||
| This version of SdFat has been modified to use standard POSIX/Linux | |||||
| definitions of open flags from fcntl.h. | |||||
| ``` | |||||
| SdFatSdio sd; | |||||
| .... | |||||
| if (!sd.begin()) { | |||||
| // Handle failure. | |||||
| } | |||||
| ``` | |||||
| Recent versions of the Arduino IDE have bugs that may cause SdFat-beta to crash. | |||||
| https://forum.arduino.cc/index.php?topic=419264.0 | |||||
| SdFat-beta was tested using Arduino AVR boards 1.6.11. | |||||
| If you are using IDE 1.6.11 you must also install AVR boards 1.6.11, not | |||||
| 1.6.12 or 1.6.13. | |||||
| If you are using Arduino IDE 1.6.11, do Tools > Board > Boards Manager > Arduino AVR Boards > 1.6.11 > Install > Close. | |||||
| Key changes: | |||||
| Open flags are include access modes, O_RDONLY, O_RDWR, O_WRONLY, and modifiers | |||||
| O_APPEND, O_CREAT, O_EXCL, O_SYNC, O_TRUNC. | |||||
| The SPI divisor has been replaced by SPISettings. | |||||
| Rename this folder SdFat and place it in the standard place for libraries. | |||||
| There are two new classes, SdFatEX and SdFatSoftSpiEX. | |||||
| I tested with a particle CLI project with a SdFat in a lib | |||||
| Please read changes.txt and the html documentation for more information. | |||||
| Please report problems as issues. | |||||
| The Arduino SdFat library provides read/write access to FAT16/FAT32 | |||||
| file systems on SD/SDHC flash cards. | |||||
| SdFat requires Arduino 1.6x or greater. | |||||
| To use SdFat, unzip the download file and place the SdFat folder | |||||
| into the libraries sub-folder in your main sketch folder. | |||||
| For more information see the Manual installation section of this guide: | |||||
| ``` | |||||
| \Users\bill\Documents\Particle\projects\SdFatMod>ls * | |||||
| README.md argon_firmware_1545324931631.bin project.properties | |||||
| http://arduino.cc/en/Guide/Libraries | |||||
| lib: | |||||
| SdFat | |||||
| A number of configuration options can be set by editing SdFatConfig.h | |||||
| define macros. See the html documentation for details | |||||
| src: | |||||
| SdFatMod.ino | |||||
| ``` | |||||
| Read changes.txt if you have used previous releases of this library. | |||||
| The mods required changing the type for open flags from uint8_t to int so | |||||
| bugs are likely if any uint8_t local variables were missed. | |||||
| Please read the html documentation for this library. Start with | |||||
| 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. | |||||
| Updated 5 Sep 2016 |
| name=SdFat | |||||
| version=2016.7.24 | |||||
| author= | |||||
| maintainer= | |||||
| sentence=FAT16/FAT32 file system for SD cards. | |||||
| paragraph= | |||||
| category=Uncategorized | |||||
| url= | |||||
| architectures=* |
| /* Arduino SdFat Library | |||||
| * Copyright (C) 2016 by William Greiman | |||||
| * | |||||
| * This file is part of the Arduino SdFat Library | |||||
| * | |||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * | |||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the Arduino SdFat Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| */ | |||||
| /** | |||||
| * \file | |||||
| * \brief Define block driver. | |||||
| */ | |||||
| #ifndef BlockDriver_h | |||||
| #define BlockDriver_h | |||||
| #include "FatLib/BaseBlockDriver.h" | |||||
| #include "SdCard/SdSpiCard.h" | |||||
| //----------------------------------------------------------------------------- | |||||
| /** typedef for BlockDriver */ | |||||
| #if ENABLE_EXTENDED_TRANSFER_CLASS || ENABLE_SDIO_CLASS | |||||
| typedef BaseBlockDriver BlockDriver; | |||||
| #else // ENABLE_EXTENDED_TRANSFER_CLASS || ENABLE_SDIO_CLASS | |||||
| typedef SdSpiCard BlockDriver; | |||||
| #endif // ENABLE_EXTENDED_TRANSFER_CLASS || ENABLE_SDIO_CLASS | |||||
| #endif // BlockDriver_h |
| /* FatLib Library | |||||
| * Copyright (C) 2013 by William Greiman | |||||
| * | |||||
| * This file is part of the FatLib Library | |||||
| * | |||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * | |||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the FatLib Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| */ | |||||
| #ifndef FatApiConstants_h | |||||
| #define FatApiConstants_h | |||||
| //------------------------------------------------------------------------------ | |||||
| // use the gnu style oflag in open() | |||||
| /** open() oflag for reading */ | |||||
| const uint8_t O_READ = 0X01; | |||||
| /** open() oflag - same as O_IN */ | |||||
| const uint8_t O_RDONLY = O_READ; | |||||
| /** open() oflag for write */ | |||||
| const uint8_t O_WRITE = 0X02; | |||||
| /** open() oflag - same as O_WRITE */ | |||||
| const uint8_t O_WRONLY = O_WRITE; | |||||
| /** open() oflag for reading and writing */ | |||||
| const uint8_t O_RDWR = (O_READ | O_WRITE); | |||||
| /** open() oflag mask for access modes */ | |||||
| const uint8_t O_ACCMODE = (O_READ | O_WRITE); | |||||
| /** The file offset shall be set to the end of the file prior to each write. */ | |||||
| const uint8_t O_APPEND = 0X04; | |||||
| /** synchronous writes - call sync() after each write */ | |||||
| const uint8_t O_SYNC = 0X08; | |||||
| /** truncate the file to zero length */ | |||||
| const uint8_t O_TRUNC = 0X10; | |||||
| /** set the initial position at the end of the file */ | |||||
| const uint8_t O_AT_END = 0X20; | |||||
| /** create the file if nonexistent */ | |||||
| const uint8_t O_CREAT = 0X40; | |||||
| /** If O_CREAT and O_EXCL are set, open() shall fail if the file exists */ | |||||
| const uint8_t O_EXCL = 0X80; | |||||
| // FatFile class static and const definitions | |||||
| // flags for ls() | |||||
| /** ls() flag for list all files including hidden. */ | |||||
| const uint8_t LS_A = 1; | |||||
| /** ls() flag to print modify. date */ | |||||
| const uint8_t LS_DATE = 2; | |||||
| /** ls() flag to print file size. */ | |||||
| const uint8_t LS_SIZE = 4; | |||||
| /** ls() flag for recursive list of subdirectories */ | |||||
| const uint8_t LS_R = 8; | |||||
| // flags for timestamp | |||||
| /** set the file's last access date */ | |||||
| const uint8_t T_ACCESS = 1; | |||||
| /** set the file's creation date and time */ | |||||
| const uint8_t T_CREATE = 2; | |||||
| /** Set the file's write date and time */ | |||||
| const uint8_t T_WRITE = 4; | |||||
| #endif // FatApiConstants_h |
| /* FatLib Library | |||||
| * Copyright (C) 2013 by William Greiman | |||||
| * | |||||
| * This file is part of the FatLib Library | |||||
| * | |||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * | |||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the FatLib Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| */ | |||||
| #ifndef FatLib_h | |||||
| #define FatLib_h | |||||
| #include "ArduinoFiles.h" | |||||
| #include "ArduinoStream.h" | |||||
| #include "FatFileSystem.h" | |||||
| #include "FatLibConfig.h" | |||||
| #include "FatVolume.h" | |||||
| #include "FatFile.h" | |||||
| #include "StdioStream.h" | |||||
| #include "fstream.h" | |||||
| //------------------------------------------------------------------------------ | |||||
| /** FatFileSystem version YYYYMMDD */ | |||||
| #define FAT_LIB_VERSION 20150131 | |||||
| #endif // FatLib_h |
| /* FatLib Library | |||||
| * Copyright (C) 2013 by William Greiman | |||||
| * | |||||
| * This file is part of the FatLib Library | |||||
| * | |||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * | |||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the FatLib Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| */ | |||||
| #ifndef FmtNumber_h | |||||
| #define FmtNumber_h | |||||
| // #include <ctype.h> | |||||
| inline bool isDigit(char c) { | |||||
| return '0' <= c && c <= '9'; | |||||
| } | |||||
| inline bool isSpace(char c) { | |||||
| return c == ' ' || (0X9 <= c && c <= 0XD); | |||||
| } | |||||
| #include <math.h> | |||||
| #include <stdint.h> | |||||
| char* fmtDec(uint16_t n, char* p); | |||||
| char* fmtDec(uint32_t n, char* p); | |||||
| char* fmtFloat(float value, char* p, uint8_t prec); | |||||
| char* fmtFloat(float value, char* ptr, uint8_t prec, char expChar); | |||||
| char* fmtHex(uint32_t n, char* p); | |||||
| float scale10(float v, int8_t n); | |||||
| float scanFloat(const char* str, char** ptr); | |||||
| #endif // FmtNumber_h |
| /* Arduino SdFat Library | |||||
| * Copyright (C) 2015 by William Greiman | |||||
| * | |||||
| * This file is part of the Arduino SdFat Library | |||||
| * | |||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * | |||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the Arduino SdFat Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| */ | |||||
| #ifndef FreeStack_h | |||||
| #define FreeStack_h | |||||
| /** | |||||
| * \file | |||||
| * \brief FreeStack() function. | |||||
| */ | |||||
| #if defined(__AVR__) || defined(DOXYGEN) | |||||
| /** boundary between stack and heap. */ | |||||
| extern char *__brkval; | |||||
| /** End of bss section.*/ | |||||
| extern char __bss_end; | |||||
| /** Amount of free stack space. | |||||
| * \return The number of free bytes. | |||||
| */ | |||||
| static int FreeStack() { | |||||
| char* sp = reinterpret_cast<char*>(SP); | |||||
| return __brkval ? sp - __brkval : sp - &__bss_end; | |||||
| // char top; | |||||
| // return __brkval ? &top - __brkval : &top - &__bss_end; | |||||
| } | |||||
| #elif defined(PLATFORM_ID) // Particle board | |||||
| static int FreeStack() { | |||||
| return System.freeMemory(); | |||||
| } | |||||
| #elif defined(__arm__) | |||||
| extern "C" char* sbrk(int incr); | |||||
| static int FreeStack() { | |||||
| char top = 't'; | |||||
| return &top - reinterpret_cast<char*>(sbrk(0)); | |||||
| } | |||||
| #else | |||||
| #warning FreeStack is not defined for this system. | |||||
| static int FreeStack() { | |||||
| return 0; | |||||
| } | |||||
| #endif | |||||
| #endif // FreeStack_h |
| /* Arduino SdFat Library | |||||
| * Copyright (C) 2012 by William Greiman | |||||
| * | |||||
| * This file is part of the Arduino SdFat Library | |||||
| * | |||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * | |||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the Arduino SdFat Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| */ | |||||
| /** | |||||
| * \file | |||||
| * \brief Minimal AVR Serial driver. | |||||
| */ | |||||
| #ifndef MinimumSerial_h | |||||
| #define MinimumSerial_h | |||||
| #include "SysCall.h" | |||||
| //============================================================================== | |||||
| /** | |||||
| * \class MinimumSerial | |||||
| * \brief mini serial class for the %SdFat library. | |||||
| */ | |||||
| class MinimumSerial : public Print { | |||||
| public: | |||||
| /** \return true for hardware serial */ | |||||
| operator bool() { return true; } | |||||
| /** | |||||
| * \return one if data is available. | |||||
| */ | |||||
| int available(); | |||||
| /** | |||||
| * Set baud rate for serial port zero and enable in non interrupt mode. | |||||
| * Do not call this function if you use another serial library. | |||||
| * \param[in] baud rate | |||||
| */ | |||||
| void begin(uint32_t baud); | |||||
| /** Wait for write done. */ | |||||
| void flush(); | |||||
| /** | |||||
| * Unbuffered read | |||||
| * \return -1 if no character is available or an available character. | |||||
| */ | |||||
| int read(); | |||||
| /** | |||||
| * Unbuffered write | |||||
| * | |||||
| * \param[in] b byte to write. | |||||
| * \return 1 | |||||
| */ | |||||
| size_t write(uint8_t b); | |||||
| using Print::write; | |||||
| }; | |||||
| #endif // MinimumSerial_h |
| /* Arduino SdSpiAltDriver Library | |||||
| * Copyright (C) 2013 by William Greiman | |||||
| * | |||||
| * This file is part of the Arduino SdSpiAltDriver Library | |||||
| * | |||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * | |||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the Arduino SdSpiAltDriver Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| */ | |||||
| #if defined(__STM32F1__) | |||||
| #include "SdSpiDriver.h" | |||||
| #define USE_STM32F1_DMAC 1 | |||||
| //------------------------------------------------------------------------------ | |||||
| static SPIClass m_SPI1(1); | |||||
| #if BOARD_NR_SPI > 1 | |||||
| static SPIClass m_SPI2(2); | |||||
| #endif // BOARD_NR_SPI > 1 | |||||
| #if BOARD_NR_SPI > 2 | |||||
| static SPIClass m_SPI3(3); | |||||
| #endif // BOARD_NR_SPI > 2 | |||||
| // | |||||
| static SPIClass* pSpi[] = | |||||
| #if BOARD_NR_SPI == 1 | |||||
| {&m_SPI1}; | |||||
| #elif BOARD_NR_SPI == 2 | |||||
| {&m_SPI1, &m_SPI2}; | |||||
| #elif BOARD_NR_SPI == 3 | |||||
| {&m_SPI1, &m_SPI2, &m_SPI3}; | |||||
| #else // BOARD_NR_SPI | |||||
| #error "BOARD_NR_SPI too large" | |||||
| #endif // BOARD_NR_SPI | |||||
| //------------------------------------------------------------------------------ | |||||
| /** Set SPI options for access to SD/SDHC cards. | |||||
| * | |||||
| * \param[in] divisor SCK clock divider relative to the APB1 or APB2 clock. | |||||
| */ | |||||
| void SdSpiAltDriver::activate() { | |||||
| pSpi[m_spiPort]->beginTransaction(m_spiSettings); | |||||
| } | |||||
| //------------------------------------------------------------------------------ | |||||
| /** Initialize the SPI bus. | |||||
| * | |||||
| * \param[in] chipSelectPin SD card chip select pin. | |||||
| */ | |||||
| void SdSpiAltDriver::begin(uint8_t csPin) { | |||||
| m_csPin = csPin; | |||||
| pinMode(m_csPin, OUTPUT); | |||||
| digitalWrite(m_csPin, HIGH); | |||||
| pSpi[m_spiPort]->begin(); | |||||
| } | |||||
| //------------------------------------------------------------------------------ | |||||
| /** | |||||
| * End SPI transaction. | |||||
| */ | |||||
| void SdSpiAltDriver::deactivate() { | |||||
| pSpi[m_spiPort]->endTransaction(); | |||||
| } | |||||
| //------------------------------------------------------------------------------ | |||||
| /** Receive a byte. | |||||
| * | |||||
| * \return The byte. | |||||
| */ | |||||
| uint8_t SdSpiAltDriver::receive() { | |||||
| return pSpi[m_spiPort]->transfer(0XFF); | |||||
| } | |||||
| //------------------------------------------------------------------------------ | |||||
| /** Receive multiple bytes. | |||||
| * | |||||
| * \param[out] buf Buffer to receive the data. | |||||
| * \param[in] n Number of bytes to receive. | |||||
| * | |||||
| * \return Zero for no error or nonzero error code. | |||||
| */ | |||||
| uint8_t SdSpiAltDriver::receive(uint8_t* buf, size_t n) { | |||||
| int rtn = 0; | |||||
| #if USE_STM32F1_DMAC | |||||
| rtn = pSpi[m_spiPort]->dmaTransfer(0, const_cast<uint8*>(buf), n); | |||||
| #else // USE_STM32F1_DMAC | |||||
| // pSpi[m_spiPort]->read(buf, n); fails ?? use byte transfer | |||||
| for (size_t i = 0; i < n; i++) { | |||||
| buf[i] = pSpi[m_spiPort]->transfer(0XFF); | |||||
| } | |||||
| #endif // USE_STM32F1_DMAC | |||||
| return rtn; | |||||
| } | |||||
| //------------------------------------------------------------------------------ | |||||
| /** Send a byte. | |||||
| * | |||||
| * \param[in] b Byte to send | |||||
| */ | |||||
| void SdSpiAltDriver::send(uint8_t b) { | |||||
| pSpi[m_spiPort]->transfer(b); | |||||
| } | |||||
| //------------------------------------------------------------------------------ | |||||
| /** Send multiple bytes. | |||||
| * | |||||
| * \param[in] buf Buffer for data to be sent. | |||||
| * \param[in] n Number of bytes to send. | |||||
| */ | |||||
| void SdSpiAltDriver::send(const uint8_t* buf , size_t n) { | |||||
| #if USE_STM32F1_DMAC | |||||
| pSpi[m_spiPort]->dmaSend(const_cast<uint8*>(buf), n); | |||||
| #else // #if USE_STM32F1_DMAC | |||||
| pSpi[m_spiPort]->write(buf, n); | |||||
| #endif // USE_STM32F1_DMAC | |||||
| } | |||||
| //----------------------------------------------------------------------------- | |||||
| void SdSpiAltDriver::setPort(uint8_t portNumber) { | |||||
| m_spiPort = portNumber < 1 || portNumber > BOARD_NR_SPI ? 0 : portNumber -1; | |||||
| } | |||||
| #endif // defined(__STM32F1__) |
| /* Arduino SdFat Library | |||||
| * Copyright (C) 2011 by William Greiman | |||||
| * | |||||
| * This file is part of the Arduino SdFat Library | |||||
| * | |||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * | |||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the Arduino SdFat Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| */ | |||||
| #ifndef SdFatTestSuite_h | |||||
| #define SdFatTestSuite_h | |||||
| #include <SdFat.h> | |||||
| #include <SdFatUtil.h> | |||||
| #if defined(__arm__) && !defined(strcmp_P) | |||||
| #define strcmp_P(a, b) strcmp((a), (b)) | |||||
| #endif // strcmp_P | |||||
| #if defined(__arm__) && !defined(strncpy_P) | |||||
| #define strncpy_P(s, t, n) strncpy(s, t, n) | |||||
| #endif // strncpy_P | |||||
| #if defined(__arm__) && !defined(strlen_P) | |||||
| #define strlen_P(str) strlen(str) | |||||
| #endif // strlen_P | |||||
| #define testVerifyBool(result) testVerify_P(result, PSTR(#result)) | |||||
| #define testVerifyMsg(result, msg) testVerify_P(result, PSTR(msg)) | |||||
| #define testVerifyStr(result, expect) testVerify_P(result, PSTR(expect)) | |||||
| void testBegin(); | |||||
| void testEnd(); | |||||
| void testVerify_P(bool b, PGM_P msg); | |||||
| void testVerify_P(char* result, PGM_P expect); | |||||
| #endif // SdFatTestSuite_h |
| // uses RTClib from https://github.com/adafruit/RTClib | // uses RTClib from https://github.com/adafruit/RTClib | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| #include "FreeStack.h" | #include "FreeStack.h" | ||||
| #define SD_CHIP_SELECT SS // SD chip select pin | #define SD_CHIP_SELECT SS // SD chip select pin |
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // create a serial output stream | // create a serial output stream | ||||
| ArduinoOutStream cout(Serial); | ArduinoOutStream cout(Serial); |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD chip select pin | // SD chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD chip select pin | // SD chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // create a serial output stream | // create a serial output stream | ||||
| ArduinoOutStream cout(Serial); | ArduinoOutStream cout(Serial); |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // create serial output stream | // create serial output stream | ||||
| ArduinoOutStream cout(Serial); | ArduinoOutStream cout(Serial); |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD chip select pin | // SD chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; | ||||
| // Demo of rewriting a line read by fgets | // Demo of rewriting a line read by fgets | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD card chip select pin | // SD card chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; | ||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||
| void makeTestFile() { | void makeTestFile() { | ||||
| // create or open test file | // 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 | // check for open error | ||||
| if (!wrfile.isOpen()) { | if (!wrfile.isOpen()) { |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD chip select pin | // SD chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; |
| return; | return; | ||||
| } | } | ||||
| binFile.rewind(); | binFile.rewind(); | ||||
| if (!binFile.read(&buf , 512) == 512) { | |||||
| if (binFile.read(&buf , 512) != 512) { | |||||
| error("Read metadata failed"); | error("Read metadata failed"); | ||||
| } | } | ||||
| // Create a new csv file. | // Create a new csv file. | ||||
| binFile.rewind(); | binFile.rewind(); | ||||
| Serial.println(); | Serial.println(); | ||||
| Serial.println(F("Checking overrun errors - type any character to stop")); | Serial.println(F("Checking overrun errors - type any character to stop")); | ||||
| if (!binFile.read(&buf , 512) == 512) { | |||||
| if (binFile.read(&buf , 512) != 512) { | |||||
| error("Read metadata failed"); | error("Read metadata failed"); | ||||
| } | } | ||||
| bn++; | bn++; |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD card chip select pin. | // SD card chip select pin. | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; | ||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||
| int rootFileCount = 0; | int rootFileCount = 0; | ||||
| sd.vwd()->rewind(); | sd.vwd()->rewind(); | ||||
| while (file.openNext(sd.vwd(), O_READ)) { | |||||
| while (file.openNext(sd.vwd(), O_RDONLY)) { | |||||
| if (!file.isHidden()) { | if (!file.isHidden()) { | ||||
| rootFileCount++; | rootFileCount++; | ||||
| } | } | ||||
| cout << F("Created Folder1\n"); | cout << F("Created Folder1\n"); | ||||
| // Create a file in Folder1 using a path. | // 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"); | error("create Folder1/file1.txt failed"); | ||||
| } | } | ||||
| file.close(); | file.close(); | ||||
| cout << F("chdir to Folder1\n"); | cout << F("chdir to Folder1\n"); | ||||
| // Create File2.txt in current directory. | // 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"); | error("create File2.txt failed"); | ||||
| } | } | ||||
| file.close(); | file.close(); |
| Serial.println(); | Serial.println(); | ||||
| // List files in root directory. | // List files in root directory. | ||||
| if (!dirFile.open("/", O_READ)) { | |||||
| if (!dirFile.open("/", O_RDONLY)) { | |||||
| sd.errorHalt("open root failed"); | 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. | // Skip directories and hidden files. | ||||
| if (!file.isSubDir() && !file.isHidden()) { | if (!file.isSubDir() && !file.isHidden()) { | ||||
| return; | return; | ||||
| } | } | ||||
| Serial.println(i); | Serial.println(i); | ||||
| if (!file.open(&dirFile, dirIndex[i], O_READ)) { | |||||
| if (!file.open(&dirFile, dirIndex[i], O_RDONLY)) { | |||||
| sd.errorHalt(F("open")); | sd.errorHalt(F("open")); | ||||
| } | } | ||||
| Serial.println(); | Serial.println(); |
| strcpy(csvName, binName); | strcpy(csvName, binName); | ||||
| strcpy(&csvName[BASE_NAME_SIZE + 3], "csv"); | 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"); | error("open csvFile failed"); | ||||
| } | } | ||||
| binFile.rewind(); | binFile.rewind(); | ||||
| } | } | ||||
| binFile.close(); | binFile.close(); | ||||
| strcpy(binName, name); | strcpy(binName, name); | ||||
| if (!binFile.open(binName, O_READ)) { | |||||
| if (!binFile.open(binName, O_RDONLY)) { | |||||
| Serial.println(F("open failed")); | Serial.println(F("open failed")); | ||||
| return; | return; | ||||
| } | } |
| strcpy(csvName, binName); | strcpy(csvName, binName); | ||||
| strcpy(&csvName[BASE_NAME_SIZE + 3], "csv"); | 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"); | error("open csvFile failed"); | ||||
| } | } | ||||
| binFile.rewind(); | binFile.rewind(); | ||||
| } | } | ||||
| binFile.close(); | binFile.close(); | ||||
| strcpy(binName, name); | strcpy(binName, name); | ||||
| if (!binFile.open(binName, O_READ)) { | |||||
| if (!binFile.open(binName, O_RDONLY)) { | |||||
| Serial.println(F("open failed")); | Serial.println(F("open failed")); | ||||
| return; | return; | ||||
| } | } |
| strcpy(csvName, binName); | strcpy(csvName, binName); | ||||
| strcpy(&csvName[BASE_NAME_SIZE + 3], "csv"); | 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"); | error("open csvFile failed"); | ||||
| } | } | ||||
| binFile.rewind(); | binFile.rewind(); | ||||
| } | } | ||||
| binFile.close(); | binFile.close(); | ||||
| strcpy(binName, name); | strcpy(binName, name); | ||||
| if (!binFile.open(binName, O_READ)) { | |||||
| if (!binFile.open(binName, O_RDONLY)) { | |||||
| Serial.println(F("open failed")); | Serial.println(F("open failed")); | ||||
| return; | return; | ||||
| } | } |
| // Warning, openNext starts at the current position of sd.vwd() so a | // Warning, openNext starts at the current position of sd.vwd() so a | ||||
| // rewind may be neccessary in your application. | // rewind may be neccessary in your application. | ||||
| sd.vwd()->rewind(); | sd.vwd()->rewind(); | ||||
| while (file.openNext(sd.vwd(), O_READ)) { | |||||
| while (file.openNext(sd.vwd(), O_RDONLY)) { | |||||
| file.printFileSize(&Serial); | file.printFileSize(&Serial); | ||||
| Serial.write(' '); | Serial.write(' '); | ||||
| file.printModifyDateTime(&Serial); | file.printModifyDateTime(&Serial); |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| #include "FreeStack.h" | #include "FreeStack.h" | ||||
| // SD chip select pin | // SD chip select pin | ||||
| char fileName[13] = "bench0.txt"; | char fileName[13] = "bench0.txt"; | ||||
| fileName[5] = '0' + test; | fileName[5] = '0' + test; | ||||
| // open or create file - truncate existing file. | // 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"); | error("open failed"); | ||||
| } | } | ||||
| maxLatency = 0; | maxLatency = 0; |
| // | // | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // | // | ||||
| // Set DISABLE_CHIP_SELECT to disable a second SPI device. | // Set DISABLE_CHIP_SELECT to disable a second SPI device. | ||||
| // For example, with the Ethernet shield, set DISABLE_CHIP_SELECT | // For example, with the Ethernet shield, set DISABLE_CHIP_SELECT |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| #include "FreeStack.h" | #include "FreeStack.h" | ||||
| // SD chip select pin | // SD chip select pin |
| rtn = ch; | rtn = ch; | ||||
| break; | break; | ||||
| } | } | ||||
| if ((n+1) >= size) { | |||||
| if ((n + 1) >= size) { | |||||
| // string too long | // string too long | ||||
| rtn = -2; | rtn = -2; | ||||
| n--; | n--; |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD chip select pin | // SD chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; |
| Serial.begin(9600); | Serial.begin(9600); | ||||
| // Wait for USB Serial | // Wait for USB Serial | ||||
| while (!Serial) { | while (!Serial) { | ||||
| SysCall::yield(); | |||||
| } | } | ||||
| Serial.print(F("FreeStack: ")); | |||||
| Serial.println(FreeStack()); | |||||
| // fill buffer with known data | // fill buffer with known data | ||||
| for (size_t i = 0; i < sizeof(buf); i++) { | for (size_t i = 0; i < sizeof(buf); i++) { | ||||
| Serial.println(F("type any character to start")); | Serial.println(F("type any character to start")); | ||||
| while (!Serial.available()) { | while (!Serial.available()) { | ||||
| SysCall::yield(); | |||||
| } | } | ||||
| Serial.print(F("FreeStack: ")); | |||||
| Serial.println(FreeStack()); | |||||
| // initialize the first card | // initialize the first card | ||||
| if (!sd1.begin(SD1_CS, SD_SCK_MHZ(18))) { | if (!sd1.begin(SD1_CS, SD_SCK_MHZ(18))) { | ||||
| // create or open /Dir2/copy.bin and truncate it to zero length | // create or open /Dir2/copy.bin and truncate it to zero length | ||||
| SdFile file2; | 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"); | sd2.errorExit("file2"); | ||||
| } | } | ||||
| Serial.println(F("Copying test.bin to copy.bin")); | Serial.println(F("Copying test.bin to copy.bin")); |
| #define DEBUG_PRINT 0 | #define DEBUG_PRINT 0 | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| #if DEBUG_PRINT | #if DEBUG_PRINT | ||||
| #include "FreeStack.h" | #include "FreeStack.h" | ||||
| #endif // DEBUG_PRINT | #endif // DEBUG_PRINT |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // Set USE_SDIO to zero for SPI card access. | // Set USE_SDIO to zero for SPI card access. | ||||
| #define USE_SDIO 0 | #define USE_SDIO 0 |
| sd.initErrorHalt(); | 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")); | sd.errorHalt(F("open failed")); | ||||
| } | } | ||||
| file.println(F("This line was printed using software SPI.")); | file.println(F("This line was printed using software SPI.")); |
| for (uint8_t dataType = 0; dataType < 5; dataType++) { | for (uint8_t dataType = 0; dataType < 5; dataType++) { | ||||
| for (uint8_t fileType = 0; fileType < 2; fileType++) { | for (uint8_t fileType = 0; fileType < 2; fileType++) { | ||||
| if (!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")); | Serial.println(F("open fail")); | ||||
| return; | return; | ||||
| } | } |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| SdFat sd; | SdFat sd; | ||||
| sd.remove("stamp.txt"); | sd.remove("stamp.txt"); | ||||
| // create a new file with default timestamps | // 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"); | error("open default.txt failed"); | ||||
| } | } | ||||
| cout << F("\nOpen with default times\n"); | cout << F("\nOpen with default times\n"); | ||||
| SdFile::dateTimeCallback(dateTime); | SdFile::dateTimeCallback(dateTime); | ||||
| // create a new file with callback timestamps | // 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"); | error("open callback.txt failed"); | ||||
| } | } | ||||
| cout << ("\nOpen with callback times\n"); | cout << ("\nOpen with callback times\n"); | ||||
| SdFile::dateTimeCallbackCancel(); | SdFile::dateTimeCallbackCancel(); | ||||
| // create a new file with default timestamps | // 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"); | error("open stamp.txt failed"); | ||||
| } | } | ||||
| // set creation date time | // set creation date time |
| // create or open /Dir2/copy.bin and truncate it to zero length | // create or open /Dir2/copy.bin and truncate it to zero length | ||||
| SdFile file2; | 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"); | sd2.errorExit("file2"); | ||||
| } | } | ||||
| Serial.println(F("Copying test.bin to copy.bin")); | Serial.println(F("Copying test.bin to copy.bin")); |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| /* | /* | ||||
| * SD chip select pin. Common values are: | * SD chip select pin. Common values are: | ||||
| * | * | ||||
| printFreeSpace(); | printFreeSpace(); | ||||
| cout << F("Create and write to ") << TEST_FILE << endl; | 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")); | sd.errorHalt(F("Create failed")); | ||||
| } | } | ||||
| file.print(F("Cause a cluster to be allocated")); | file.print(F("Cause a cluster to be allocated")); |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| #include "FreeStack.h" | #include "FreeStack.h" | ||||
| // Set USE_SDIO to zero for SPI card access. | // Set USE_SDIO to zero for SPI card access. | ||||
| cidDmp(); | cidDmp(); | ||||
| // open or create file - truncate existing file. | // 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"); | error("open failed"); | ||||
| } | } | ||||
| // fill buf with known data | // fill buf with known data | ||||
| for (uint16_t i = 0; i < (BUF_SIZE-2); i++) { | |||||
| for (size_t i = 0; i < (BUF_SIZE-2); i++) { | |||||
| buf[i] = 'A' + (i % 26); | buf[i] = 'A' + (i % 26); | ||||
| } | } | ||||
| buf[BUF_SIZE-2] = '\r'; | buf[BUF_SIZE-2] = '\r'; |
| error("Can't create file name"); | 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"); | error("file.open"); | ||||
| } | } | ||||
| // Read any Serial data. | // Read any Serial data. |
| // Demo of fgets function to read lines from a file. | // Demo of fgets function to read lines from a file. | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD chip select pin | // SD chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; | ||||
| char line[25]; | char line[25]; | ||||
| int n; | int n; | ||||
| // open test file | // open test file | ||||
| SdFile rdfile("fgets.txt", O_READ); | |||||
| SdFile rdfile("fgets.txt", O_RDONLY); | |||||
| // check for open error | // check for open error | ||||
| if (!rdfile.isOpen()) { | if (!rdfile.isOpen()) { | ||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||
| void makeTestFile() { | void makeTestFile() { | ||||
| // create or open test file | // 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 | // check for open error | ||||
| if (!wrfile.isOpen()) { | if (!wrfile.isOpen()) { |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // create Serial stream | // create Serial stream | ||||
| ArduinoOutStream cout(Serial); | ArduinoOutStream cout(Serial); |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD chip select pin | // SD chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; |
| */ | */ | ||||
| #include <SPI.h> | #include <SPI.h> | ||||
| #include "SdFat.h" | #include "SdFat.h" | ||||
| #include "sdios.h" | |||||
| // SD chip select pin | // SD chip select pin | ||||
| const uint8_t chipSelect = SS; | const uint8_t chipSelect = SS; | ||||
| } | } | ||||
| } | } | ||||
| // create a file and write one line to the file | // 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()) { | if (!file.isOpen()) { | ||||
| error("Name1.txt"); | error("Name1.txt"); | ||||
| } | } | ||||
| } | } | ||||
| // open file for append in new location and add a line | // 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"); | error("dir2/DIR3/NAME3.txt"); | ||||
| } | } | ||||
| file.println("A line for dir2/DIR3/NAME3.txt"); | file.println("A line for dir2/DIR3/NAME3.txt"); |
| latency. Using a Mega Arduino can help since it has more buffering. | latency. Using a Mega Arduino can help since it has more buffering. | ||||
| The bintocsv folder contains a PC program for converting binary files to | The bintocsv folder contains a PC program for converting binary files to | ||||
| CSV files. I have included a executable for Windows. Linux and Mac users | |||||
| can build from the included source files. bintocvs is a command line program. | |||||
| CSV files. Build it from the included source files. bintocvs is a command line program. | |||||
| bintocsv binFile csvFile | bintocsv binFile csvFile | ||||
| /* Arduino SdFat Library | |||||
| * Copyright (C) 2012 by William Greiman | |||||
| /** | |||||
| * Copyright (c) 20011-2017 Bill Greiman | |||||
| * This file is part of the SdFat library for SD memory cards. | |||||
| * | * | ||||
| * This file is part of the Arduino SdFat Library | |||||
| * MIT License | |||||
| * | * | ||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * Permission is hereby granted, free of charge, to any person obtaining a | |||||
| * copy of this software and associated documentation files (the "Software"), | |||||
| * to deal in the Software without restriction, including without limitation | |||||
| * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
| * and/or sell copies of the Software, and to permit persons to whom the | |||||
| * Software is furnished to do so, subject to the following conditions: | |||||
| * | * | ||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * The above copyright notice and this permission notice shall be included | |||||
| * in all copies or substantial portions of the Software. | |||||
| * | * | ||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the Arduino SdFat Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||||
| * DEALINGS IN THE SOFTWARE. | |||||
| */ | */ | ||||
| /** | /** | ||||
| \mainpage Arduino %SdFat Library | \mainpage Arduino %SdFat Library | ||||
| <CENTER>Copyright © 2012, 2013, 2014, 2015, 2016 by William Greiman | <CENTER>Copyright © 2012, 2013, 2014, 2015, 2016 by William Greiman | ||||
| SdBaseFile, SdFile, File, StdioStream, \ref fstream, \ref ifstream, | SdBaseFile, SdFile, File, StdioStream, \ref fstream, \ref ifstream, | ||||
| and \ref ofstream. | and \ref ofstream. | ||||
| The SdFat, SdFatEX, SdFatSoftSpi and SdFatSoftSpiEX classes maintain a | |||||
| The SdFat, SdFatEX, SdFatSoftSpi and SdFatSoftSpiEX classes maintain a | |||||
| FAT volume, a current working directory, and simplify initialization | FAT volume, a current working directory, and simplify initialization | ||||
| of other classes. The SdFat and SdFatEX classes uses a fast custom hardware SPI | |||||
| of other classes. The SdFat and SdFatEX classes uses a fast custom hardware SPI | |||||
| implementation. The SdFatSoftSpi and SdFatSoftSpiEX classes uses software SPI. | implementation. The SdFatSoftSpi and SdFatSoftSpiEX classes uses software SPI. | ||||
| the SdFatEX and SdFatSoftSpiEX use extended multi-block I/O for enhanced | the SdFatEX and SdFatSoftSpiEX use extended multi-block I/O for enhanced | ||||
| the class SdFatSoftSpiEX will be defined. | the class SdFatSoftSpiEX will be defined. | ||||
| These classes used extended multi-block SD I/O for better performance. | These classes used extended multi-block SD I/O for better performance. | ||||
| the SPI bus may not be shared with other devices in this mode. | the SPI bus may not be shared with other devices in this mode. | ||||
| Set USE_STANDARD_SPI_LIBRARY and ENABLE_SOFTWARE_SPI_CLASS to | Set USE_STANDARD_SPI_LIBRARY and ENABLE_SOFTWARE_SPI_CLASS to | ||||
| enable various SPI options. set USE_STANDARD_SPI_LIBRARY to use the standard | enable various SPI options. set USE_STANDARD_SPI_LIBRARY to use the standard | ||||
| Arduino SPI library. set ENABLE_SOFTWARE_SPI_CLASS to enable the SdFatSoftSpi | Arduino SPI library. set ENABLE_SOFTWARE_SPI_CLASS to enable the SdFatSoftSpi | ||||
| The two example programs QuickStart, and SdInfo are useful for troubleshooting. | 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 | is not seen by SdFat. This is often caused by a wiring error and reformatting | ||||
| the card will not solve the problem. | the card will not solve the problem. | ||||
| <PRE> | <PRE> | ||||
| Is there a wiring/soldering problem? | Is there a wiring/soldering problem? | ||||
| errorCode: 0x1, errorData: 0xff | errorCode: 0x1, errorData: 0xff | ||||
| </PRE> | |||||
| </PRE> | |||||
| Here is a message from QuickStart that indicates a formatting problem: | Here is a message from QuickStart that indicates a formatting problem: | ||||
| <PRE> | <PRE> | ||||
| Card successfully initialized. | Card successfully initialized. | ||||
| value is lost. Files that have a base-name where all characters have the | value is lost. Files that have a base-name where all characters have the | ||||
| same case and an extension where all characters have the same case will | same case and an extension where all characters have the same case will | ||||
| display properly. Examples this type name are UPPER.low, lower.TXT, | display properly. Examples this type name are UPPER.low, lower.TXT, | ||||
| UPPER.TXT, and lower.txt. | |||||
| UPPER.TXT, and lower.txt. | |||||
| An application which writes to a file using print(), println() or | An application which writes to a file using print(), println() or | ||||
| write() must close the file or call sync() at the appropriate time to | 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. | 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 | since 2048 bytes of I/O is required to update file and | ||||
| directory information. This includes writing the current data block, reading | directory information. This includes writing the current data block, reading | ||||
| the block that contains the directory entry for update, writing the directory | the block that contains the directory entry for update, writing the directory |
| /* Arduino SdFat Library | |||||
| * Copyright (C) 2011 by William Greiman | |||||
| /** | |||||
| * Copyright (c) 20011-2017 Bill Greiman | |||||
| * This file is part of the SdFat library for SD memory cards. | |||||
| * | * | ||||
| * This file is part of the Arduino SdFat Library | |||||
| * MIT License | |||||
| * | * | ||||
| * This Library is free software: you can redistribute it and/or modify | |||||
| * it under the terms of the GNU General Public License as published by | |||||
| * the Free Software Foundation, either version 3 of the License, or | |||||
| * (at your option) any later version. | |||||
| * Permission is hereby granted, free of charge, to any person obtaining a | |||||
| * copy of this software and associated documentation files (the "Software"), | |||||
| * to deal in the Software without restriction, including without limitation | |||||
| * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
| * and/or sell copies of the Software, and to permit persons to whom the | |||||
| * Software is furnished to do so, subject to the following conditions: | |||||
| * | * | ||||
| * This Library is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * The above copyright notice and this permission notice shall be included | |||||
| * in all copies or substantial portions of the Software. | |||||
| * | * | ||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with the Arduino SdFat Library. If not, see | |||||
| * <http://www.gnu.org/licenses/>. | |||||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||||
| * DEALINGS IN THE SOFTWARE. | |||||
| */ | */ | ||||
| #include <SdFatTestSuite.h> | #include <SdFatTestSuite.h> | ||||
| static uint16_t failCount; | static uint16_t failCount; | ||||
| while (Serial.read() <= 0) {} | while (Serial.read() <= 0) {} | ||||
| delay(200); // Catch Due reset problem | delay(200); // Catch Due reset problem | ||||
| testOut->print(F("FreeRam: ")); | |||||
| testOut->println(FreeRam()); | |||||
| testOut->print(F("FreeStack: ")); | |||||
| testOut->println(FreeStack()); | |||||
| testOut->println(); | testOut->println(); | ||||
| failCount = 0; | failCount = 0; | ||||
| testCount = 0; | testCount = 0; | ||||
| void testEnd() { | void testEnd() { | ||||
| testOut->println(); | testOut->println(); | ||||
| testOut->println(F("Compiled: " __DATE__ " " __TIME__)); | testOut->println(F("Compiled: " __DATE__ " " __TIME__)); | ||||
| testOut->print(F("FreeRam: ")); | |||||
| testOut->println(FreeRam()); | |||||
| testOut->print(F("FreeStack: ")); | |||||
| testOut->println(FreeStack()); | |||||
| testOut->print(F("Test count: ")); | testOut->print(F("Test count: ")); | ||||
| testOut->println(testCount); | testOut->println(testCount); | ||||
| testOut->print(F("Fail count: ")); | testOut->print(F("Fail count: ")); |
| /** | |||||
| * Copyright (c) 20011-2017 Bill Greiman | |||||
| * This file is part of the SdFat library for SD memory cards. | |||||
| * | |||||
| * MIT License | |||||
| * | |||||
| * Permission is hereby granted, free of charge, to any person obtaining a | |||||
| * copy of this software and associated documentation files (the "Software"), | |||||
| * to deal in the Software without restriction, including without limitation | |||||
| * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
| * and/or sell copies of the Software, and to permit persons to whom the | |||||
| * Software is furnished to do so, subject to the following conditions: | |||||
| * | |||||
| * The above copyright notice and this permission notice shall be included | |||||
| * in all copies or substantial portions of the Software. | |||||
| * | |||||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||||
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||||
| * DEALINGS IN THE SOFTWARE. | |||||
| */ | |||||
| #ifndef SdFatTestSuite_h | |||||
| #define SdFatTestSuite_h | |||||
| #include "SdFat.h" | |||||
| #include "FreeStack.h" | |||||
| #if defined(__arm__) && !defined(strcmp_P) | |||||
| #define strcmp_P(a, b) strcmp((a), (b)) | |||||
| #endif // strcmp_P | |||||
| #if defined(__arm__) && !defined(strncpy_P) | |||||
| #define strncpy_P(s, t, n) strncpy(s, t, n) | |||||
| #endif // strncpy_P | |||||
| #if defined(__arm__) && !defined(strlen_P) | |||||
| #define strlen_P(str) strlen(str) | |||||
| #endif // strlen_P | |||||
| #define testVerifyBool(result) testVerify_P(result, PSTR(#result)) | |||||
| #define testVerifyMsg(result, msg) testVerify_P(result, PSTR(msg)) | |||||
| #define testVerifyStr(result, expect) testVerify_P(result, PSTR(expect)) | |||||
| void testBegin(); | |||||
| void testEnd(); | |||||
| void testVerify_P(bool b, PGM_P msg); | |||||
| void testVerify_P(char* result, PGM_P expect); | |||||
| #endif // SdFatTestSuite_h |