formatting sd card

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello , I'm using SD card with same70

I'm using ASF component "sd/mmc stack(component) (MCI) " 

and I can't find anything that can format my sd card , I want to do it by code without having to unplug the card and connect it to pc using sd card reader to format it

is it possible?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you don't use a file system then there is no need to format. You can write 0 in the blocks I suppose. If you do intend to use a file system then that implementation might have the format function (like FatFs has f_mkfs) but it would be a bit unusual to need that (cards are sold formatted).

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lajon wrote:

If you don't use a file system then there is no need to format. You can write 0 in the blocks I suppose. If you do intend to use a file system then that implementation might have the format function (like FatFs has f_mkfs) but it would be a bit unusual to need that (cards are sold formatted).

/Lars

ah sorry I forgot to mention I'm using ASF component "fatfts file system(service)"

the thing is I'm testing some stuff and some times I need to re-format the SD card , but it takes long time to unplug it from the device and do it on pc

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it's really FatFs then documentation is here...

 

http://elm-chan.org/fsw/ff/00ind...

 

As you can see the API to create a filesystem is f_mkfs() which is "make filesystem"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

If it's really FatFs then documentation is here...

 

http://elm-chan.org/fsw/ff/00ind...

 

As you can see the API to create a filesystem is f_mkfs() which is "make filesystem"

Hello , thanks for your answer 

I think it's FatFs as I already use most of the commands in the documentation like f_write , f_open , f_close, f_lseek , f_read etc etc

so you're saying if I use the f_mkfs() function it will re-format the sd card? (that's what I need to re-format and remove all data )

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Formatting doesn’t remove the data! It just wipes the fat and directory.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Formatting doesn’t remove the data! It just wipes the fat and directory.

what I need is the same that happens when you connect sd card to a pc using sd card reader then right click and choose format (removes data and formatting the sd card)

how can I do this with code without the need to connect to pc

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

these are the fatfs api function my code has 

/* FatFs module application interface                           */

FRESULT f_mount (BYTE, FATFS*);                        /* Mount/Unmount a logical drive */
FRESULT f_open (FIL*, const TCHAR*, BYTE);            /* Open or create a file */
FRESULT f_read (FIL*, void*, UINT, UINT*);            /* Read data from a file */
FRESULT f_lseek (FIL*, DWORD);                        /* Move file pointer of a file object */
FRESULT f_close (FIL*);                                /* Close an open file object */
FRESULT f_opendir (DIR*, const TCHAR*);                /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*);                    /* Read a directory item */
FRESULT f_stat (const TCHAR*, FILINFO*);            /* Get file status */
FRESULT f_write (FIL*, const void*, UINT, UINT*);    /* Write data to a file */
FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**);    /* Get number of free clusters on the drive */
FRESULT f_truncate (FIL*);                            /* Truncate file */
FRESULT f_sync (FIL*);                                /* Flush cached data of a writing file */
FRESULT f_unlink (const TCHAR*);                    /* Delete an existing file or directory */
FRESULT    f_mkdir (const TCHAR*);                        /* Create a new directory */
FRESULT f_chmod (const TCHAR*, BYTE, BYTE);            /* Change attriburte of the file/dir */
FRESULT f_utime (const TCHAR*, const FILINFO*);        /* Change timestamp of the file/dir */
FRESULT f_rename (const TCHAR*, const TCHAR*);        /* Rename/Move a file or directory */
FRESULT f_chdrive (BYTE);                            /* Change current drive */
FRESULT f_chdir (const TCHAR*);                        /* Change current directory */
FRESULT f_getcwd (TCHAR*, UINT);                    /* Get current directory */
FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*);    /* Forward data to the stream */
FRESULT f_mkfs (BYTE, BYTE, UINT);                    /* Create a file system on the drive */
FRESULT    f_fdisk (BYTE, const DWORD[], void*);        /* Divide a physical drive into some partitions */
int f_putc (TCHAR, FIL*);                            /* Put a character to the file */
int f_puts (const TCHAR*, FIL*);                    /* Put a string to the file */
int f_printf (FIL*, const TCHAR*, ...);                /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR*, int, FIL*);                    /* Get a string from the file */

 well I think I should do it in 2 steps , f_mkfs to re-format and f_unlink to delete files 

is this right ? or I'm getting something wrong?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Like I said it's f_mkfs()

 

As Kartman says, just like when your pc "formats" a card, this does not "wipe" data on the card (writing 0x00 to all sectors) but it simply writes empty FAT and root directory entries to the start of the card so it looks "empty".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Like I said it's f_mkfs()

 

As Kartman says, just like when your pc "formats" a card, this does not "wipe" data on the card (writing 0x00 to all sectors) but it simply writes empty FAT and root directory entries to the start of the card so it looks "empty".

okay got it , thanks

all this time I thought the format wipes data as well cause it always looked empty after formatting

okay , so I'll just use the f_mkfs()

thanks again

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Back in the very old days of floppy disks the MS-DOS "format" command did used to write 0x00 to all sectors. Later (might have been MS-DOS 3.3?) they added a "/quick" option that just wrote clean FAT/directory but left old data. For floppy disks this made a considerable difference as a process that used to take minutes could be done in seconds. Ever since the default has tended to be just "quick". There might be an option to do a "full wipe" but usually you need a "forensic eraser" to do things like that on modern storage media like HDDs, SSDd, SD/MMC and so on.

 

Of course if it does just write empty FAT/directories then as soon as you start to write files that will over-write sectors that may have existing data so, in time, everything on the disk will be replaced.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Back in the very old days of floppy disks the MS-DOS "format" command did used to write 0x00 to all sectors. Later (might have been MS-DOS 3.3?) they added a "/quick" option that just wrote clean FAT/directory but left old data. For floppy disks this made a considerable difference as a process that used to take minutes could be done in seconds. Ever since the default has tended to be just "quick". There might be an option to do a "full wipe" but usually you need a "forensic eraser" to do things like that on modern storage media like HDDs, SSDd, SD/MMC and so on.

 

Of course if it does just write empty FAT/directories then as soon as you start to write files that will over-write sectors that may have existing data so, in time, everything on the disk will be replaced.

okay now my question .. if I just format the sd card (without wiping data ) , if I do a check whether the files exist or not like using f_open for example , what would I get ? would it fail as file doesn't exist ? or would it work and open the file and read the data inside?

2nd thing I checked this link to use the f_mkfs http://irtos.sourceforge.net/FAT32_ChaN/doc/en/mkfs.html 

for 1st argument I have to choose the drive number , how do I know the drive number of my sd card?

and if it's 0 for example would be just like " f_mkfs(0,0,0); "?

and does it return FR_OK or something if it success?

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Once you have done a mkfs() everything that defines the structure of the files on the "disk" is reset. So, yeah, there maybe 100's, 1,000's or even more sectors on the media that still hold old data from previous files but because there is no reference to any of those files any more in the FATs or the root directory, both of which appear "empty" then any attempt to f_open() anything that existed previously will fail with a "file not found" error. So it is like a "clean" disk, just not very clean!

 

When you only have one storage device in the system then, yes, it will be numbered 0.

 

The drive numbering thing is to cater for the more complex kind of system where you might have FatFs controlling all of SD/MMC, hard drive and compact flash card. If you only wanted to format the CF card you'd call mkfs("2:", ...) or whatever.

 

BTW you did read this didn't you? http://elm-chan.org/fsw/ff/doc/m... - the "Example" there shows a typical invocation of f_mks().

 

Just as an aside in all my years of using SD/MMC in media players, cameras, PCs, dashcams, etc etc I don't think I've ever had the desire to format one - not even in a PC so I kind of wonder why you'd waste the flash space to offer this? I'd tend to say to the end user "if you really want to format an SD/MMC go and stick it into your nearest PC for a couple of minutes!"

Last Edited: Mon. Oct 15, 2018 - 08:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Once you have done a mkfs() everything that defines the structure of the files on the "disk" is reset. So, yeah, there maybe 100's, 1,000's or even more sectors on the media that still hold old data from previous files but because there is no reference to any of those files any more in the FATs or the root directory, both of which appear "empty" then any attempt to f_open() anything that existed previously will fail with a "file not found" error. So it is like a "clean" disk, just not very clean!

 

When you only have one storage device in the system then, yes, it will be numbered 0.

 

The drive numbering thing is to cater for the more complex kind of system where you might have FatFs controlling all of SD/MMC, hard drive and compact flash card. If you only wanted to format the CF card you'd call mkfs("2:", ...) or whatever.

 

BTW you did read this didn't you? http://elm-chan.org/fsw/ff/doc/m... - the "Example" there shows a typical invocation of f_mks().

 

Just as an aside in all my years of using SD/MMC in media players, cameras, PCs, dashcams, etc etc I don't think I've ever had the desire to format one - not even in a PC so I kind of wonder why you'd waste the flash space to offer this? I'd tend to say to the end user "if you really want to format an SD/MMC go and stick it into your nearest PC for a couple of minutes!"

thanks a lot for this clear answer

the thing is the sd card is inside a handheld device , so it takes time to reach it , and also I will have to make full test after opening the device cover in case any component get unplugged or something during this process

so it's more safe and time saving to do it by software 

the main reason for this that sometimes files get corrupted and the sd card has to be formatted (low quality chinese sd cards) so I'm trying to find best way to fix this by adding a manual way to format without causing any harm to the hardware inside , and wasting too much time in testing all the device functions every time

I'll try these and see which one gonna work 

				printf("format sd card\r\n");
				res  == f_mkfs("",0,0);
				printf("format res1 = %d /n",res);
				if(FR_OK  == res )
				{
					printf("format1 done\r\n");
				}
				res  == f_mkfs("LUN_ID_SD_MMC_0_MEM:",0,0);
				printf("format res2 = %d /n",res);
				if(FR_OK  == res )
				{
					printf("format2 done\r\n");
				}
				res  == f_mkfs(0,0,0);
				printf("format res4 = %d /n",res);
				if(FR_OK  == res )
				{
					printf("format4 done\r\n");
				}

then do the f_unlink to all existing files too , and see what happens.

thanks a lot for your help 

cheers

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and btw I already checked the link you mentioned before , but it's probably different ASF version than the one I have 

mine has 3 arguments only as I mentioned before , this 1 has 5 arguments , I know I can replace it but idk maybe something else will be affected 

this is the one I have in my ASF version

http://irtos.sourceforge.net/FAT32_ChaN/doc/en/mkfs.html

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
res  == f_mkfs("",0,0);

That is not correct. The example shows:

 

 res = f_mkfs("", FM_ANY, 0, work, sizeof work);

 

In particular the second parameter must not be 0. It has to be one of FM_FATFM_FAT32FM_EXFAT or FM_ANY which means "the one of these that is best for the media size" - so actually always use that.

 

The simplest invocation would appear to be:

 

 res = f_mkfs("", FM_ANY, 0, NULL, 0);

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

you're talking about another version of f_mkfs()

this is the one I have http://irtos.sourceforge.net/FAT32_ChaN/doc/en/mkfs.html

FRESULT f_mkfs (
  BYTE  Drive,            /* Logical drive number */
  BYTE  PartitioningRule, /* Partitioning rule */
  UINT  AllocSize         /* Size of the allocation unit */
);

Parameters

Drive:

Logical drive number (0-9) to be formatted.

PartitioningRule:

Specifies partitioning rule, FDISK(0) or SFD(1). This argument is ignored on some case.

AllocSize:

Force the allocation unit (cluter) size in unit of byte. The value must be power of 2 and between the sector size and 128 * sector size. When a zero is given, the cluster size is determined depends on the volume size.

 

I already checked the link but as I said it's probably newer version of ASF , the one in my code is old one 

Last Edited: Mon. Oct 15, 2018 - 10:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

do you recommend that I replace the old f_mkfs with the newer one with 5 arguments ?

I can try and check if it effects something else in the code .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found this in my conf_access.h

/*! \name Activation of Logical Unit Numbers
 */
//! @{
#define LUN_0                DISABLE   //!< On-Chip Virtual Memory.
#define LUN_1                DISABLE   //!< AT45DBX Data Flash.
#define LUN_2                ENABLE    //!< SD/MMC Card over Slot 0
#define LUN_3                DISABLE   //!< Spare
#define LUN_4                DISABLE   //!< Spare
#define LUN_5                DISABLE   //!< Spare
#define LUN_6                DISABLE   //!< Spare
#define LUN_7                DISABLE   //!< Spare
#define LUN_USB              DISABLE   //!< Host Mass-Storage Memory.

does it mean my sd/mmc number is LUN_2? so I need to make f_mkfs("LUN_2:",0,0); ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FatFs comes as a complete system - you can't just replace one function in it. Either you use the latest from the Chan site or you use whatever old version they have packed into ASF. To get the SPI interface stuff that ASF provides I guess you need to stick with the version that Atmel packaged in.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using the one I already have that I mentioned before still doesn't work 

I almost tried everything still not working

I re-open it and the files are there and working .

res = 5;
				res  = f_mkfs("",0,0);
				printf("format res1 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format1 done\r\n");
				}
				res = 5;
				res  = f_mkfs(LUN_ID_SD_MMC_0_MEM,0,0);
				printf("format res2 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format2 done\r\n");
				}
				res = 5;
				res  = f_mkfs("0:",0,0);
				printf("format res3 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format3 done\r\n");
				}
				res = 5;
				res  = f_mkfs(0,0,0);
				printf("format res4 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format4 done\r\n");
				}
				res = 5;
				res  = f_mkfs("1:",0,0);
				printf("format res5 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format5 done\r\n");
				}
				res = 5;
				res  = f_mkfs("2:",0,0);
				printf("format res6 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format6 done\r\n");
				}
				res = 5;
				res  = f_mkfs("LUN_ID_2:",0,0);
				printf("format res7 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format7 done\r\n");
				}
				res = 5;
				res  == f_mkfs(LUN_ID_2,0,0);
				printf("format res8 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format8 done\r\n");
				}
				res = 5;
				res  = f_mkfs("LUN_ID_2",0,0);
				printf("format res9 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format9 done\r\n");
				}

none of them returned FR_OK (0)

idk what else should I try to make it work .

Last Edited: Mon. Oct 15, 2018 - 12:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mostafa.aliaeldin wrote:
none of them returned FR_OK (0)
So if it's not FR_OK what was the error code returned?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
what was the error code returned?

in some cases I got 11 and in some others got 12

here's what they mean

	FR_INVALID_DRIVE,		/* (11) The logical drive number is invalid */
	FR_NOT_ENABLED,			/* (12) The volume has no work area */

for the ones with 11 I removed them all as the argument probably wrong 

so I have only these 3 left 

				res = 30;
				res  = f_mkfs(LUN_ID_SD_MMC_0_MEM,1,0);  //12
				printf("format res2 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format2 done\r\n");
				}
				res = 30;
				res  = f_mkfs(0,1,0);                    //12
				printf("format res4 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format4 done\r\n");
				}
				res = 30;
				res  = f_mkfs(LUN_ID_2,1,0);             //12
				printf("format res8 = %d \r\n",res);
				if(FR_OK  == res )
				{
					printf("format8 done\r\n");
				}

these 3 return '12' it says the volume has no work area , what does this mean?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think there's something related to f_mount function

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

have you looked at the example?

static uint8_t run_fatfs_test(uint32_t disk_dev_num)
{
    uint32_t i;
    UINT     byte_to_read;
    UINT     byte_read;
#if _FS_READONLY == 0
    UINT byte_written;
#endif

    FRESULT res;
    DIR     dirs;
    TCHAR   root_directory[4];
    /* File name to be validated */
    TCHAR file_name[18];

    TCHAR test_folder_name[5];
    TCHAR test_folder_location[8];
    TCHAR get_test_folder[8];
#if _USE_LFN
    char lfn[_MAX_LFN + 1];
    fno.lfname = lfn;
    fno.lfsize = _MAX_LFN + 1;
#endif

    /* Declare these as static to avoid stack usage.
     * They each contain an array of maximum sector size.
     */
    static FATFS fs;
    static FIL   file_object;
    char         disk_str_num[2];

    sprintf(disk_str_num, "%d", disk_dev_num);
    sprintf(test_folder_name, "%s", (const char *)"TEST");
    sprintf(root_directory, "%s:/", disk_str_num);
    sprintf(test_folder_location, "%s%s", root_directory, test_folder_name);
    sprintf(file_name, "%s/Basic.bin", test_folder_location); /*File path*/

    /* Mount disk*/
    printf("-I- Mount disk %d\n\r", (int)disk_dev_num);
    /* Clear file system object */
    memset(&fs, 0, sizeof(FATFS));
    res = f_mount(&fs, "", 1);
    if (res != FR_OK) {
        printf("-E- f_mount pb: 0x%X\n\r", res);
        return 0;
    }

#ifdef FORMAT_CARD /** Enable the macro to Format card and do testing*/
#if _FS_READONLY == 0
    /* Format disk */
    printf("-I- Format disk %d\n\r", (int)disk_dev_num);
    puts("-I- Please wait a moment during formatting...\r");
    res = f_mkfs(disk_str_num, /* Drv */
                 0,            /* FDISK partition */
                 512);         /* AllocSize */
    puts("-I- Disk format finished !\r");
    if (res != FR_OK) {
        printf("-E- f_mkfs pb: 0x%X\n\r", res);
        return 0;
    }
#else
    puts("-I- Please run Full version FAT FS test first\r");
    return 0;
#endif
#endif

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So if you single-step into the f_mkfs() code what causes it to make the decision about INVALID_DRIVE. In the FatFs code I see it doing things like:

	/* Check mounted drive and clear work area */
	vol = get_ldnumber(&path);					/* Get target logical drive */
	if (vol < 0) return FR_INVALID_DRIVE;

so if you step into that get_ldnumber() then is it really returning a negative value and why? 

 

Elsewhere in the FatFs code the only places I see it mention FR_NOT_ENABLED are in find_volume() where it does:

	/* Check if the filesystem object is valid or not */
	fs = FatFs[vol];					/* Get pointer to the filesystem object */
	if (!fs) return FR_NOT_ENABLED;		/* Is the filesystem object available? */

so if it is returning FR_NOT_ENABLED then that would seem to be because the volume is not mounted. Are you doing an f_mount() before f_mkfs()? I'm just guessing but I think it probably will have had to read the BPB before it could consider doing an mkfs().

 

Having said that the example in the "modern" manual for FatFs() shows it doing an mkfs() before a mount() and I don't see anything in the mkfs() documentation that says mount() is a pre-requisite.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yea I think it's probably needed to do f_mount before f_mkfs according to this link 

http://elm-chan.org/fsw/ff/doc/rc.html

FR_NOT_ENABLED:

Work area for the logical drive has not been registered by f_mount function.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got it done , I had to init and mount the sd card then do the mkfs, I also added the f_unlink after f_mkfs and they both worked perfectly

thanks a lot for your help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great news - from the example it looks like later FatFs does not require it to be mounted first.

 

(if you think about it - if you have a card with NO file system (sector 0 = all 0x00) then you would otherwise have a real "chicken/ egg" situation where you could not mount it to format it!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Great news - from the example it looks like later FatFs does not require it to be mounted first.

 

(if you think about it - if you have a card with NO file system (sector 0 = all 0x00) then you would otherwise have a real "chicken/ egg" situation where you could not mount it to format it!)

Yes , I understand , the thing is it's a manual option to be used in special conditions , so it won't be a problem , I added a combination of keys with a specific order to do this function whenever I need to

I'm able to fully format and wipe data on sd cards manually without having to open the device sealing and that's exactly what I needed

thanks for your help and your time :)

this is my code for reference

sd_mmc_init();

do {
	status = sd_mmc_test_unit_ready(0);
	if (CTRL_FAIL == status)
	{
		printf("Card install FAIL\n\r");
		printf("Please unplug and re-plug the card.\n\r");
		while (CTRL_NO_PRESENT != sd_mmc_check(0))
		{
		}
	}
} while (CTRL_GOOD != status);

memset(&fs, 0, sizeof(FATFS));

res = f_mount(LUN_ID_SD_MMC_0_MEM, &fs);
if (FR_INVALID_DRIVE == res) {
	printf("[FAIL] res %d\r\n", res);
	return 0;
}
printf("Disk Mounted\r\n");
if(FormatSDCard == true)
{
	////////////
	printf("format sd card\r\n");
	res = 30;
	res  = f_mkfs(LUN_ID_SD_MMC_0_MEM,1,0);  //12
	printf("format res2 = %d \r\n",res);
	if(FR_OK  == res )
	{
		printf("format2 done\r\n");
	}
	res = 30;
	res  = f_mkfs(0,1,0);                    //12
	printf("format res4 = %d \r\n",res);
	if(FR_OK  == res )
	{
		printf("format4 done\r\n");
	}
	res = 30;
	res  = f_mkfs(LUN_ID_2,1,0);             //12
	printf("format res8 = %d \r\n",res);
	if(FR_OK  == res )
	{
		printf("format8 done\r\n");
	}

	/*//////////////////////////////////*/
	printf("format0000 sd card\r\n");

	res = 30;
	res  = f_mkfs(LUN_ID_SD_MMC_0_MEM,0,0);
	printf("format res2 = %d \r\n",res);
	if(FR_OK  == res )
	{
		printf("format2 done\r\n");
	}
	res = 30;
	res  = f_mkfs(0,0,0);
	printf("format res4 = %d \r\n",res);
	if(FR_OK  == res )
	{
		printf("format4 done\r\n");
	}
	res = 30;
	res  = f_mkfs(LUN_ID_2,0,0);
	printf("format res8 = %d \r\n",res);
	if(FR_OK  == res )
	{
		printf("format8 done\r\n");
	}

	DeleteFiles();

they return 0 (FR_OK) in the 6 situations 

so they all success to format the sd card

then I use the function DeleteFiles which f_unlink all files and wipes them .

Last Edited: Sat. Oct 20, 2018 - 07:54 PM