2015-11-18 11:08 PM
I am on a project with an STM32F407 on a custom board and I am having trouble with reading from a USB memory device.
The code framework is generated with CubeMX and setup to use FatFs and USB in host mode to access a USB memory stick.While it mostly seem to be working, that is the USB enumerates, FatFs mounts and I can display directories and read and write small files (like an ini config file), I have trouble reading larger files like WAV files that are used for audio play back through a DAC.When I open the WAV file, I read the header OK but as soon as I need to read more ( I read chunks of 2K bytes), the data I read is corrupt. Right after the f_read, I check the data buffer and there is corruption in the data. The buffer data is recognizable as I used a custom WAV file with a known simple waveform.The data that I see is like this:0, 0, 400, 0, 800, 0, 1200, 0, 1600, 0, 2000, 0, 2400, 0, 3568, 10, <<< CORRUPT FROM HERE32768, 12, 4096, 14, 40960, 15, 12288, 17, 49152, 18, 20480, 20, 57344, 21, 28672, 23, I noted that even though the data is corrupt, it is fairly consistent from cycle to cycle i.e. every time I read the file it is the same corruption.What could be the cause of this? I already spend days on this on something which is quite an obscure problem that may be lurking on the low level libraries or the CubeMX configuration that I may not understand or have missed (documentation is not very clear :( )Any help much appreciated.2015-11-19 04:07 AM
When I do files system and IO sub-system validation I write very long streams of pseudo-random data that are easy to check, and hard for the system to accidentally get right with any common failure modes.
Suggest you validate the FatFs via USB writer thoroughly, and document the failure(s) to ST. If it validates Ok, then review more carefully what you are doing with the data and the file system. The consistent failure is a bit odd, does it fall on a 64-byte boundary?