#SD Library#
sd's Introduction
sd's People
Forkers
mdrunk gberl001 jeremysf drpjk defragster universal-it-systems shoshocodo wmxz-eu olivervoel dagbar sigmafx lishuai1225 gabeplaysdrums gothack fatemehki djquardaboff uw-sdic ggarza78 luchk eyewonder needfulthings tsandmann timgrant yhvh sepppenner brivbl rutmarti fodormarton muiota wwatson4506 ryanrsrs tyzjames kurte zayslash salmon-built-designs mjs513 qnimble hideohattori bimac h4yn0nnym0u5e geffennirsd's Issues
Access 2 SD cards simultaneously
I need to play background audio while accessing the SD card for data logging at the same time on Teensy 3.5.
Since the SD instance can't read two files at the same time, I decided to use an additional micro SD card module, so 1 SD is for audio and the other is for data. Doesn't work either.
I would prefer to have to use only the onboard SD card. For audio, I am using the Teensy audio lib, while for data logging, I am using the EDB library which also includes this library (I deleted the standard Arduino SD lib to not be confused).
Using 1 card for both seems to be working as I see that the library allows multiple SD.open's , but when I use that as per EDB example, the audio is distorted and log data is corrupt.
Is there a way to mod this lib to enable proper multi-file or multi-card access?
UPDATE: Turn out there is also a conflict beenween Audio.h and SD.h. As long as I include Audio.h, SD.open used in EDB library will result in a deadlock.
Dave
write(buffer, size) fails for size >= 64kB
char/string pointer inputs should be const
sketches get the warning:
warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
FS.h not found ;(
In file included from include/main.h:5:0,
from src/main.cpp:1:
include/SD.h:35:16: fatal error: FS.h: No such file or directory
'SPISettings' was not declared in this scope
Having trouble compiling this for teensy 3.1. Here's the error traceback:
/Users/stevenle/Documents/Arduino/libraries/SD/utility/Sd2Card.cpp: In function 'void spiInit(uint8_t)':
/Users/stevenle/Documents/Arduino/libraries/SD/utility/Sd2Card.cpp:54:14: error: 'settings' was not declared in this scope
/Users/stevenle/Documents/Arduino/libraries/SD/utility/Sd2Card.cpp:54:66: error: 'SPISettings' was not declared in this scope
'class SdFs' has no member named 'restart'
Hi @PaulStoffregen I'm unable to build this library into my project and I get this error:
error: 'class SdFs' has no member named 'restart'
You also have a comment at this function call;
if (ret)
{
ret = sdfs.restart();
// bugbug:: if it fails and builtin may need to start pinMode again...
}
//Serial.print(ret ? "begin ok" : "begin nope");
Do you have any ideas as to what the issue might be?
I've tried a few versions of greiman/SdFat thinking it might've been a breaking change but to no avail.
I seem to occasionally get this issue too:
error: #error "Teensy's SD library uses a custom modified copy of SdFat.
Standard SdFat was mistakenly used. Arduino should print multiple libraries found for SdFat.h.
To resolve this error, you will need to move or delete the copy Arduino is using,
or otherwise take steps to cause Teensy's special copy of SdFat to be used."
But I am able to find that the macro set by the #define
directive is set in the SdFat source.
USE_TEENSY3_SPI causes fatal conflicts in the SPI bus
I'm using both a LISD3DH accelerometer (in SPI mode) and a Micro-SD card connected to a Teensy 3.2. With the SD library unmodified, initializing the SD card fails and also causes the accelerometer to fail.
Commenting out: USE_TEENSY3_SPI in Sd2Card.cpp allows both to succeed.
There is some side effect in the USE_TEENSY3_SPI configuration that causes the bus to fail; I haven't debugged further.
SDHC clock incorrectly set
Wildcard in library.properties but filtering architectures
Hello and thanks for your awesome library 👍
Apparently the master branch of this project has been bundled with Arduino 1.8.14 latest release.
The issue is that the library claims to handle all architectures whereas the code indicates it clearly does not.
As a result this library now predates any core-bundled SD.h with a lower version number (such as the one from esp32-arduino), even though that architecture isn't listed in the Sd2PinMap file.
I'm not sure what should happen instead, not erroring to satisfy the wildcard in the properties file, or be exhaustive with the supported architectures, but the only way I could find to solve this error with esp32-arduino was to delete the bundled SD library from the arduino/libraries application folder.
This is a big constraint for me as I'm using your excellent library in other non-esp32 projects and will have to re-import it anyway.
Please let me know what I can do to help, I already suggested to espressif team to raise the version number to a higher value, but this is more a hack than a real fix as the real problem is the wildcard in the properties file.
Thanks again for the great work!
Unexpected behavior in getModifyDateTime / getCreateDateTime (Possible bug)
The example listfiles.ino exposes what I believe might be considered a bug:
if (entry.getModifyTime(datetime)) {
printSpaces(4);
printTime(datetime);
Since printTime does no error checking, the example assumes that getModifyTime will return false unless datetime is valid. Unfortunately this is not correct: getModifyTime happily returns true for invalid datetimes. This can result in a crash.
To repro, you need an SD card containing a file with an invalid lastModified datetime. In my case I have an ExFat SD card containing files that were written by BillG's SdFat (with no attention paid to file dates) and one of the files returns an invalid modification datetime with month==255. After getModifyTime returns true, the subsequent call to printTime fails when we exceed the months array index bounds. The result is a program crash and truncated output at the point of failure.
Validity checking could be added to the example, but I think many people will find it misleading to have getModifyTime return true and an invalid datetime.
The File::getModifyTime() call passes through FsFile.h for triage to FatFile::getModifyDateTime() or ExFatFile::getModifyDateTime()
bool getModifyDateTime(uint16_t* pdate, uint16_t* ptime) {
return m_fFile ? m_fFile->getModifyDateTime(pdate, ptime) :
m_xFile ? m_xFile->getModifyDateTime(pdate, ptime) : false;
}
In my case the actual work is done in ExFatFile, which returns true so long as the file exists in the directory cache and will happily return invalid data for the date and time.
bool ExFatFile::getModifyDateTime(uint16_t* pdate, uint16_t* ptime) {
DirFile_t* df = reinterpret_cast<DirFile_t*>
(m_vol->dirCache(&m_dirPos, FsCache::CACHE_FOR_READ));
if (!df) {
DBG_FAIL_MACRO;
goto fail;
}
*pdate = getLe16(df->modifyDate);
*ptime = getLe16(df->modifyTime);
return true;
fail:
return false;
}
For the printout below, I modified printTime in the example to show the invalid entry rather than crashing
if ((tm.mon > 11) || (tm.mon < 0))
Serial.printf("Oops_[%d]", tm.mon);
else
Serial.print(months[tm.mon]);
Yielding:
Initializing SD card...initialization done.
SessionFile00.raw 1035441 06:14 December 8, 2021
SessionFile01.raw 1866293 00:00 Oops_[255] 0, 1980
mtpindex.dat 0 19:05 December 15, 2021
SessionFile02.raw 6946558 06:18 December 8, 2021
SessionFile03.raw 1183576 18:08 December 15, 2021
SessionFile04.raw 1380207 18:12 December 15, 2021
SETTINGS.WSS 40782 00:45 December 16, 2021
datalog.bin 61 00:00 January 1, 2021
done!
You will notice a possibly related second problem:
datalog.bin was created 5 minutes ago by another SD example (SdFat_Usage.ino), and it is showing an incorrect file modification time and date. I could understand Jan 1, 1980, but Jan 1, 2021 is just... not... yeah.
SD listing/writing/reading of Wave files
I am trying to use the SD list code below to list songs recorded as wave files. When run, it does not list any files even though the files "play" with the Audio Shield Card and other code. Is there a problem in using this list code with audio files as opposed to raw data files? When run with one raw data file as the 1st file in the directory, it will list it plus one of the wav files, but none of the other 33 songs. Am I missing something here?
`/*
SD card basic file example
This example shows how to create and destroy an SD card file
The circuit:
- SD card attached to SPI bus as follows:
** MOSI - pin 11, pin 7 on Teensy with audio board
** MISO - pin 12
** CLK - pin 13, pin 14 on Teensy with audio board
** CS - pin 4, pin 10 on Teensy with audio board
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SD.h>
#include <SPI.h>
File root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// Teensy audio board: pin 10
// Teensy 3.5 & 3.6 on-board: BUILTIN_SDCARD
// Wiz820+SD board: pin 4
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
const int chipSelect = 10;
void setup()
{
//UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
SPI.setMOSI(7); // Audio shield has MOSI on pin 7
SPI.setSCK(14); // Audio shield has SCK on pin 14
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
}
void loop()
{
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numTabs) {
while(true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
//Serial.println("**nomorefiles**");
break;
}
for (uint8_t i=0; i<numTabs; i++) {
Serial.print('\t');
}
Serial.print(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();
}
}
`
fatal error: FS.h: No such file or directory with Teensy 4.0
Getting error below with Teensy 4.0
fatal error: FS.h: No such file or directory
Some SDFat Examples do not work
See title :)
UI: Add fast alternative to Up & Down buttons
FileImpl not a class or struct name
Hello,
I am using your SD repo as a dependency in my platformio project. When I drill down to the error in SD.h I am told that "FileImpl not a class or struct name"
Where is FileImpl supposed to be defined? How can I fix this?
Code does not write binary file correctly
Hi Paul,
I am reading an historic floppy disk image and dumping to to SD in binary format, code snippet:
File myFile;
myFile = SD.open(fname.c_str(), FILE_WRITE);
myFile.seek(0);
for (int sector=0; sector<18*80; sector++) {
byte dat[512];
readit(sector, dat);
dumpFast(dat, 512);
myFile.write(dat, 512);
}
myFile.close();
My dumpFast routine shows on Serial port, e.g.,
41 55 54 4F 45 58 45 43 42 41 54 20 00 00 00 00 AUTOEXECBAT ....
00 00 00 00 00 00 00 00 21 00 2B 00 80 00 00 00 ........!.+.�...
The file on the SD shows in notepad++ hex editor (something like):
41 55 54 4F 45 58 45 43 42 41 54 20 00 00 00 00 AUTOEXECBAT ....
00 00 00 00 00 00 00 00 21 00 2B 00 d0 90 00 00 ........!.+.�...
00
I.e. non-ascii characters like 0x080 are replaced by UTF8 0xd0 0x90. This seems to happen consistently.
Using teendyduino 1.57 in arduino 1.8.19, on Teensy 3.5
Can you shed light on why this happens and how to avoid this, I expected write() to be binary.
Thanks, Marcel
SD.h on Teensy3.5
Hi there,
I moved my project from Arduino Mega to Teensy 3.5. I tried to use the external microsd card adapter rather than the built-in sd card slot. The problem is I cannot access the card when using the standard cardinfo sketch. Are there any places in head files I need to change so that I can just use regular SPI connection to SD card adapter? I am sure the teensy 3.5 board and sd card have no issue, because I have tested on teensy 3.2 and Mega board, they all work well. It doesnt work on two of my Teensy 3.5.
Some warnings with GCC 9
C:\Arduino\hardware\teensy\avr\libraries\SD\File.cpp: In constructor 'File::File(SdFile, const char*)':
C:\Arduino\hardware\teensy\avr\libraries\SD\File.cpp:26:37: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class SdFile' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
26 | memcpy(_file, &f, sizeof(SdFile));
| ^
In file included from C:\Arduino\hardware\teensy\avr\libraries\SD/SD.h:23,
from C:\Arduino\hardware\teensy\avr\libraries\SD\File.cpp:15:
C:\Arduino\hardware\teensy\avr\libraries\SD/utility/SdFat.h:135:7: note: 'class SdFile' declared here
135 | class SdFile : public Print {
| ^~~~~~
C:\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp:445:15: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
445 | dateTime_(&p->creationDate, &p->creationTime);
| ^~~~~~~~~~~~~~~~
C:\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp:445:15: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
C:\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp:445:33: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
445 | dateTime_(&p->creationDate, &p->creationTime);
| ^~~~~~~~~~~~~~~~
C:\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp:445:33: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
C:\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp: In member function 'uint8_t SdFile::sync()':
C:\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp:973:17: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
973 | dateTime_(&d->lastWriteDate, &d->lastWriteTime);
| ^~~~~~~~~~~~~~~~~
C:\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp:973:17: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
C:\Arduino\hardware\teensy\avr\libraries\SD\utility\SdFile.cpp:973:36: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
973 | dateTime_(&d->lastWriteDate, &d->lastWriteTime);
| ^~~~~~~~~~~~~~~~~
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.