I am attempting to load a WAV file from an SD card on the Daisy Patch. I’m able to browse the contents of the card, but when I attempt to use f_read
it returns FR_DISK_ERR
.
This is my open
function that attempts to read the file. I have adapted it from an earlier project of mine for an ST development board where it is working fine. The f_open
and f_lseek
calls are both successful, any ideas why f_read
might fail this way? I’m able to browse the card before and after the failed read, so I think the configuration is mostly okay.
bool FileHandle::open(const char* fileName)
{
FRESULT res;
FIL waveFile;
UINT bytesRead;
char filePath[256];
sprintf(filePath, "%s/%s", fileSystem.getCurrentPath(), fileName);
debugPrint("FileHandle::open( %s )\r\n", fileName);
debugPrint("current directory: %s\r\n", fileSystem.getCurrentPath());
if((res = f_open(&waveFile, filePath, FA_OPEN_EXISTING | FA_READ)) != FR_OK)
{
debugPrint("Unable to open WAVE file '%s'\r\n", filePath);
return false;
}
if((res = f_lseek(&waveFile, 0)) != FR_OK)
{
debugPrint("Unable to seek, %s\r\n", getFatFSErrorCode(res));
return false;
}
// Read and validate the RIFF header
if((res = f_read(&waveFile, &m_waveDesc, sizeof(WaveDesc), &bytesRead)) != FR_OK && bytesRead != sizeof(WaveDesc))
{
debugPrint("Invalid WAV file, %s\r\n", getFatFSErrorCode(res));
return false;
}
...