FAT32 USB pen drive partition information

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
Sparky1039
Posts: 1179
Joined: 24 Nov 2005 20:07
Location: Colorado, USA

FAT32 USB pen drive partition information

#1 Post by Sparky1039 » 10 Oct 2014 21:01

In my efforts to understand how to use the USB host and FAT32 libraries with USB pen drives, I also experienced that some drives could not be read or accessed by the FAT32_Init() function. Turns out those pen drives experiencing this problem were not formatted entirely correct for this application.

When formatting your USB pen drives make sure the main partition attribute is set to PRIMARY partition. For all of the "failed" drives this attribute was set to LOGICAL partition. The mikroE FAT32 library functions seem to have difficulty accessing those partitions set as logical. Using the windows format/partition application does not provide the user access to this attribute. I had to use a third party formatting/partitioning tool to change it (my tool of choice was EaseUS Partition Master).

This bit of information may also apply to SD cards too. I personally haven't verified this, but it would make sense and may explain why so many users have had difficulty accessing various MMC cards in the past if they weren't formatted correctly.

The FAT32 help file does mention about primary and logical partitions but I found it somewhat vague like...
...the library will work with the first available primary (logical) partition that has non-zero size.
To me this help file quote is confusing. Which is it, primary or logical??? Unfortunately mE sends you off to fend for yourself in understanding the nuances of mass storage devices and FAT allocation formats.

HTH.

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: FAT32 USB pen drive partition information

#2 Post by marina.petrovic » 13 Oct 2014 14:06

Hi,

The note which you mentioned from library Help file is related with storage device which have Master Boot Record (MBR).
In that case library will work only with first available primary partition and first available logical partition that has non-zero size.

Mass Storage Device example is tested with some "older" flash drives (for example, 1GB Kingston).
FAT32 Library have some problems with some newer version of SD cards and flash drives, as is Class 10.
Our software developers are familiar with this and they will certainly try to add some modification in existing FAT32 library.

Thank you very much for sharing your observations with our users.
I am very sorry for any inconvenience.

Best regards,
Marina

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: FAT32 USB pen drive partition information

#3 Post by Rotary_Ed » 17 Oct 2014 14:17

Thanks, Sparky

I found that only one of the flash drives I have will work with the FAT32_Init function. It is a SanDisk Cruzer 8 GB (white Tab). I tried several SanDisk Ultra models and none of them worked. One thing that I am uncertain about, it appears according to partition information that the one unit that works has a FAT32 format with a Cluster size of16,384 bytes - which rather surprised me.

Can you tell me what cluster size the working disk you have??

Thanks again
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re:FAT INIT ERROR was FAT32 USB pen drive partition informat

#4 Post by Rotary_Ed » 17 Oct 2014 16:54

Ok, in addition to the Primary designation of the Partition as mentioned my Sparky, I found that (at least in my case) there was one additional requirement.

I found that I had to format the Flash Drive with the bytes per sector set to 512 (default in most cases) but the bytes per cluster (not sector) had to be set to 16K. That surprised me until I did a little research and found that with the Flash Drive capacity getting up to many GB that many of the manufactures are using larger size cluster to speed up things.

I then recalled I had noticed that when I had the FAT file system give me the format data on the one drive (that had worked) that it showed
16,384 bytes per cluster (same as 32 sectors per cluster). So after the aboved mentioned research, I set the format to 16K per cluster.

I then format three Flash drives of two different makes with 16K chosen on the format window for bytes/cluster and they all now work.
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Sparky1039
Posts: 1179
Joined: 24 Nov 2005 20:07
Location: Colorado, USA

Re: FAT32 USB pen drive partition information

#5 Post by Sparky1039 » 17 Oct 2014 18:45

Of two pen drives I was able to check, the cluster size was 512 bytes on an old 128MB drive and 4096 bytes for a 4GB drive. I unfortunately don't have anything larger on hand at the moment. Both of these work just fine with the mE FAT32 library drivers once they were set to primary partition. mE needs to revise their documentation to reflect the cluster size capability especially since the FAT32 library is probably one of the most used external sources of code for their compilers (USB host coming in a strong second).

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: FAT32 USB pen drive partition information

#6 Post by Rotary_Ed » 17 Oct 2014 19:32

It is something that does need to be reviewed at a minimum. I have no explanation for why my drives would not work unless I had the bytes/cluster set to 16K. It would never have occurred to me to set it at that value, except that is what the FAT32 told me my one working drive was formatted to. I could never check if the different drives would have shown their bytes/cluster setting with the FAT32 because they would never get past the FAT INIT ERROR message.

However, I Just went back and formatted a FAT16 Flash drive to FAT32 with 4K bytes/cluster and it worked this time. So I agree with you Sparky, apparently the bytes/Cluster is not the critical parameter I thought it was.
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Re: FAT32 USB pen drive partition information

#7 Post by Rotary_Ed » 17 Oct 2014 19:34

I forgot to mention that after I formatted that last drive with a 4K bytes/Cluster - that is what (4096 bytes/cluster) that the MK FAT32 system reported. So clearly it recognizes the different bytes/cluster and apparently can work with any legal size.
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Post Reply

Return to “Library Development Discussion”