cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 FatFs f_open return FR_DISK_ERR

danghongquan198
Associate
Posted on June 02, 2015 at 08:52

I'm using the FatFs library ver R0.10 to access the SD card. Here is my code:

SystemInit();
USART_Configuration();
NVIC_Configuration();
/*-------------------------- SD Init ----------------------------- */
Status=disk_initialize(0);
printf('' \r\n\r\n ----- SD_Init Status:%d\r\n'',Status);
if (Status == SD_OK)
{ 
printf('' Initialize SD card successfully!\r\n\r\n'');
/*----------------- Read CSD/CID MSD registers ------------------*/
Status = SD_GetCardInfo(&SDCardInfo);
printf('' ----- SD_GetCardInfo Status:%d\r\n'',Status);
}
if (Status == SD_OK)
{
printf('' Get SD card infomation successfully!\r\n Block size:%x, Card type:%x\r\n\r\n'',SDCardInfo.CardBlockSize,SDCardInfo.CardType);
/*----------------- Select Card --------------------------------*/
Status = SD_SelectDeselect((u32) (SDCardInfo.RCA << 16));
printf('' ----- SD_SelectDeselect Status:%d\r\n'',Status);
}
if (Status == SD_OK)
{
printf('' Select SD card successfully!\r\n\r\n'');
Status = SD_EnableWideBusOperation(SDIO_BusWide_4b);
printf('' ----- SD_EnableWideBusOperation Status:%d\r\n'',Status);
}
/*------------------- Block Erase -------------------------------*/
if (Status == SD_OK)
{
printf('' Enable wide bus operation successfully!\r\n\r\n'');
/* Erase NumberOfBlocks Blocks of WRITE_BL_LEN(512 Bytes) */
Status = SD_Erase(Operate_Block*BlockSize, (Operate_Block+1)*BlockSize);
printf('' ----- SD_Erase Status:%d\r\n'',Status);
}
/* Set Device Transfer Mode to DMA */
if (Status == SD_OK)
{
printf('' Erase block %d successfully!\r\n All the data is 0x00\r\n\r\n'',Operate_Block);
Status = SD_SetDeviceMode(SD_POLLING_MODE);
printf('' ----- SD_SetDeviceMode Status:%d\r\n'',Status);
}
res = f_mount(0,&fs);
res = f_open(&fsrc,''0:/bigdata.txt'', FA_CREATE_ALWAYS | FA_WRITE );

f_mount() return FR_OK but f_open() return FR_DISK_ERR. I try to debug f_open() and it call:check_fs(fs, bsect) return 3 -> /* An error occured in the disk I/O layer */How could I solve this problem?

#stm32f4 #discovery #sdio
0 REPLIES 0