Max File Size Readable by Teensy 4.1 Built-In SD

grinch

Well-known member
Hi, I'm working on a project where I need to read a large audio file off the built-in SD card reader on the Teensy 4.1 (4 16-bit channels, roughly 1 hour of audio, 48kHz, raw audio data format, about 1.5 GB). I've programmed my own handler for this which uses the SD library directly, so this isn't an audio library question. I'm getting an error where my file isn't being read by my file open function, and before going further with debugging I figured I'd check to make sure that reading a file of that size won't cause an issue.

Is there any limit on the filesize that the SD library and the built-in reader can work with, or is this just limited by the storage on the SD card itself? And any other common issues I should check on?

I've already done the obvious and made sure my file is indeed on the card and that it's named correctly. Here is the function I'm using to open the card in case that's relevant (I'm getting the "File Not Found!" error):

Code:
bool CopyBufferSD::open(const char *filename)
{
	__disable_irq();
	rawFile = SD.open(filename);
        Serial.println(filename);
	Serial.println(rawFile.available());
	__enable_irq();
	if (!rawFile) {
                Serial.println("File not found!");
		return false;
	}
	return true;
}
 
What's the file name? It has to be in 8.3 format.

Code:
Serial.println(rawFile.available());
I think this will crash the Teensy if there's no file because rawFile will be NULL.

Pete
 
What's the file name? It has to be in 8.3 format.

Code:
Serial.println(rawFile.available());
I think this will crash the Teensy if there's no file because rawFile will be NULL.

Pete

PLAY.data is the filename. What does 8.3 mean? Does the type need to be shorter? Could change it to .dat 🤷*♂️

That line actually doesn't crash the Teensy which is weird. Just returns 0, and continues on to my other print statements. Not the behavior I'd expect either but I'll take it lol.
 
PLAY.data is the filename. What does 8.3 mean? Does the type need to be shorter? Could change it to .dat

The original FAT filesystem only supports file names with at most 8 characters, followed by a dot, followed by at most 3 characters.

The way Windows added support for longer file names is via VFAT. There, each file has a 8.3 filename (in your case it would probably be PLAY~1.DAT – but I'm just guessing, I don't even have a Windows machine anymore!), and a "full" VFAT filename if the filename cannot be represented in the limited 8.3 format.

To reduce resource use, the standard SD library does not support VFAT, only the 8.3 names. (That is, it does not matter if the filesystem has VFAT and long filename support, as long as you use the 8.3 format names in your Teensy code. Because it can be nontrivial to find out what the 8.3 name is, it is better to make sure the filename is in the 8.3 format – at most eight letters or digits, followed by a dot, followed by at most three letters or digits – and It Will Just Work.)
 
Also, make sure that any alpha characters in the file name and extension are upper case. Lower case characters will result in a LFN even if the name fits in 8.3.
 
Right now, the default SD library uses the FAT32 filesystem (as others have said, the name must adhere to the original 8.3 naming scheme). The FAT32 filesystem has a limit that any one file cannot be more the 4 gigabytes.

In addition, SD cards have levels, original SD/micro-Sd cards are limited to 1-2 gigabytes for the whole card. The next size up (SD-HC) is supported by the SD library. SD-HC cards are 2 - 32 gigabytes, and use the FAT32 file system. Above 32 gigabyte cards, the level is SD-XC. The filesystem used is exFat. The current SD library does not support this. The current beta (1.54 beta 4) is replacing the SD library with the SdFat library. The SdFat library can handle the exFat level. I don't know if there are sd/micro-sd card readers out there that can handle SD-HC but not SD-XC at the electrical level, but there might be.
 
The original FAT filesystem only supports file names with at most 8 characters, followed by a dot, followed by at most 3 characters.

The way Windows added support for longer file names is via VFAT. There, each file has a 8.3 filename (in your case it would probably be PLAY~1.DAT – but I'm just guessing, I don't even have a Windows machine anymore!), and a "full" VFAT filename if the filename cannot be represented in the limited 8.3 format.

To reduce resource use, the standard SD library does not support VFAT, only the 8.3 names. (That is, it does not matter if the filesystem has VFAT and long filename support, as long as you use the 8.3 format names in your Teensy code. Because it can be nontrivial to find out what the 8.3 name is, it is better to make sure the filename is in the 8.3 format – at most eight letters or digits, followed by a dot, followed by at most three letters or digits – and It Will Just Work.)

This fixed my problem, thanks! In answer to my own question and in case anyone is wondering the same thing, I'm currently reading a 1.3GB file with no issues.
 
Back
Top