Teensy 4.0 fails to begin() with an SD card

KrisKasprzak

Well-known member
All,

I have a board with a display and SD card and when using a Teensy 3.2 all works well (SPI display and the SD card). The SD card is on the display, but resistors replaced with 0 ohm and it works.

I recompiled my code for a teensy 4.0 and the SD card fails on sd.begin(). I'm using pin 10 as my SD chip select. I can't even get the Sdfat examples to work. Generally, do we expect the 4.0 to be able to use SD cards w/o code changes? If not what code changes are needed

I have a project from a few months back, that uses a 4.0 and SD card and no issues.

I'm using Teensy loader 1.54

Thoughts?


Code:
#include <SdFat.h>

bool IsSD = false;

SdFat sd;
SdFile dataFile;

void setup() {

  Serial.begin(9600);

  delay(2000);

  IsSD = sd.begin(10);
  
  Serial.println(IsSD);

}

void loop() {
  

}
 
Not sure of connectivity involved?

But a T_4.0 using PJRC Audio card SD socket should be similar with SPI to SD and display? That works ... can't say tested here recently enough to remember ... but examples for Audio tutorial T_3.2 should work on T_4.0 with any needed adjust given the SPI SCK pin 13 doesn't have option for pin 14. The later examples in the tutorial connect an ILI9341 - not sure if it samples from SD ...

Perhaps that gives a place to look?
 
I ran your program on a Teensy 4.0 with the audio shield (rev D) connected with a 32GB SD card installed. I used 1.54 with the latest core library changes from github.

It prints "1". That's the correct result, right?

screenshot.png
 
I hadn't tried the new Teensy SD/SdFat libraries, so i fired up IDE 1.8.15 with TD 1.54. I used a T4.0 with Rev D audio shield to provide SPI microSD. Like Paul, your sketch printed "1", and I added sd.ls(LS_R); after the println to get a directory listing of my 8GB Sandisk. That worked too. I ran SdFat bench example and that worked on both SPI microSD and builtin microSD SD on Teensy 4.1 (SDIO).

Code:
SPI @50mhz (actual 48 MHz)
          write speed and latency
          speed,max,min,avg
          KB/Sec,usec,usec,usec
          2898.55,116867,98,176
          4212.30,2756,98,121

          read speed and latency
          speed,max,min,avg
          KB/Sec,usec,usec,usec
          5202.91,99,97,98
          5224.66,98,97,97    41.8 mbs


SDIO@50mhz
         write speed and latency
         speed,max,min,avg
         KB/Sec,usec,usec,usec
         4019.29,98964,22,125
         6289.31,6917,22,80

         read speed and latency
         speed,max,min,avg
         KB/Sec,usec,usec,usec
         22727.27,23,22,22
         22727.27,23,22,22     182 mbs
Your "SPI display and the SD card" should have a pin for display CS and another pin for the SD CS. Make sure the teensy pin 10 is jumpered to SD card CS pin. Also make sure you don't have any local copies of SdFat lib, and that you are using the Teensy supplied version of SdFat lib
 
It should print 1, but trying 2 Teensy 4.0, and 1 Teensy 4.1 I get 0 meaning the SD card fails to begin when using SdFat.

For my tests I'm now using just a Teensy and an SD card shield

However using SD.h. the Teensy 4.0 and a 4.1 work (at least SD.begin() returns true).

Maybe I have and old out of date SdFat that did not get installed properly. I'm sure it works otherwise we would have heard about. it. I'll remove Arduino and Teensyduino and reinstall.



Code:
//#include <SdFat.h>
#include <SD.h>

bool IsSD = false;

//SdFat sd;
//SdFile dataFile;

void setup() {

  Serial.begin(9600);
  delay(2000);
  IsSD = SD.begin(10);

  Serial.println(IsSD);
 // SD.ls(LS_R);

}

void loop() {


}
 
@Paul: you write "I used 1.54 with the latest core library changes from github."

do I need to get the latest SdFat from gitHUb and overwrite my Teensyduino install?

I'll give that a shot, but would be good to know if a manual update is needed.
 
1.54 should be fine. The copy of Arduino I have running here is 1.54 plus just a few minor changes which have been added since 1.54. They shouldn't have any impact on SD cards. I simply tested on the copy of Arduino which was running on my desktop and hardware I already had on my workbench, because that was the quickest & easiest way.

But if needed, I could retest on the 1.54 release. Pretty sure it will work. That's also what Manitou tested.
 
I just deleted all sdFat in my 1) Arduino\libraries and in my 2) Arduino\hardware\teensy\avr\libraries and installed this lib in both locations

https://github.com/greiman/SdFat

I'm on Win10 and Arduino IDE 1.8.13 . If both SD and SdFat didn't it would be a wiring issue or something simple but I change comments to use SD.h and being() works. This is too weird

Pretty sure I'm the only one with issues, otherwise we would have heard about it.

Attached is my setup


IMG_2997.jpg
 
I'd recommend deleting SdFat from Arduino\libraries.

Then install Arduino 1.8.15 again. Arduino's installer will delete the old 1.8.13 copy. After Arduino 1.8.15, install Teensyduino 1.54. That should give you the same software Manitou and I tested.
 
I can imagine all of you have this working but still a no go for me after updating everything.

I am using a 16 GB SD card

IDE
Teensyduino: 1.54
Arduino 1.8.15
downloaded latest from Github SdFat: line 43 in .h is #define SD_FAT_VERSION_STR "2.0.7"
SdFat in Teensy folder only


Computer:
Win10
Ram 32 GB
TrendMicro virus checker

Compile options
Board Teensy 4.0
USB Type: Serial
CPU Speed 600 MHZ
Optimize: smallest code (fastest tried sd.begin still fails)
Keyboard layout US English
Port: COM5 Serial (Teensy 4.0)

SdFat fails on sd.begin(10);
SD succedds on SD.begin(10);

Stuck...
 
OK, got my SD cards working, seems these lines are needed

#define SPI_SPEED SD_SCK_MHZ(4)
IsSD = sd.begin(CS, SPI_SPEED);


...maybe my cards are slow?


Code:
#include "SdFat.h"

#define SPI_SPEED SD_SCK_MHZ(4)
#define CS 10

bool IsSD = false;

SdFat sd;

void setup() {

  pinMode(CS, OUTPUT);

  Serial.begin(115200);

  delay(2000);
  IsSD = sd.begin(CS, SPI_SPEED);

  Serial.println(IsSD);
  sd.ls(LS_R);

}

void loop() {


}
 
Maybe that adaptor board is using slow resistor dividers meant to a 5V Arduino Uno?

The SD standard says all cards are supposed to support 25 MHz speed, so it's probably not the card.
 
Back
Top