Hi,
I'm having trouble reading directly from the SD card into PSRAM. I'm using a Teensy 4.1 with one 8MB PSRAM chip. When I pass a pointer in PSRAM to the FsFile read function, the read would often fail. The same read succeeds reliably when I pass a pointer in the internal RAM. The T4.1 is not connected to anything so it seems that the PSRAM access is interfering with the SD card access. Has anyone seen similar problems? I created a test program to reproduce it.
The test has 4 variants:
1: Read from SD to PSRAM. This fails most of the time
2: Read from SD to ITCM. This passes reliably.
3: Read from SD to ITCM then copy to PSRAM. This fails occasionally.
4: Read from SD to ITCM then copy to PSRAM and flush the PSRAM cache. This passes reliably.
Place a large file named TESTFILE.BIN in the root of the SD card and enter the variant in the serial console when prompted.
I'm using Arduino 1.8.13, Teensyduino 1.53 and Bill Greiman's latest SdFat-beta. I tried 2 SD cards (SDXC with EXFAT and SDHC with FAT32) and the result is the same. I don't think it's a problem with the soldering because I tried Paul's PSRAM test and it passed. And I don't think it's a problem with the SD card or the SdFat library either because the reads into ITCM works reliably.
I'm having trouble reading directly from the SD card into PSRAM. I'm using a Teensy 4.1 with one 8MB PSRAM chip. When I pass a pointer in PSRAM to the FsFile read function, the read would often fail. The same read succeeds reliably when I pass a pointer in the internal RAM. The T4.1 is not connected to anything so it seems that the PSRAM access is interfering with the SD card access. Has anyone seen similar problems? I created a test program to reproduce it.
Code:
#include "SdFat.h"
#define BUFSIZE (256*1024)
#define FILENAME "TESTFILE.BIN"
SdFs sd;
FsFile file;
char itcmBuf[BUFSIZE];
EXTMEM char psramBuf[BUFSIZE];
bool runTest(int variant){
Serial.print("running variant ");
Serial.println(variant);
file.open(FILENAME);
if(!file){
Serial.println("file open failed");
return false;
}
int total_bytes_read = 0;
while(file.available()){
int bytes_read;
if(variant == 1){
bytes_read = file.read(psramBuf, BUFSIZE);
}else{
bytes_read = file.read(itcmBuf, BUFSIZE);
}
if(bytes_read < 0){
Serial.print("read failed after ");
Serial.print(total_bytes_read);
Serial.println(" bytes");
file.close();
return false;
}else{
//Serial.println("read ok");
total_bytes_read += bytes_read;
}
if(variant == 3 || variant == 4){
memcpy(psramBuf, itcmBuf, BUFSIZE);
if(variant == 4){
arm_dcache_flush_delete(psramBuf, BUFSIZE);
}
}
}
Serial.println("reads succeeded");
file.close();
return true;
}
void setup() {
Serial.begin(115200);
while(!Serial);
while (!sd.begin(SdioConfig(FIFO_SDIO))) {
Serial.println("SdFs begin() failed");
}
sd.chvol();
// stress test
// while(runTest(4));
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Select test variant");
Serial.println("1: SD -> PSRAM");
Serial.println("2: SD -> ITCM");
Serial.println("3: SD -> ITCM, ITCM -> PSRAM");
Serial.println("4: SD -> ITCM, ITCM -> PSRAM with cache flush");
int variant = 0;
while(variant == 0){
while(!Serial.available());
char c = Serial.read();
if(c >= '1' && c <= '4'){
variant = c - '0';
}
}
runTest(variant);
}
The test has 4 variants:
1: Read from SD to PSRAM. This fails most of the time
2: Read from SD to ITCM. This passes reliably.
3: Read from SD to ITCM then copy to PSRAM. This fails occasionally.
4: Read from SD to ITCM then copy to PSRAM and flush the PSRAM cache. This passes reliably.
Place a large file named TESTFILE.BIN in the root of the SD card and enter the variant in the serial console when prompted.
I'm using Arduino 1.8.13, Teensyduino 1.53 and Bill Greiman's latest SdFat-beta. I tried 2 SD cards (SDXC with EXFAT and SDHC with FAT32) and the result is the same. I don't think it's a problem with the soldering because I tried Paul's PSRAM test and it passed. And I don't think it's a problem with the SD card or the SdFat library either because the reads into ITCM works reliably.