Author Topic: latest version  (Read 6959 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
latest version
« on: December 04, 2017, 03:01:58 PM »
Hi Mark,
  My current project is seeing a 8GB micro sd card as 4GB. Looking at the mass_storage.h header , it has :

   05.08.2014 Correct long file rename end of directory save            {1}
    15.08.2014 Corrected =! to !=                                        {2}
    29.08.2014 Correct creating additional directory clusters            {3}
    03.09.2014 Remove fnCreateFile(), fnSetFileLocation() and fnInsertLFN_name() parameter {4}
    03.09.2014 Reset any deleted location markers when moving to next paragraph {5}
    06.10.2014 Correct brackets in fnExtractLongFileName()                {6} [uFATV2.01]
[1] changes for formatting cards that previously didnt format.  . I think this was an update you gave me.


I tried copying over the files from the utasker demo that works, but got a heap of errors, see attached. 

As my own project is working well, I dont want to change over to a complete new utasker, I would like to just update the  mass_storage part.

Many Thanks
Neil
« Last Edit: December 04, 2017, 03:18:17 PM by neil »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: latest version
« Reply #1 on: December 04, 2017, 03:38:56 PM »
Neil

Which function is showing the wrong size?
Do you have the CSD that is read from the card?
Also, check that you use the latest version of fnCheckCSD() which automatic corrects SPI based connections that return a shifted CSD.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: latest version
« Reply #2 on: December 04, 2017, 04:41:30 PM »
Hi Mark,
  Thanks for the below.
I read the size and free space with the below. The card size is 8GB, and the checkcsd() function is the same.

ulong Freespace,CardSize;
ptrDiskInfo = fnGetDiskInfo(DISK_D);
Freespace=ptrDiskInfo->utFileInfo.ulFreeClusterCount * ptrDiskInfo->utFAT.ucSectorsPerCluster * ptrDiskInfo->utFAT.usBytesPerSector;
CardSize=ptrDiskInfo->ulSD_sectors * ptrDiskInfo->utFAT.usBytesPerSector;
 
Freespace=3516268544
CardSize=3531603968

CSD: 0x40 0x0e 0x00 0x32 0x5b 0x59 0x00 0x00 0x3a 0x4f 0x7f 0x80 0x0a 0x40 0x00 0x9d

I have attached the ptrDiskInfo  info.

Best Regards
Neil


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: latest version
« Reply #3 on: December 05, 2017, 01:39:51 PM »
Neil

This may not be an issue with utFAT but instead the fact that 4G is the largest number than an unsigned long can hold.

ulong Freespace,CardSize;
ptrDiskInfo = fnGetDiskInfo(DISK_D);
Freespace=ptrDiskInfo->utFileInfo.ulFreeClusterCount * ptrDiskInfo->utFAT.ucSectorsPerCluster * ptrDiskInfo->utFAT.usBytesPerSector;
CardSize=ptrDiskInfo->ulSD_sectors * ptrDiskInfo->utFAT.usBytesPerSector;


I think that these calculations are overflowing and so you are only seeing the 'remainder' after the overflow.

See a newer version of debug.c where this routine is used for the calculation:

    20.02.2012 Display large SD card sizes in kBytes to avoid 32 bit overflow {43}

static void fnDisplayDiskSize(unsigned long ulSectors, unsigned short usBytesPerSector) // {43}
{
    if (ulSectors >= 0x800000) {                                         // note that 512 byte sectors are assumed
        fnDebugDec((ulSectors/2), 0);                                    // the number of bytes cannot be held in a 32 bit number so display it in kBytes
        fnDebugMsg(" kBytes");
    }
    else {
        fnDebugDec((ulSectors * 512), 0);                                // the value can be displayed in bytes
        fnDebugMsg(" bytes");
    }
}


As you see, it displays in kBytes rather than Bytes once the value can't be represented in 32 bits.

Regards

Mark


Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: latest version
« Reply #4 on: December 05, 2017, 04:57:24 PM »
Hi Mark
  That seemed to be the issue, thanks for that. I never thought about the value being too large for the variable.

I used the following to get freespace.

unsigned long Freespace=ptrDiskInfo->utFileInfo.ulFreeClusterCount * ptrDiskInfo->utFAT.ucSectorsPerCluster;

How do I get the size of the card?

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: latest version
« Reply #5 on: December 05, 2017, 05:07:19 PM »
Neil

ptrDiskInfo->ulSD_sectors * ptrDiskInfo->utFAT.usBytesPerSector gives the size of the card.

fnDisplayDiskSize(ptrDiskInfo->ulSD_sectors, ptrDiskInfo->utFAT.usBytesPerSector);

Code: [Select]
static void fnDisplayDiskSize(unsigned long ulSectors, unsigned short usBytesPerSector) // {43}
{
    if (ulSectors >= 0x800000) {                                         // note that 512 byte sectors are assumed
        fnDebugDec((ulSectors/2), 0);                                    // the number of bytes cannot be held in a 32 bit number so display it in kBytes
        fnDebugMsg(" kBytes");
    }
    else {
        fnDebugDec((ulSectors * 512), 0);                                // the value can be displayed in bytes
        fnDebugMsg(" bytes");
    }
}

Regards

Mark