Possible issue in "__Lib_FAT32_Driver" of the Fat32 library

Beta Testing discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Possible issue in "__Lib_FAT32_Driver" of the Fat32 library

#1 Post by Dany » 11 Nov 2013 21:22

Hi,

Concerning the Fat32 library usage:

There is a possible error in the outcome of routine "FAT32_Dev_SectorCount" in unit "__Lib_FAT32_Driver" of the Fat32 example in the mP PIC mpkg file:

Code excerpt:

Code: Select all

   if (1 = ((csdbuf[0] and 0xC0) shr 6)) then
    begin
        size := 0;                             size := size shl 8;
        size := size + (csdbuf[7] and 0x3F);   size := size shl 8;
        size := size + csdbuf[8];              size := size shl 8;
        size := size + csdbuf[9];              size := size shl 0;

        // size is in 0.5MB, get size in sectors (assumed 512 bytes sector size)
        size := size * 1024;  // <--- must be: Size := (Size+1) * 1024
    end
See comment in above code.
The outcome of the unchanged routine will always be 1024 sectors (0.5 MB) too less.

Thanks in advance for changing this!
Last edited by Dany on 14 Nov 2013 13:10, edited 3 times in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Error in " __Lib_FAT32_Driver" of the Fat32 library

#2 Post by dejan.odabasic » 13 Nov 2013 21:11

Hello,

Here are the results of 8GB card I tested:
SD_Card_details.png
SD_Card_details.png (114.29 KiB) Viewed 4435 times
Best regards.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Error in " __Lib_FAT32_Driver" of the Fat32 library

#3 Post by Dany » 14 Nov 2013 12:03

Hi,

Thanks for your reply.

Well, the difference is only 0.5 Mb on 8 Gb... and I see that the PC calculations are the same as the drivers calculation... :?:

Anyway, I got the info from the "SD Specification Part1, Physical Layer Simplified Specification" document, see https://www.sdcard.org/downloads/pls/.

Extract of the content:
C_SIZE
This field is expanded to 22 bits and can indicate up to 2 TBytes (It is the same as the maximum
memory space specified by a 32-bit block address.)
This parameter is used to calculate the user data area capacity in the SD memory card (not include the
protected area). The user data area capacity is calculated from C_SIZE as follows:
memory capacity = (C_SIZE+1) * 512KByte
That was the reason for my reaction on the "__Lib_FAT32_Driver" code... :D Perhaps the document is wrong?

p.s. I weakened the title of the post. :D :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Possible issue in "__Lib_FAT32_Driver" of the Fat32 libr

#4 Post by dejan.odabasic » 14 Nov 2013 13:29

Hello,

It's just a matter of difference in specification version.
Explanation that you found is covered with following code:
SD card.png
SD card.png (37.4 KiB) Viewed 4416 times
Best regards.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Possible issue in "__Lib_FAT32_Driver" of the Fat32 libr

#5 Post by Dany » 14 Nov 2013 17:16

It's just a matter of difference in specification version.
Explanation that you found is covered with following code:
The specification version used for 8Gb cards is the version 2.0. You point in your code to version 1.x.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”