Cardinfo runs OK but any SdFat category fails to init sdcard on T4.1 using TD1.52

Status
Not open for further replies.

johnda

Member
Hi Support,
Thanks to Robin and Paul and the entire development group for an exciting new product in T4.1.

I am having some trouble with getting the sdcard working though.
I have a large monitor type program that ran fine on T3.6 with an earlier (2018) version of SdFat
But have not yet been able to get SdFat running on the T4.1.

Here are details:
TD1.52 SdFat-beta for 4.0-4.1 from greiman
Running clock 600mhz with other settings a default.
sdcard formatted FAT32 16GB with a few files on it.

The cardinfo example based on SD lib runs fine and even prints the list of files.

But the OpenNext example fails on 4.1 (but runs fine on a Teensy 3.6)

The only info I get is that it failed the begin() - method returns 0.

Here is the smallest program I could make to reproduce the failure.
All of the includes are in the program to in case they are part of the problem (extracted from the original much larger program).
I've tried all 3 SD_FAT_TYPEs and they all fail.

If you have any suggestions so I can provide more info or things to read up on (I've tried the Sdfat html class pages but am not sure where to begin), I would appreciate it very much.

#include <stdio.h>
#include <stdlib.h>
#include "TeensyThreads.h"
#include <EEPROM.h>

//#include <i2c_t3.h> New i2c lib: Used instead of Wire.h see Documents for doc
#include <Wire.h>
#include <ILI9341_t3.h>
#include <Streaming.h>
#include <Metro.h>
#include <SPI.h> // WARNING : TEENSY DEFAULT LED (PIN 13) IS OVER-RIDDEN BY SCK FOR SPI
#include <TimeLib.h>
#include <XPT2046_Touchscreen.h>
#include "DHT.h"
#include <FreqMeasureMulti.h>

#include "SdFat.h"

#define SD_FAT_TYPE 1

#if SD_FAT_TYPE == 1
SdFat SD;
// File file;
File filex, fhandle1, fhandle2, fhandle3, anaFile, hexFile, afile, bfile ;
File root;
#elif SD_FAT_TYPE == 2
SdExFat SD;
ExFile filex, fhandle1, fhandle2, fhandle3, anaFile, hexFile, afile, bfile ;
ExFile root;
#elif SD_FAT_TYPE == 3
SdFs SD;
FsFile filex, fhandle1, fhandle2, fhandle3, anaFile, hexFile, afile, bfile ;
FsFile root;
#endif // SD_FAT_TYPE

// ILI9341_t3 tft
const uint8_t CS_PIN = 8, TFT_CS = 10, TFT_DC = 9, TIRQ_PIN = 2;
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC); // 'n' version causing errors
XPT2046_Touchscreen ts(CS_PIN); // TFT GRAPHICS OBJECTS TOUCHSCREEN
TS_Point p, pmap;

// CALLBACK ROUTINES
time_t newtime, tempSystime;
void dateTime(uint16_t* date, uint16_t* time) { // Following used by -> SdFile::dateTimeCallback(dateTime);
*date = FAT_DATE(year(), month(), day()); // set date time callback function
*time = FAT_TIME(hour(), minute(), second());
}
time_t getTeensy3Time() {
return Teensy3Clock.get();
}

void setup() {
tft.begin();
ts.begin(); // touchscreen begin
tft.fillScreen(ILI9341_BLACK); tft.setRotation(1);

if (!SD.begin()) {
Serial.println("SD initialization failed!");
tft.setCursor(5, 205);
tft.setTextSize(2);
tft.print("SD failed to initialize");
delay(3000);
} else {
SdFile::dateTimeCallback(dateTime); // set date time callback function
Serial.println("SD Init success ..file timestamp callback installed "); }
}
void loop() {
}
 
A few of us are having a bit of an hard time getting SdFat "standard" fully work on T4.1.
At the moment it's not clear whether Bill Greiman will backport T4.1 support to standard SdFat.

You may try SdFat Beta (aka "V2"), which does support T4.1:
https://github.com/greiman/SdFat-beta

but it's not fully backward-compatible, so it may break builds, depending on what's in your code.
 
Thanks for your reply XFer.
Yes, I am using 'V2' version of SdFat, but there has been only a single update in the last 23 days and most updates are 2 years old.
SdFat is a great lib and it ran well on T3.6, it is unfortunate that it is not usable on T4.1

I will be trying to use SD lib with it's reduced functionality, as it is the supported library in Teensyduino.

Can you recommend any tutorials for SD lib, as I find it confusing for simple file opens(even though it's an SdFat wrapper too), compared to Greiman's SdFat ?

Greiman's SdFat technique for opens is:
File thisfile ;
bool status;
...
status = thisfile.open() ;


But SD lib uses:
File fileobj ;
...
fileobj = SD.open("/");

return status of open is unknown.

john
 
Extra configuration must be provided in the SD.begin () line. The Sdfat beta library has two options:
Code:
SD.begin (SdioConfig (FIFO_SDIO));

and
Code:
SD.begin (SdioConfig (DMA_SDIO));

Depending on the processing speed of instructions. With FIFO_SDIO better results are obtained. Try this:

Code:
#include <stdio.h>
#include <stdlib.h>
#include "TeensyThreads.h"
#include <EEPROM.h>

//#include <i2c_t3.h> New i2c lib: Used instead of Wire.h see Documents for doc
#include <Wire.h>
#include <ILI9341_t3.h>
#include <Streaming.h>
#include <Metro.h>
#include <SPI.h> // WARNING : TEENSY DEFAULT LED (PIN 13) IS OVER-RIDDEN BY SCK FOR SPI
#include <TimeLib.h>
#include <XPT2046_Touchscreen.h>
#include "DHT.h"
#include <FreqMeasureMulti.h>

#include "SdFat.h"

#define SD_FAT_TYPE 1

#if SD_FAT_TYPE == 1
SdFat SD;
// File file;
File filex, fhandle1, fhandle2, fhandle3, anaFile, hexFile, afile, bfile ;
File root;
#elif SD_FAT_TYPE == 2
SdExFat SD;
ExFile filex, fhandle1, fhandle2, fhandle3, anaFile, hexFile, afile, bfile ;
ExFile root;
#elif SD_FAT_TYPE == 3
SdFs SD;
FsFile filex, fhandle1, fhandle2, fhandle3, anaFile, hexFile, afile, bfile ;
FsFile root;
#endif // SD_FAT_TYPE

// ILI9341_t3 tft
const uint8_t CS_PIN = 8, TFT_CS = 10, TFT_DC = 9, TIRQ_PIN = 2;
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC); // 'n' version causing errors
XPT2046_Touchscreen ts(CS_PIN); // TFT GRAPHICS OBJECTS TOUCHSCREEN
TS_Point p, pmap;

// CALLBACK ROUTINES
time_t newtime, tempSystime;
void dateTime(uint16_t* date, uint16_t* time) { // Following used by -> SdFile::dateTimeCallback(dateTime);
*date = FAT_DATE(year(), month(), day()); // set date time callback function
*time = FAT_TIME(hour(), minute(), second());
}
time_t getTeensy3Time() {
return Teensy3Clock.get();
}

void setup() {
tft.begin();
ts.begin(); // touchscreen begin
tft.fillScreen(ILI9341_BLACK); tft.setRotation(3);

if (!SD.begin(SdioConfig(FIFO_SDIO))) {
//if (!SD.begin(SdioConfig(DMA_SDIO))) {
//if (!SD.begin()) {
tft.fillScreen(ILI9341_RED); tft.setRotation(3);
Serial.println("SD initialization failed!");
tft.setCursor(5, 205);
tft.setTextSize(2);
tft.print("SD failed to initialize");
delay(3000);
} else {
SdFile::dateTimeCallback(dateTime); // set date time callback function
tft.fillScreen(ILI9341_GREEN); tft.setRotation(3);
Serial.println("SD Init success ..file timestamp callback installed "); 
tft.setCursor(5, 205);
tft.setTextSize(2);
tft.print("SD Init success");
}
}
void loop() {
}

With SD.begin()
pgmkhjfib4orqb5zg.jpg


With SD.begin(SdioConfig(FIFO_SDIO)) or SD.begin(SdioConfig(DMA_SDIO))
wuhidzig0legewozg.jpg
 
This is the setup to obtain the previous images

Code:
void setup() {
tft.begin();
//ts.begin(); // touchscreen begin
tft.fillScreen(ILI9341_BLACK); tft.setRotation(3);

if (!SD.begin(SdioConfig(FIFO_SDIO))) {
//if (!SD.begin(SdioConfig(DMA_SDIO))) {
//if (!SD.begin()) {
tft.fillScreen(ILI9341_RED); tft.setRotation(3);
Serial.println("SD initialization failed!");
tft.setTextColor(ILI9341_WHITE,ILI9341_RED);
tft.setCursor(5, 205);
tft.setTextSize(2);
tft.print("SD failed to initialize");
delay(3000);
} else {
SdFile::dateTimeCallback(dateTime); // set date time callback function
tft.fillScreen(ILI9341_GREEN); tft.setRotation(3);
Serial.println("SD Init success ..file timestamp callback installed "); 
tft.setTextColor(ILI9341_BLACK,ILI9341_GREEN);
tft.setCursor(5, 205);
tft.setTextSize(2);
tft.print("SD Init success");
}
}
 
Thanks for your time and help

Thanks so much for your time and expertise to help with this issue.
I stumbled on
SdioConfig (FIFO_SDIO) during research into the problem, but this confirms i was on the right path.
It is running now and I'm on to a Wire issue with i2c_t3.

Best regards,
john
 
Status
Not open for further replies.
Back
Top