Teensy 4.1 Cannot access Internal SD card

I'm using PlatformIO 5.1.0 (+Visual Code) with a Teensy 4.1.
As you could probably guess from below, I'm trying to get ArduinoMenu going with SdFat (cards are small FAT16 for a reason) and a rotary encoder.
All libs and platform software are up-to-date.
I'm getting "'BUILTIN_SDCARD' was not declared in this scope"

Where is that symbol actually declared? what's its value on a Teensy 4.1?

Any help is appreciated!

PACKAGES:
- framework-arduinoteensy 1.153.0 (1.53)
- toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
Dependency Graph
|-- <MIDI Library> 5.0.2
|-- <USBHost_t36> 0.1
|-- <Encoder>
|-- <Adafruit BusIO> 1.7.1
| |-- <Wire> 1.0
| |-- <SPI> 1.0
|-- <ArduinoMenu library> 4.21.3
| |-- <SdFat> 2.0.4
| | |-- <SPI> 1.0
| |-- <ClickEncoder> 0.0.0-alpha+sha.9337a0c46c
| |-- <Wire> 1.0
| |-- <Adafruit GFX Library> 1.10.5
| | |-- <Adafruit BusIO> 1.7.1
| | | |-- <Wire> 1.0
| | | |-- <SPI> 1.0
| | |-- <Wire> 1.0
| | |-- <SPI> 1.0
|-- <ClickEncoder> 0.0.0-alpha+sha.9337a0c46c
|-- <SdFat> 2.0.4
| |-- <SPI> 1.0
|-- <SPI> 1.0
|-- <Adafruit GFX Library> 1.10.5
| |-- <Adafruit BusIO> 1.7.1
| | |-- <Wire> 1.0
| | |-- <SPI> 1.0
| |-- <Wire> 1.0
| |-- <SPI> 1.0
|-- <Adafruit SSD1306> 2.4.3
| |-- <Adafruit GFX Library> 1.10.5
| | |-- <Adafruit BusIO> 1.7.1
| | | |-- <Wire> 1.0
| | | |-- <SPI> 1.0
| | |-- <Wire> 1.0
| | |-- <SPI> 1.0
| |-- <SPI> 1.0
 
Hi.

I cannot get the Teensy 4.1 SD card reader to recognise any SD card. I have tried 2 different Teensy 4.1 modules and 8 different sizes and brands of SD card. I've even tried 2 different PC's and USB cables - clutching at straws, I know. I've used the BUILTIN_SDCARD in this and a number of other example programs, but they consistently find 'no card'. The fact that they compile correctly tells me that they are using the correct Teensy SD.h//SDFat.h etc.

The cards all format and read fine on my PC and via a Arduino Mega2560 card reader.

I have an ethernet Magjack wired to both Teensy modules; would this stop it recognising the SD card reader? There are no other peripherals connected.
 
Hi.

I cannot get the Teensy 4.1 SD card reader to recognise any SD card. I have tried 2 different Teensy 4.1 modules and 8 different sizes and brands of SD card. I've even tried 2 different PC's and USB cables - clutching at straws, I know. I've used the BUILTIN_SDCARD in this and a number of other example programs, but they consistently find 'no card'. The fact that they compile correctly tells me that they are using the correct Teensy SD.h//SDFat.h etc.

The cards all format and read fine on my PC and via a Arduino Mega2560 card reader.

I have an ethernet Magjack wired to both Teensy modules; would this stop it recognising the SD card reader? There are no other peripherals connected.

Hi, I don't have any particular insight, but I've been using the SD reader for a while now and it does work.

Fairly obvious suggestions:
1.Format the SD cards with the official formatter:
https://www.sdcard.org/downloads/formatter/

2. Post pictures and code here. Usually someone gets back with suggestions pretty quickly.

3. Is it possible you damaged something installing the Magjack? Tiny board, hot iron.

Good luck.
 
Thanks for the replies. I did most of my testing with one SD card which seems to be faulty and when I tried other SD cards, it seems to have been with a program which used the wrong SD.h.
All now working with 7 out of 8 SD cards. The other one works perfectly on PC's but not Teensy.
All good to proceed, thanks for the help.
 
I'm trying to get the internal SD card on a Teensy 4.1 working. I have used the examples that Paul suggested at: https://github.com/PaulStoffregen/SD...9f246b20be1282

When I run the CarfInfo.ino example, I get the error messages listed below. The only modification I made was to uncomment BUILTIN_SDCARD so that it would use the internal card. chipSelect is declared in the CardInfo.ino example. Also - what do I do with the Chip Select assignment when using the built-in card as I assume no external I/O pin is required?

Final question - I plan to write quite a lot of logged data to the SD card at pretty quick rates - 4 serial ports running at 115200 baud - although bandwidth is not 100% utilised. Are the SD write routines blocking, or occurring in the background?

thanks

----------------------------------------------------
ERROR MESSAGE:
In file included from C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:23:0:
C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SD\src/SD.h:38:24: error: expected unqualified-id before numeric constant
#define BUILTIN_SDCARD 254
^
C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:36:1: note: in expansion of macro 'BUILTIN_SDCARD'
BUILTIN_SDCARD
^
C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino: In function 'void setup()':
C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:60:34: error: 'chipSelect' was not declared in this scope
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
^
C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:114:23: error: no matching function for call to 'SdFile::eek:penRoot(SdVolume&)'
root.openRoot(volume);
^
In file included from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsLib.h:32:0,
from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/SdFat.h:35,
from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SD\src/SD.h:27,
from C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:23:
C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsFile.h:458:8: note: candidate: bool FsBaseFile::eek:penRoot(FsVolume*)
bool openRoot(FsVolume* vol);
^
C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsFile.h:458:8: note: no known conversion for argument 1 from 'SdVolume' to 'FsVolume*'
Error compiling for board Teensy 4.1.
 
I'm trying to get the internal SD card on a Teensy 4.1 working. I have used the examples that Paul suggested at: https://github.com/PaulStoffregen/SD...9f246b20be1282

When I run the CarfInfo.ino example ...

Starting with {local install}\hardware\teensy\avr\libraries\SD\examples\CardInfo\CardInfo.ino

To run on a T_4.1 the only change to make and see it working is:
Code:
const int chipSelect = BUILTIN_SDCARD;

With a good install of TeensyDuino and T_4.1 as the board the item BUILTIN_SDCARD is already defined, and it must just be set into the const int chipSelect as above.
 
Use the simpler SD library. Internally it uses SdFat (we abandoned the ancient Arduino SD library code with Teensyduino version 1.54), so don't worry, you're not losing anything by using SD.h.


Final question - I plan to write quite a lot of logged data to the SD card at pretty quick rates - 4 serial ports running at 115200 baud - although bandwidth is not 100% utilised. Are the SD write routines blocking, or occurring in the background?

It's blocking.

To avoid loss of incoming serial data during the (rare) moments the SD card takes longer to write, use addMemoryForRead() to increase the serial receive buffer size, or use hardware flow control if your serial device supports RTS/CTS. Details on both here:

https://www.pjrc.com/teensy/td_uart.html

You'll get better SD write performance if you compose your data to write to the card in a buffer which is a multiple of 512 bytes and then write the buffer all at once.

Cards with a "A1" or "A2" rating have optimization for 4096 byte buffer size. Older cards often want larger buffers for best performance. But the speed you will need should be possible on any card with 512 byte buffers. Even the worst cards can usually sustain 16 bit stereo audio recording (176 kbytes/sec) that way, which is a lot more data than 4 serial ports at ~11 kbytes/sec each.

Again, there's no real performance advantage to using the more complicated SdFat examples. The Arduino SD.h library has a bad reputation and a lot of guides online say to use SdFat for performance. But we no longer use the old SD with Teensy. Starting with Teensyduino 1.54, the SD.h library is just a thin compatibility wrapper which uses SdFat for everything. And if you really do need some special SdFat feature, you can still use it. See the File > Examples > SD > SdFat_Usage example for details. So please, do yourself a favor and go with the much simpler SD library examples.
 
Thanks for the feedback. I made that change then hit another Error:

Arduino: 1.8.15 (Windows 10), TD: 1.54, Board: "Teensy 4.1, Serial, 600 MHz, Faster, US English"

C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino: In function 'void setup()':

C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:114:23: error: no matching function for call to 'SdFile::eek:penRoot(SdVolume&)'

root.openRoot(volume);

^

In file included from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsLib.h:32:0,

from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/SdFat.h:35,

from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SD\src/SD.h:27,

from C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:23:

C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsFile.h:458:8: note: candidate: bool FsBaseFile::eek:penRoot(FsVolume*)

bool openRoot(FsVolume* vol);

^

C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsFile.h:458:8: note: no known conversion for argument 1 from 'SdVolume' to 'FsVolume*'

Error compiling for board Teensy 4.1.
 
Paul, Thanks for the tips. With the Teensy 3.5 in a similar situation I modified the SERIALn_RX_BUFFER_SIZE definition in each of the underlying libraries (I got that advice from this forum somewhere), but see in the 4.1 the serial libraries are not setup in the same way. I wasn't aware of the addMemoryForRead() function and will give that a try. Is the addMemoryForRead() buffer array a new array that is used in addition to the buffer that already exists within the serial libraries, or by defining a new array it replaces the existing buffer?

Unfortunately serial flow control isn't an option for this app as it is too real time. I did place the footprint for a second Teensy 4.1 on the PCB dedicated purely as a data logger to slave of the first Teensy in case I hit any SD card blocking issues.

Regarding the simpler SD library ? Is that the standard Arduino SD library https://www.arduino.cc/reference/en/libraries/sd/ ? I assume with the TeensyDuino install it still supports the built-in SD Card with 4 bit mode?

thanks again
 
Regarding the simpler SD library ? Is that the standard Arduino SD library
That IS the "standard Arduino SD library" but NOT the one you should use.
If the compiler/linker does use this one you will get an error.
If you wish to use the Arduino one for other MCU targets then it is better to temporarily rename it to something else perhaps .../sdz/..
Without the Arduino SD library being visible, the compiler/linker will use the Teensy version.
 
I made that change then hit another Error:

From the error message, it's pretty clear you did not in fact click File > Examples > SD > CardInfo and use that simpler example code (or any of the examples from File > Examples > SD). The error messages clearly indicate you're still using "Teensy_4.1_SD_Card_Test.ino", which appears (guesswork since we can't see your screen) to be an example copied from the SdFat library.

Again, my advice is still: "do yourself a favor and go with the much simpler SD library examples".
 
Regarding this question:

Regarding the simpler SD library ? Is that the standard Arduino SD library https://www.arduino.cc/reference/en/libraries/sd/ ? I assume with the TeensyDuino install it still supports the built-in SD Card with 4 bit mode?

I tried to explain this in msg #35 with the words: "Starting with Teensyduino 1.54, the SD.h library is just a thin compatibility wrapper which uses SdFat for everything".

It is *not* the same code as Arduino publishes. It is a thin compatibility wrapper which uses the highly optimized SdFat library, but gives compatibility with the simple SD.h library.

My advice is still the same. Use the simple way with #include <SD.h> and do not include SdFat.h in your program. It is the same speed as the complicated way. You're only just making everything more difficult than necessary.
 
The project I created is called Teensy_4.1_SD_Card_Test.ino. The only text in the .ino file is an exact cut and paste of the CardInfo code from:
https://github.com/PaulStoffregen/S...9f246b20be1282/examples/CardInfo/CardInfo.ino
The only change I've made is: const int chipSelect = BUILTIN_SDCARD;
The file has the correct SD.h inclusion:
#include <SD.h>

So, I then copied the CardInfo.ino example from:
C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SD\examples\CardInfo\CardInfo.ino
to a new folder, changed the ChipSelect to BUILTIN_SDCARD, and everything worked fine.

I then went back and exactly copied the code again from:
https://github.com/PaulStoffregen/S...9f246b20be1282/examples/CardInfo/CardInfo.ino
then changed the chip select to BUILTIN_SDCARD and got exactly the same error as I originally posted.

I repeated the entire steps above just to be sure and the same results occured when copying the code from.
https://github.com/PaulStoffregen/S...9f246b20be1282/examples/CardInfo/CardInfo.ino
and then everything worked using:
C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SD\examples\CardInfo\CardInfo.ino

I've got working code now, but I don't think I was doing anything incorrectly as I had followed the GitHub examples.
------------------------------------------------------------------------------------------------------------------------

C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:114:23: error: no matching function for call to 'SdFile::eek:penRoot(SdVolume&)'
root.openRoot(volume);
^
In file included from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsLib.h:32:0,
from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/SdFat.h:35,
from C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SD\src/SD.h:27,
from C:\Users\David\Documents\Arduino\Teensy_4.1_SD_Card_Test\Teensy_4.1_SD_Card_Test.ino:23:
C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsFile.h:458:8: note: candidate: bool FsBaseFile::eek:penRoot(FsVolume*)
bool openRoot(FsVolume* vol);
^
C:\Program Files (x86)\Arduino_1.8.15\hardware\teensy\avr\libraries\SdFat\src/FsLib/FsFile.h:458:8: note: no known conversion for argument 1 from 'SdVolume' to 'FsVolume*'
Error compiling for board Teensy 4.1.
 
The console output isn't showing the 'Libraries Used' section - though the path suggests the one with errors is from the right place.

It also suggests the IDE is 1.8.15 - an older version than the current in use IDE 1.8.19

Also what version of TeensyDuino is installed? The latest release is 1.57

No reason to use github copy if th elocal install works - though if the TeensyDuino installed is old there may be some conflict with other updates to SD.h or SdFat code.
 
I'm glad you got it working.

Why it works in one scenario and not another is a mystery to me. Now that you have a way which works, do you really want to spend more time to discover why it did not work the other way?


As only a general guideline, your best and easiest path to examples is to click File > Examples in Arduino. This will open example programs which came with the actual copies of the libraries you have installed. Usually grabbing code from Github or other websites also works, but sometimes it's easy to make a mistake, like copying an incompatible version. The File > Examples menu is a much easier and more reliable way to get the proper examples for the libraries you actually have installed.
 
Going to have to do some thread necromancy with this, as I'm having the exact same problems as listed above.

Getting "initialization failed" over and over. Tried with 2 different sd cards:
- unbranded 32gb microsdhc
- transcend 1gb microsd

Both formatted to fat32, both perfectly usable on computer via usb-reader.
Tested with all SD examples included, changing chipSelect to BUILTIN_SDCARD as expected, but always get the error, no matter what I do...

Arduino IDE 2.2.1 + Teensy 1.58.1
 
Going to have to do some thread necromancy with this, as I'm having the exact same problems as listed above.

Getting "initialization failed" over and over. Tried with 2 different sd cards:
- unbranded 32gb microsdhc
- transcend 1gb microsd

Both formatted to fat32, both perfectly usable on computer via usb-reader.
Tested with all SD examples included, changing chipSelect to BUILTIN_SDCARD as expected, but always get the error, no matter what I do...

Arduino IDE 2.2.1 + Teensy 1.58.1

Seems as though formatting the 32gb one with the official sd card formatter tool has made it work. The other one remains unusable, I'm guessing it might be too old for the library to properly work with it.
 
Back
Top