FF_Format() does not work as expected on STM32F4

sanjayanvekar wrote on Friday, May 26, 2017:

Hello,
I am tyring to use FF_Format() as descibed in the standrd example provided on freertos website, but unfortunatley the formated SD card is not recongnized by Windows and also after formating I cannot create any file on the embedded device. I am using FAT32 format and currently trying with 8Gb uSD card. Please help me to resolve this issue.

Thanks & Best Regards,
Sanjay

heinbali01 wrote on Saturday, May 27, 2017:

Hi Sanjay,

When you use a pre-formatted card, can your device correctly read and write that card?

I just tried to format a card on my STM32F4 EVAL, by calling FF_SDDiskFormat() from ff_sddisk.c.

It calls FF_Format() as follows:

    /* Format the drive - try FAT32 with large clusters. */
    BaseType_t xPartitionNumber = 0;
    xError = FF_Format( pxDisk, xPartitionNumber, pdFALSE, pdFALSE);

It produces this logging with a 16GB card:

00.000 [SvrWork   ] >> format
00.000 [SvrWork   ] FF_Format: Secs 31291384 Rsvd 32 Hidden 8 Root 0 Data 31291352
00.000 [SvrWork   ] FF_Format: SecCluster 64 DatSec 31283704 DataClus 488807 ulClusterBeginLBA 7688
00.037 [SvrWork   ] FF_Format: Clearing entire FAT (2 x 3819 sectors):
14.473 [SvrWork   ] FF_Format: Clearing done
14.473 [SvrWork   ] FF_Format: Clearing root directory at 00001E08: 64 sectors
14.681 [SvrWork   ] FF_SDDiskFormat: OK, now remounting
14.686 [SvrWork   ] prvDetermineFatType: firstWord 0000FFF8
14.687 [SvrWork   ] ****** FreeRTOS+FAT initialized 31291384 sectors
14.687 [SvrWork   ] FF_SDDiskFormat: rc 00000001
14.687 [SvrWork   ] Reading FAT and calculating Free Space
14.687 [SvrWork   ] Partition Nr          0
14.687 [SvrWork   ] Type                 12 (FAT32)
14.688 [SvrWork   ] VolLabel       'MY NAME    ' 
14.688 [SvrWork   ] TotalSectors   31291384
14.688 [SvrWork   ] SecsPerCluster       64
14.688 [SvrWork   ] Size              15275 MB
14.688 [SvrWork   ] FreeSize          15275 MB ( 100 perc free )

I copied directories and files to the SD-card and checked them under Linux with fsck.vfat. It passed the tests.

Can you show any logging as here above?

Does your uSD card contain a valid partition table? Was it already formatted before you tried to format it?

Here is how you can create a partition:

FF_IOManager_t *pIoMan = sddisk_ioman( xMyDisk );
FF_PartitionParameters_t xParameters;

memset( &xParameters, '\0', sizeof xParameters );
xParameters.xSizes[0] = 100;         /* Assign 100% to the first partition. */
xParameters.ulSectorCount = pxDisk->ulNumberOfSectors;
xParameters.ulHiddenSectors = 8;     /* Keep at least these initial sectors free. */
xParameters.xPrimaryCount = 1;       /* If true, the partition will become of type "extended". */
FF_Error_t xError = FF_Partition( &xMyDisk, &xParameters );
if( FF_isERR( xError ) == 0 )
{
    /* partition OK. */
}

Regards.