Closed MarianoDesivo closed 2 years ago
Hi @MarianoDesivo
The FIL
object you're using has been created on the stack, and is therefore inaccessible to the SD peripheral.
It's interesting that the f_open
call passes at all, but it could be that it doesn't actually start to read any data via the peripheral until the seek/read functions that actually perform diskio.
If you move the FIL fil
object into global space it will be created in the default AXI SRAM
sector instead of on the DTCMRAM
used for the stack, and everything should work.
This is briefly touched on in the documentation for the FatFSInterface, but isn't specific about other FatFS objects, and should probably be mentioned in the SdmmcHandler, as well as having a dedicated guide in the docs. We'll work on getting some better documentation for this.
Great! Thanks Stephen
it's a bit untidy (and some missing prints) but it read everything OK now:
chunksize:↵ WAVE:↵ . bytesread: 4↵ .f bytesread: 4. bytesread: 4. bytesread: 4. bytesread: 4↵ .Subchunk1Size 16 bytesRead: 4↵ .AudioFormat 1 bytesRead 2↵ .NumofChan 2 bytesRead 2↵ .Samplerate 48000 bytesRead 4↵ .byteRate 192000 bytesRead 4↵ .Block Aling 4 bytesRead 2↵ .Bit Depth 16 bytesRead 2↵ .d . . . bytesRead 4↵ .Subchunk2Size 2979536 bytesRead 4 ↵ .f_lseek: C4.wav↵ .f_read: C4.wav bytesRead: 2979536↵
Also I used this AudioCallBack to play the wav file from the SDRAM and it is working:
for(size_t i = 0; i < size; i += 2)
{
static uint16_t indice = 0; //only from 0 to 64k
out[i] = s162f(SDRAMsamples[indice]) * 0.5f;
indice++;
out[i + 1] = s162f(SDRAMsamples[indice]) * 0.5f;
indice++;
}
Maybe I need to add a buffer instead of directly using the SDRAM in the AudioCallback
@MarianoDesivo Glad to hear it's working!
I recommend using size_t
or some other unsigned 32-bit int (e.g. uint32_t
) for your index so you don't run into any issues when you try to read beyond the 2^16 sample.
Otherwise, you can read directly from the SDRAM in the audio callback. There are no problems doing that.
The performance of the 64MB SDRAM isn't quite as fast as the internal memory, but it is still quite fast.
I'm going to close the issue, but feel free to keep commenting if you have any other questions on the subject :)
I am trying to load wav data into SDRAM. So first I open a file with f_open() which returns 0 (no error)
But then if I try f_lseek() or f_read(), it returns 1 (FR_DISK_ERR) It prints:
If I don't use f_lseek(), bytesRead becomes 2 million instead of 0, still gives me error (and it left some hundred bytes to read). I thought it could be a problem of the SDRAM, but that does not explain why f_lseek() does not work. On the example WavPlayer.cpp you use f_lseek and f_read, and they seems to work
Here is my code: