mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-24 19:42:27 +03:00
Update to SdFat 2.0.2, speed SD access (#7779)
* Update to upstream SdFat 2.0.2 Increases the read/write performance for SD card accesses by a significant amount, up to 5x (3+MB/s) in testing. Fixes #7772 * Add SDFS::availableForWrite handler Peek into the sector cache to determine the maximum number of bytes that can be written w/o needing a (slow) SD operation. Fixes #7650
This commit is contained in:
committed by
GitHub
parent
9de8373f1b
commit
c487ca5233
@ -25,7 +25,6 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "SDFS.h"
|
||||
#include "SDFSFormatter.h"
|
||||
#include <FS.h>
|
||||
|
||||
using namespace fs;
|
||||
@ -65,13 +64,13 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces
|
||||
}
|
||||
free(pathStr);
|
||||
}
|
||||
sdfat::File fd = _fs.open(path, flags);
|
||||
sdfat::File32 fd = _fs.open(path, flags);
|
||||
if (!fd) {
|
||||
DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d",
|
||||
&fd, path, openMode, accessMode);
|
||||
return FileImplPtr();
|
||||
}
|
||||
auto sharedFd = std::make_shared<sdfat::File>(fd);
|
||||
auto sharedFd = std::make_shared<sdfat::File32>(fd);
|
||||
return std::make_shared<SDFSFileImpl>(this, sharedFd, path);
|
||||
}
|
||||
|
||||
@ -91,7 +90,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
|
||||
}
|
||||
// At this point we have a name of "/blah/blah/blah" or "blah" or ""
|
||||
// If that references a directory, just open it and we're done.
|
||||
sdfat::File dirFile;
|
||||
sdfat::File32 dirFile;
|
||||
const char *filter = "";
|
||||
if (!pathStr[0]) {
|
||||
// openDir("") === openDir("/")
|
||||
@ -136,7 +135,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
|
||||
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
|
||||
return DirImplPtr();
|
||||
}
|
||||
auto sharedDir = std::make_shared<sdfat::File>(dirFile);
|
||||
auto sharedDir = std::make_shared<sdfat::File32>(dirFile);
|
||||
auto ret = std::make_shared<SDFSDirImpl>(filter, this, sharedDir, pathStr);
|
||||
free(pathStr);
|
||||
return ret;
|
||||
@ -146,8 +145,15 @@ bool SDFSImpl::format() {
|
||||
if (_mounted) {
|
||||
return false;
|
||||
}
|
||||
SDFSFormatter formatter;
|
||||
bool ret = formatter.format(&_fs, _cfg._csPin, _cfg._spiSettings);
|
||||
sdfat::SdCardFactory cardFactory;
|
||||
sdfat::SdCard* card = cardFactory.newCard(sdfat::SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings));
|
||||
if (!card || card->errorCode()) {
|
||||
return false;
|
||||
}
|
||||
sdfat::FatFormatter fatFormatter;
|
||||
uint8_t *sectorBuffer = new uint8_t[512];
|
||||
bool ret = fatFormatter.format(card, sectorBuffer, nullptr);
|
||||
delete[] sectorBuffer;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user