jmarques
May 12 2009, 7:17 AM
Hi,
I have a problem with auto_mount(), it is returning FR_WRITE_PROTECTED and i can't understand why. It is always in this part :
/* The logical drive must be re-mounted. Following code attempts to mount the logical drive */
memset(fs, 0, sizeof(FATFS)); /* Clean-up the file system object */
stat = disk_initialize(0); /* Initialize low level disk I/O layer */
if (stat & STA_NOINIT) /* Check if the drive is ready */
return FR_NOT_READY;
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
return FR_WRITE_PROTECTED;
Does this mean that the card is write protected? The SD card is new. Can they come from factory write protected?
I am using an 80c51f410.
THANKS!!!
I have a problem with auto_mount(), it is returning FR_WRITE_PROTECTED and i can't understand why. It is always in this part :
/* The logical drive must be re-mounted. Following code attempts to mount the logical drive */
memset(fs, 0, sizeof(FATFS)); /* Clean-up the file system object */
stat = disk_initialize(0); /* Initialize low level disk I/O layer */
if (stat & STA_NOINIT) /* Check if the drive is ready */
return FR_NOT_READY;
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
return FR_WRITE_PROTECTED;
Does this mean that the card is write protected? The SD card is new. Can they come from factory write protected?
I am using an 80c51f410.
THANKS!!!
DavesGarage
May 12 2009, 11:20 AM
Chan's auto_mount() function decides if the card is write protected by looking at the return value from your disk_initialize() function.
Notice the parameters that are passed to auto_mount()? The last parameter is called "chk_wp" - this is a flag to check for write_protection. If this value is set to 1, then the last line in your code above will be executed. If it is zero, then it won't.
When you scan through all of the calls to auto_mount(), you will find that some have this set to 1, and some don't. The ones that have it set to 1 are the functions that want to write to the card, like making directories, making files, formatting the card, etc...
But the reason why you are getting the FR_WRITE_PROTECTED message is because the "stat" variable, which was set within your disk_initialize() function, has the STA_PROTECT bit set.
Try looking in the disk_initialize() function. This is where you problem lies...
Hope this helps,
Notice the parameters that are passed to auto_mount()? The last parameter is called "chk_wp" - this is a flag to check for write_protection. If this value is set to 1, then the last line in your code above will be executed. If it is zero, then it won't.
When you scan through all of the calls to auto_mount(), you will find that some have this set to 1, and some don't. The ones that have it set to 1 are the functions that want to write to the card, like making directories, making files, formatting the card, etc...
But the reason why you are getting the FR_WRITE_PROTECTED message is because the "stat" variable, which was set within your disk_initialize() function, has the STA_PROTECT bit set.
Try looking in the disk_initialize() function. This is where you problem lies...
Hope this helps,
jmarques
May 13 2009, 2:21 AM
Hi,
The disk_initialize() is the same as the example that is given here, and the SD_Init returns 0 as it should. Later I tried to send the command CLR_WRITE_PROT before the f_open, this as solved the problem... Now i have another one, again in auto_mount(). When it search for the FAT partition on the drive:
fmt = check_fs(bootsect = 0); the check_fs returns 2 (fm=2) in the second condition:
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;
With fm=2 the auto_mout returns :
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512U) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
Do you think that there is a problem with the SD card? I have formatted the card in FAT and later i tried with FAT32. the same error happens.
Thanks for the help.
The disk_initialize() is the same as the example that is given here, and the SD_Init returns 0 as it should. Later I tried to send the command CLR_WRITE_PROT before the f_open, this as solved the problem... Now i have another one, again in auto_mount(). When it search for the FAT partition on the drive:
fmt = check_fs(bootsect = 0); the check_fs returns 2 (fm=2) in the second condition:
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;
With fm=2 the auto_mout returns :
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512U) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
Do you think that there is a problem with the SD card? I have formatted the card in FAT and later i tried with FAT32. the same error happens.
Thanks for the help.
jmarques
May 14 2009, 4:15 AM
Hi,
The disk_initialize() is the same as the example that is given here, and the SD_Init returns 0 as it should. Later I tried to send the command CLR_WRITE_PROT before the f_open, this as solved the problem... Now i have another one, again in auto_mount(). When it search for the FAT partition on the drive:
fmt = check_fs(bootsect = 0); the check_fs returns 2 (fm=2) in the second condition:
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;
With fm=2 the auto_mout returns :
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512U) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
Do you think that there is a problem with the SD card? I have formatted the card in FAT and later i tried with FAT32. the same error happens.
Thanks for the help.
The disk_initialize() is the same as the example that is given here, and the SD_Init returns 0 as it should. Later I tried to send the command CLR_WRITE_PROT before the f_open, this as solved the problem... Now i have another one, again in auto_mount(). When it search for the FAT partition on the drive:
fmt = check_fs(bootsect = 0); the check_fs returns 2 (fm=2) in the second condition:
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;
With fm=2 the auto_mout returns :
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512U) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
Do you think that there is a problem with the SD card? I have formatted the card in FAT and later i tried with FAT32. the same error happens.
Thanks for the help.
DavesGarage
May 19 2009, 8:44 AM
Try separating the conditions in the if() statement, and look at the value returned from LD_WORD().
For instance:
Tell me the value of NewVar and fmt...
For instance:
NewVar = LD_WORD(&fs->win[BPB_BytsPerSec]);
if( fmt || (NewVar != 512U) ) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
if( fmt || (NewVar != 512U) ) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
Tell me the value of NewVar and fmt...
jmarques
May 20 2009, 3:18 AM
Hi,
NewVar = 0x00;
ftm = 0x02;
NewVar = 0x00;
ftm = 0x02;
DavesGarage
May 20 2009, 8:04 AM
try formatting the SD card using the f_mkfs() function. If NewVar == 0x00, then your SD card isn't formatted correctly.
jmarques
May 20 2009, 9:49 AM
Using that func isn't the same as the format of windows?? because i have formatted in FAT16 and 32 and still didn't work.
It is possible that the 2 card that i have, have problems??
The 2 card are:
2Gb, Kingston and it is recognized as a type2.
1Gb, ??? and it is recognized as a type 1.
It is possible that the 2 card that i have, have problems??
The 2 card are:
2Gb, Kingston and it is recognized as a type2.
1Gb, ??? and it is recognized as a type 1.
jmarques
May 20 2009, 9:51 AM
Can you give an example of the f_mkfs(), I can't find one.
Thanks
Thanks
Ajay
May 21 2009, 1:32 PM
can you try with a lower size card? 512MB or 256MB?
DavesGarage
May 21 2009, 9:59 PM
Hi,
The disk_initialize() is the same as the example that is given here, and the SD_Init returns 0 as it should. Later I tried to send the command CLR_WRITE_PROT before the f_open, this as solved the problem... Now i have another one, again in auto_mount(). When it search for the FAT partition on the drive:
fmt = check_fs(bootsect = 0); the check_fs returns 2 (fm=2) in the second condition:
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;
With fm=2 the auto_mout returns :
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512U) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
Do you think that there is a problem with the SD card? I have formatted the card in FAT and later i tried with FAT32. the same error happens.
Thanks for the help.
The disk_initialize() is the same as the example that is given here, and the SD_Init returns 0 as it should. Later I tried to send the command CLR_WRITE_PROT before the f_open, this as solved the problem... Now i have another one, again in auto_mount(). When it search for the FAT partition on the drive:
fmt = check_fs(bootsect = 0); the check_fs returns 2 (fm=2) in the second condition:
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;
With fm=2 the auto_mout returns :
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512U) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
Do you think that there is a problem with the SD card? I have formatted the card in FAT and later i tried with FAT32. the same error happens.
Thanks for the help.
I took some time to look over the functions, and the disk_initialize() function is written by you, right?
Within this function, there is a variable names Stat, which is not the same as the variable within the automount function.
When you initialized this variable, how did you do it?
In my diskio.c module, my declaration looks like this:
CODE:
static volatile DSTATUS Stat = STA_NOINIT; /* Disk status */
Not only does this declare the variable, but it initializes it to STA_NOINIT as well...
This is a global declaration, within the DISKIO.C module...
Make sure you do this...