Teensy 3.5/3.6 TeensySdioDemo Failed Error

Status
Not open for further replies.

jamays3

Member
Hello everyone,

Currently working on a project that requires me to record data at a quick rate. I wanted to use the built-in Teensy SD Card slot as the project I am working on also has a size limit.

I planned on starting with the "TeensySDioDemo" sketch first. However, I am getting the following error with both the SdFatSdioEX and SdFatSdio options...

begin() failed
Invalid format, reformat SD

I get both these errors for both methods within the demo with both the Teensy 3.5 AND the Teensy 3.6 (I own both). I also have two SanDisk Micro SD Cards that are new and that I formatted multiple times. Does this code need to be edited for certain chip selects or something?

Does anyone know a solution to this issue? I am a student and am fairly new to Teensy.

Thanks!!

The Code for the TeensySdioDemo is below...

Code:
// Simple performance test for Teensy 3.5/3.6 SDHC.
// Demonstrates yield() efficiency.

// Warning SdFatSdio and SdFatSdioEX normally should 
// not both be used in a program.
// Each has its own cache and member variables.

#include "SdFat.h"

// 32 KiB buffer.
const size_t BUF_DIM = 32768;

// 8 MiB file.
const uint32_t FILE_SIZE = 256UL*BUF_DIM;

SdFatSdio sd;

SdFatSdioEX sdEx;

File file;

uint8_t buf[BUF_DIM];

// buffer as uint32_t
uint32_t* buf32 = (uint32_t*)buf;

// Total usec in read/write calls.
uint32_t totalMicros = 0;
// Time in yield() function.
uint32_t yieldMicros = 0;
// Number of yield calls.
uint32_t yieldCalls = 0;
// Max busy time for single yield call.
uint32_t yieldMaxUsec = 0;
// Control access to the two versions of SdFat.
bool useEx = false;
//-----------------------------------------------------------------------------
bool sdBusy() {
  return useEx ? sdEx.card()->isBusy() : sd.card()->isBusy();
}
//-----------------------------------------------------------------------------
void errorHalt(const char* msg) {
  if (useEx) {
    sdEx.errorHalt(msg);
  } else {
    sd.errorHalt(msg);
  }
}
//------------------------------------------------------------------------------
uint32_t kHzSdClk() {
  return useEx ? sdEx.card()->kHzSdClk() : sd.card()->kHzSdClk(); 
}  
//------------------------------------------------------------------------------
// Replace "weak" system yield() function.
void yield() {
  // Only count cardBusy time.
  if (!sdBusy()) {
    return;
  }
  uint32_t m = micros();
  yieldCalls++;
  while (sdBusy()) {
    // Do something here.
  }
  m = micros() - m;
  if (m > yieldMaxUsec) {
    yieldMaxUsec = m;
  }
  yieldMicros += m;
}
//-----------------------------------------------------------------------------
void runTest() {
  // Zero Stats
  totalMicros = 0;
  yieldMicros = 0;
  yieldCalls = 0;
  yieldMaxUsec = 0; 
  if (!file.open("TeensyDemo.bin", O_RDWR | O_CREAT)) {
    errorHalt("open failed");
  }
  Serial.println("\nsize,write,read");
  Serial.println("bytes,KB/sec,KB/sec");
  for (size_t nb = 512; nb <= BUF_DIM; nb *= 2) {
    file.truncate(0);
    uint32_t nRdWr = FILE_SIZE/nb;
    Serial.print(nb);
    Serial.print(',');
    uint32_t t = micros();
    for (uint32_t n = 0; n < nRdWr; n++) {
      // Set start and end of buffer.
      buf32[0] = n;
      buf32[nb/4 - 1] = n;
      if (nb != file.write(buf, nb)) {
        errorHalt("write failed");
      }
    }
    t = micros() - t;
    totalMicros += t;
    Serial.print(1000.0*FILE_SIZE/t);
    Serial.print(',');
    file.rewind();
    t = micros();
    
    for (uint32_t n = 0; n < nRdWr; n++) {
      if ((int)nb != file.read(buf, nb)) {
        errorHalt("read failed");
      }
      // crude check of data.     
      if (buf32[0] != n || buf32[nb/4 - 1] != n) {
        errorHalt("data check");
      }
    }
    t = micros() - t;
    totalMicros += t;   
    Serial.println(1000.0*FILE_SIZE/t);    
  }
  file.close();
  Serial.print("\ntotalMicros  ");
  Serial.println(totalMicros);
  Serial.print("yieldMicros  ");
  Serial.println(yieldMicros);
  Serial.print("yieldCalls   ");
  Serial.println(yieldCalls);
  Serial.print("yieldMaxUsec ");
  Serial.println(yieldMaxUsec); 
  Serial.print("kHzSdClk     ");
  Serial.println(kHzSdClk());
  Serial.println("Done");
}
//-----------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  while (!Serial) {
  }
  Serial.println("SdFatSdioEX uses extended multi-block transfers without DMA.");
  Serial.println("SdFatSdio uses a traditional DMA SDIO implementation."); 
  Serial.println("Note the difference is speed and busy yield time.\n"); 
}
//-----------------------------------------------------------------------------
void loop() {
  do {
    delay(10);
  } while (Serial.available() && Serial.read());

  Serial.println("Type '1' for SdFatSdioEX or '2' for SdFatSdio");
  while (!Serial.available()) {
  }
  char c = Serial.read();
  if (c != '1' && c != '2') {
    Serial.println("Invalid input");
    return;
  }
  if (c =='1') {
    useEx = true;
    if (!sdEx.begin()) {
      sd.initErrorHalt("SdFatSdioEX begin() failed");
    }
    // make sdEx the current volume.
    sdEx.chvol();
  } else {
    useEx = false;
    if (!sd.begin()) {
      sd.initErrorHalt("SdFatSdio begin() failed");
    }
    // make sd the current volume.
    sd.chvol();  
  }
  runTest();
}
 
What size is the card? What is the formatting type?

There is an official published SDCardFormatter that puts it in the right shape - FAT32 works IIRC.
 
The question is, how did you format your SD cards? If I remember well, there should also be a SD formatter sketch in the example files.
 
Thanks for the quick replies!

I just tried the "SdFormatter" sketch and got the following error with my Teensy 3.6

SD initialization failure!
Is the SD card inserted correctly?
Is chip select correct at the top of this program?
error: card.begin failed
SD error: 20,ff

The Chip Select is connected to SS and SD card is inserted correctly.

Also, the card is also 64 GB
 
Without special FAT lib the limit is 32 GB - not sure if this is that special lib? The PJRC examples are limited to 32 GB

For native T_3.5 and T_3.6 the PJRC sketches use the special value for those unique native 'SPI' pins - it should be commented in the sketch
 
So, there is something very wrong. What I don‘t understand is you writing „The Chip Select is connected to SS...“

Using the internal SD card slot of the Teensy 3.5/6 does not require extra connections. It‘s all about defining the Chip select as BUILTIN_SDCARD:
Code:
You can just use any example with the CS pin set to BUILTIN_SDCARD
as "SD.begin(BUILTI[COLOR=#333333]N_[/COLOR]SDCARD[COLOR=#333333])[/COLOR][COLOR=#333333]"[/COLOR]
 
Ah so there may be a limit on the card capacity?

Also, here is some code that is in the "SdFormatter" where the chip select is declared.

// Set USE_SDIO to zero for SPI card access.
#define USE_SDIO 0
//
// Change the value of chipSelect if your hardware does
// not use the default value, SS. Common values are:
// Arduino Ethernet shield: pin 4
// Sparkfun SD shield: pin 8
// Adafruit SD shields and modules: pin 10
const uint8_t chipSelect = SS;

Here, the "SS" should refer to the internal SD card slot for Teensy 3.5/3.6 right?
 
Since it doesn‘t work that way, replace SS by BUILTIN_SDCARD.

Please understand that most of the SD examples and libraries were created long time before the Teensy 3.5/6 with built-in SD slots came to market. Thus, there might be a lack of appropriate documentation.

It might also be that you‘ll need to comment out the line #define USE_SDIO 0 but I‘m not sure. Try it out.
 
Unfortunately, neither of those options worked...

Also, those errors were just in the "SdFormatter" code. The "TeensySdioDemo" does not have a chip select within the code. I tried putting BUILTIN_SDCARD in the sketch like this...

sdEx.begin(BUILTIN_SDCARD)

However, it states "BUILTIN_SDCARD was not declared in this scope".

The "TeensySdioDemo" example (posted in initial question) says it is for Teensy 3.5/3.6 so I am very confused as to why it is not working...
 
The SDIO demo says clearly why it fails - a SD format problem, which could also be a SD size problem.

What I can‘t see is why the formatter sketch wouldn‘t work. I haven‘t worked with SD stuff in the last years, but if I remember well, there was a 4GB Limit on 32bit processors in the time.
 
Ill try and get my hands on a smaller SD card here soon. then I can get back to you guys!

Thank you so much for helping out. Much appreciated!
 
Hey guys,

I tried using a 32 GB SD Card and no luck. I have two 32 GBs and neither worked.

Dont know what it could be. Is there a certain way to format them? A certain type of format?

Thanks!
 
Hey guys,

I tried using a 32 GB SD Card and no luck. I have two 32 GBs and neither worked.

Dont know what it could be. Is there a certain way to format them? A certain type of format?

Thanks!

the example program does not work with exFAT formatted disks (usually >32 GB)
it works for FAT32 formatted disks (just tested it)
AFAIK, None of the Teensy programs works with NTFS or any Linux formats.

To format uSD, you can use the official formatter from https://www.sdcard.org/downloads/formatter_4/
or try windows formatter (<=32 GB) or Bill Greimans's formatter example
You can format disks of all sizes as FAT32 (the larger disk, the larger clustersize should be selected)
 
Hello teensiers,
I try to compile "Simple performance test for Teensy 3.5/3.6 SDHC" (see post 9-30-2018 jamais3) unsuccesfully. A lot of errors.
I downloaded all headerfiles again today. I use the latest Arduino/Teensy software. Please can anyone advise me?. Thanks.

The errorlist:
In file included from C:\Program Files\Arduino\libraries\SD\src/BlockDriver.h:29:0,

from C:\Program Files\Arduino\libraries\SD\src/SdFat.h:32,

from F:\Mijn Documenten\Arduino\Teensy\SdFat-1.0.7\SdFat-1.0.7\examples\QuickStart\QuickStart.ino:4:

C:\Program Files\Arduino\libraries\SD\src/SdSpiCard.h: In constructor 'SdSpiCard::SdSpiCard()':

C:\Program Files\Arduino\libraries\SD\src/SdSpiCard.h:44:29: error: 'SD_CARD_ERROR_INIT_NOT_CALLED' was not declared in this scope

SdSpiCard() : m_errorCode(SD_CARD_ERROR_INIT_NOT_CALLED), m_type(0) {}

^

C:\Program Files\Arduino\libraries\SD\src/SdSpiCard.h: In member function 'bool SdSpiCard::readCID(cid_t*)':

C:\Program Files\Arduino\libraries\SD\src/SdSpiCard.h:131:25: error: 'CMD10' was not declared in this scope

return readRegister(CMD10, cid);

^

C:\Program Files\Arduino\libraries\SD\src/SdSpiCard.h: In member function 'bool SdSpiCard::readCSD(csd_t*)':

C:\Program Files\Arduino\libraries\SD\src/SdSpiCard.h:142:25: error: 'CMD9' was not declared in this scope

return readRegister(CMD9, csd);

^

C:\Program Files\Arduino\libraries\SD\src/SdSpiCard.h: In member function 'uint8_t SdSpiCard::cardAcmd(uint8_t, uint32_t)':

C:\Program Files\Arduino\libraries\SD\src/SdSpiCard.h:252:17: error: 'CMD55' was not declared in this scope

cardCommand(CMD55, 0);

^

In file included from F:\Mijn Documenten\Arduino\Teensy\SdFat-1.0.7\SdFat-1.0.7\examples\QuickStart\QuickStart.ino:4:0:

C:\Program Files\Arduino\libraries\SD\src/SdFat.h: In member function 'void SdFileSystem<SdDriverClass>::initErrorPrint(Print*)':

C:\Program Files\Arduino\libraries\SD\src/SdFat.h:198:30: error: 'SD_CARD_ERROR_CMD0' was not declared in this scope

if (cardErrorCode() == SD_CARD_ERROR_CMD0) {

^

C:\Program Files\Arduino\libraries\SD\src/SdFat.h: At global scope:

C:\Program Files\Arduino\libraries\SD\src/SdFat.h:329:60: error: 'SPI_FULL_SPEED' was not declared in this scope

bool begin(uint8_t csPin = SS, SPISettings spiSettings = SPI_FULL_SPEED) {

^

C:\Program Files\Arduino\libraries\SD\src/SdFat.h:339:61: error: 'SPI_FULL_SPEED' was not declared in this scope

bool cardBegin(uint8_t csPin = SS, SPISettings settings = SPI_FULL_SPEED) {

^

C:\Program Files\Arduino\libraries\SD\src/SdFat.h:506:70: error: 'SD_SCK_MHZ' was not declared in this scope

bool begin(uint8_t csPin = SS, SPISettings settings = SD_SCK_MHZ(50)) {

^

QuickStart: In function 'void loop()':
QuickStart:15: error: 'SD_SCK_MHZ' was not declared in this scope
#define SPI_SPEED SD_SCK_MHZ(4)

^

F:\Mijn Documenten\Arduino\Teensy\SdFat-1.0.7\SdFat-1.0.7\examples\QuickStart\QuickStart.ino:102:29: note: in expansion of macro 'SPI_SPEED'

if (!sd.begin(chipSelect, SPI_SPEED)) {

^

'SD_SCK_MHZ' was not declared in this scope.
 
Status
Not open for further replies.
Back
Top