AnsweredAssumed Answered

STM32 Host USB Memory FatFs reads corrupt data

Question asked by Hess.Marco on Nov 19, 2015
Latest reply on Nov 19, 2015 by Clive One
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 HERE
32768, 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.