Teensy 4.0 BUILT_IN SD - SPI Drive strength

Hi All,

Redirected here by greiman of SDFat.

I build a custom board of which allows for an SD card to be connected to the T 4.0. I am getting odd results when it comes to writing to the SD card.

If I write to the SD once every 800ms, this works, but anything quicker than 800ms and the SD becomes unformatted.

Quick example as code is massive:

Code:
char newTextToAdd[500];
String testCode = "This is a test";
testCode.toCharArray(newTextToAdd, sizeof(newTextToAdd));
file.open(csFileName, FILE_WRITE);
file.write(newTextToAdd, tt.length());
file.close();
delay(800);

So I was thinking there was an issue with my code, however I ran the SDIO demo by greiman and I yield the following results:

Code:
FIFO SDIO mode.

size,write,read
bytes,KB/sec,KB/sec
512,11018.91,11716.91
1024,10819.65,11723.24
2048,11083.92,11726.17
4096,11071.23,11754.79
8192,10952.82,11765.29
16384,Error: write failed
SD_CARD_ERROR_CMD12, ErrorData: 0X0

Again, the SD becomes unformatted. Greiman suggest that I alter the drive strength https://github.com/greiman/SdFat/blob/628effa1c277e6dc1fef461b4b755ad300735248/src/SdCard/SdioTeensy.cpp#L339 and frequency https://github.com/greiman/SdFat/blob/628effa1c277e6dc1fef461b4b755ad300735248/src/SdCard/SdioTeensy.cpp#L730 in the teensy source code.

I now suspect the SD is becoming unformatted because the card is too far away from the T4.0 on the PCB.

Can anyone please advise what frequency/drive strength should be selected to (boost the signal)?

NB: The SD either becomes unformatted or unresponsive, until power is cycled (or I call sd.begin(SD_CONFIG) again). I am using multiple SanDisk SDHC/SDXC (v30)s purchased from different sources and am confident they are all genuine.

Many Thanks
 
Last edited:
Please include a minimal but Complete sketch. Without that assuming the SD Card is wired to the T_4.0 Underside for SDIO demo.

Also on desk here is a T_4.0 with an SD card well mounted and tested (thanks to @loglow/TallDog) - but without a complete sketch the same code can't be quickly tested here.

Also, what version of IDE and TeensyDuino is in use?
 
Quick example as code is massive:

This isn't enough. Nobody can see the problem, let alone reproduce it, by such a short code fragment.

The best I can tell you from only that code fragment is I and countless other people have successfully written to SD cards using similar code. Something no evident from that code fragment is very wrong.

In fact, even how you have connected the SD card isn't clear, at least to me. The subject says "SPI Drive Strength". But your message says "SDIO demo". You mention "sd.begin(SD_CONFIG)" but didn't show what SD_CONFIG actually is.


I now suspect the SD is becoming unformatted because the card is too far away from the T4.0 on the PCB.

Can anyone please advise what frequency/drive strength should be selected to (boost the signal)?

Can you understand you're asking us to give you technical guidance which is specific to hardware we can't even see?!

Electrical signal quality is a complicated topic. This isn't the sort of question that has a "one size fits all" type of answer. In many scenarios, especially with lengthy wires lacking a ground plane or ground wires in close proximity, attempting to increase the signal bandwidth makes the problems even worse. The physical wiring matters greatly for signal quality problems. Assuming this really is a signal quality problem, in addition to seeing a complete program (surely you can compose such a program for the sake of getting useful help) we also must see the wiring.
 
Back
Top