1

I'm using STM32F105 USB OTG standard libraries to drive USB flash in mass storage mode. It works fine with some USB memories models but not with all models. In the ST documents is written "Complies with the On-The-Go Supplement to the USB 2.0 Specification (Revision 1.0a)".

I have problem with the most of USB 2.0 flash memories that I've bought recently. Is it about "Revision 1.0a"? and is there a way to modify the library to support newest models?

electro
  • 375
  • 1
  • 3
  • 13
  • 1
    I doubt it has anything to do with "Revision 1.0a". This revision applies to the OTG specs, which in no ways define how to interface a mass storage device specifically. This spec describes what happens at a lower hardware level. I am, however, 100% sure that, at the hardware level, STM32 can talk with *any* flash memory that complies with the USB spec (of whatever revision). So, yes, I am sure there is a way to modify the library to support newest models, since it is a software problem (probably closer to the filesystem structure than the OTG signaling). – dim Jan 23 '17 at 10:54
  • Technically, I have fully answered both your questions. But I expect you are not satisfied, are you? Maybe you want to reformulate and ask *what* in the libraries must be improved to support all flash drives (note that I won't be able to answer that part, however, which is why I just write comments here). – dim Jan 23 '17 at 10:57
  • Thanks @dim. No, really I don't expect you to help me modifying the library. Your answer helps me to not searching in wrong place. – electro Jan 24 '17 at 14:07

2 Answers2

3

Mass storage is a bit of a tricky one. In terms of the software stack, there are really three layers that connect your fopen/fclose to the bits in the flash drive itself:

1) The USB host driver. This manages the low level communications on the bus. The STM32F library fully supports all the requirements of the USB standard in this regard, so you can theoretically connect to anything that is USB 2.0 compliant.

2) The mass storage device driver. The USB standard defines protocols for a few higher level device classes that are commonly used (things like audio, keyboards, mass storage) and mass storage is one of them. However, the mass storage device class is rather broad, covering about 40+ years of varying standards and protocols for talking to storage media. The STM32F library only implements one particular SCSI command set, but this is used by pretty much every flash drive I have ever come across so I doubt this is the problem.

3) The file system driver. The mass storage driver really just exposes raw blocks of memory that can be read and write. A computer can put whatever it likes into these data blocks. However, to be able to use the flash drive between different systems it needs to be structured with a particular file system. The STM32F library uses the FatFS software library to implement a lightweight FAT32 file system. This sits at the top of the software stack and exposes the fopen/fclose etc API that you then use to read from the drive.

So if your flash memory is not working, then the problem likely lies in either layer 2 or 3. My guess would be it lies in layer 3, and that the drives are not formatted with FAT32. Unfortunately FAT32 is getting quite old now, and can only handle drives up to 32GB, and as many new flash drives are much bigger than this they are formatted with something else.

Reading newer file systems is a real pain, because Microsoft keeps them patent encumbered, meaning there is not much open source support, but you should be able to format your drives with FAT32 provided you don't need to support more than the 32GB limit.

Jon
  • 4,894
  • 13
  • 20
  • Thanks @Jon. Your answer is perfect. I think you are right and my problem may be in layer 3 (in file system), because I can detect the flash memory when it is inserted but I can't see its content (about memories that I have problem with them). But I've formatted all of them with FAT32. So do you have any new idea? – electro Jan 24 '17 at 14:19
  • @Saeed Are the flash drives that aren't working greater than 32GB? I also just checked the fatfs page and it seems it now supports exFAT (though you need to pay Microsoft to use this in a product) though I don't know if the version in the ST libraries has this. You probably need to read up a bit more on what FatFS supports and check that the flash drives complies. Things like sector sizes can cause problems. – Jon Jan 24 '17 at 14:28
  • No @Jon, all the flash memories that I have tested are below 8GB. Let me say clearly that I've done this project about 4 years ago, and in that time it was working with almost all flash memories (most those days brands like Transcend, Kingston, ...). But recently with new memories (like ADATA, ...) I have this problem. – electro Jan 25 '17 at 06:47
1

We had a similar issue and it turned out that our hardware circuit was wrong. We had 22 Ohm resistors in ND and PD lines. We replaced with 0 Ohm and all the memory sticks work now.